// Path: src/main/java/com/tamingtext/classifier/mlt/TrainMoreLikeThis.java
// public static enum MatchMode {
//   KNN,
//   TFIDF
// }


import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.commons.cli2.CommandLine;
import org.apache.commons.cli2.Group;
import org.apache.commons.cli2.Option;
import org.apache.commons.cli2.OptionException;
import org.apache.commons.cli2.builder.ArgumentBuilder;
import org.apache.commons.cli2.builder.DefaultOptionBuilder;
import org.apache.commons.cli2.builder.GroupBuilder;
import org.apache.commons.cli2.commandline.Parser;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.shingle.ShingleAnalyzerWrapper;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermEnum;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.similar.MoreLikeThis;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.mahout.common.CommandLineUtil;
import org.apache.mahout.common.commandline.DefaultOptionCreator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.tamingtext.classifier.mlt.TrainMoreLikeThis.MatchMode;
    
    categories.addAll(Arrays.asList(parts));
    log.info("Loaded " + categories.size() + " categories from index");
  }
  
  /** populate the list of categories by reading the values from the categoryField in the index */
  protected void scanCategories() throws IOException {
    TermEnum te = indexReader.terms(new Term(categoryFieldName));
    final Set<String> c = categories;
    
    do {
      if (!te.term().field().equals(categoryFieldName)) break;
      c.add(te.term().text());
    } while (te.next());
    
    log.info("Scanned " + c.size() + " categories from index");
  }
  
  public void setMaxResults(int maxResults) {
    this.maxResults = maxResults;
  }
  
  public Collection<String> getCategories() {
    return Collections.unmodifiableSet(categories);
  }
  
  public MatchMode getMatchMode() {
    return matchMode;
  }

// Path: src/main/java/com/tamingtext/classifier/mlt/TrainMoreLikeThis.java
// public static enum MatchMode {
//   KNN,
//   TFIDF
// }


// Path: src/main/java/com/tamingtext/classifier/mlt/MoreLikeThisCategorizer.java
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.commons.cli2.CommandLine;
import org.apache.commons.cli2.Group;
import org.apache.commons.cli2.Option;
import org.apache.commons.cli2.OptionException;
import org.apache.commons.cli2.builder.ArgumentBuilder;
import org.apache.commons.cli2.builder.DefaultOptionBuilder;
import org.apache.commons.cli2.builder.GroupBuilder;
import org.apache.commons.cli2.commandline.Parser;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.shingle.ShingleAnalyzerWrapper;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermEnum;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.similar.MoreLikeThis;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.mahout.common.CommandLineUtil;
import org.apache.mahout.common.commandline.DefaultOptionCreator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.tamingtext.classifier.mlt.TrainMoreLikeThis.MatchMode;

    
    categories.addAll(Arrays.asList(parts));
    log.info("Loaded " + categories.size() + " categories from index");
  }
  
  /** populate the list of categories by reading the values from the categoryField in the index */
  protected void scanCategories() throws IOException {
    TermEnum te = indexReader.terms(new Term(categoryFieldName));
    final Set<String> c = categories;
    
    do {
      if (!te.term().field().equals(categoryFieldName)) break;
      c.add(te.term().text());
    } while (te.next());
    
    log.info("Scanned " + c.size() + " categories from index");
  }
  
  public void setMaxResults(int maxResults) {
    this.maxResults = maxResults;
  }
  
  public Collection<String> getCategories() {
    return Collections.unmodifiableSet(categories);
  }
  
  public MatchMode getMatchMode() {
    return matchMode;
  }

  public void setMatchMode(MatchMode matchMode) {