title: Classify a text with weka after classifier has been trained
body: <p>I am a beginner with weka. </p>
  
  <p>I have managed to import dataset from the disk (one folder by category, all text related to this category inside the folder), apply StringToWordVector with tokenizer, train a Naive Multniomial categorizer ... The code is below (it is c# but Java is ok of course) </p>
  
  <p>However, I can hardly find information on how to use the categorizer on a project. Say I have a text with unknown category, input by a user, how can I just apply the categorizer to this text and infer the category it belongs to ? (code "// what to do here below"). 
  Any help would be greatly appreciated ;-) </p>
  
  <p>Thanks in advance</p>
  
  <p>Julien</p>
  
  <pre><code>string filepath = @"C:\Users\Julien\Desktop\Meal\";
      ClassificationDatasetHelper classHelper = new ClassificationDatasetHelper();
      weka.core.converters.TextDirectoryLoader tdl = new
      weka.core.converters.TextDirectoryLoader();
      tdl.setDirectory(new java.io.File(filepath));
      tdl.setCharSet("UTF-8");
  
      weka.core.Instances insts = tdl.getDataSet();
  
      weka.filters.unsupervised.attribute.StringToWordVector swv = new weka.filters.unsupervised.attribute.StringToWordVector();
      swv.setInputFormat(insts);
      swv.setDoNotOperateOnPerClassBasis(false);
      swv.setOutputWordCounts(true);
      swv.setWordsToKeep(1000);
      swv.setIDFTransform(true);
      swv.setMinTermFreq(1);
      swv.setDoNotOperateOnPerClassBasis(false);
      swv.setPeriodicPruning(-1);
      weka.core.tokenizers.NGramTokenizer tokenizer = new weka.core.tokenizers.NGramTokenizer();
      tokenizer.setNGramMinSize(2);
      tokenizer.setNGramMaxSize(2);
      swv.setTokenizer(tokenizer);
  
      insts = weka.filters.Filter.useFilter(insts, swv);
  
      insts.setClassIndex(0);
  
      weka.classifiers.Classifier cl = new weka.classifiers.bayes.NaiveBayesMultinomial();
      int trainSize = insts.numInstances() * percentSplit / 100;
      int testSize = insts.numInstances() - trainSize;
      weka.core.Instances train = new weka.core.Instances(insts, 0, trainSize);
  
      cl.buildClassifier(train);
      string s = "Try to classify this text";
      weka.core.Instance instanceToClassify = new weka.core.Instance();
  
      // what to do here
      // ???
  
      double predictedClass = cl.classifyInstance(instanceToClassify);
  </code></pre>
  
  <p>Thanks</p>