// Path: src/main/java/com/tamingtext/util/FileUtil.java
// public class FileUtil {
// 
//   public static File[] buildFileList(File f) {
//     if (!f.isDirectory()) {
//       throw new IllegalArgumentException(f + " is not a directory or does not exit");
//     }
//     
//     // list training data.
//     File[] inputFiles = f.listFiles(new FileFilter() {
//       @Override
//       public boolean accept(File pathname) {
//         if (pathname.isFile()) {
//           String name = pathname.getName();
//           if (name.startsWith(".") || name.endsWith(".crc")) {
//             return false;
//           }
//           return true; // a file.
//         }
//         
//         return false; // not a file.
//       }
//     });
//     return inputFiles;
//   }
// 
// }


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import opennlp.tools.doccat.BagOfWordsFeatureGenerator;
import opennlp.tools.doccat.DoccatModel;
import opennlp.tools.doccat.DocumentCategorizerME;
import opennlp.tools.tokenize.SimpleTokenizer;
import opennlp.tools.tokenize.Tokenizer;
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.mahout.common.CommandLineUtil;
import org.apache.mahout.common.commandline.DefaultOptionCreator;
import org.slf4j.Logger;
import com.tamingtext.util.FileUtil;
<callout arearefs="tm.train">Train categorizer</callout>  
</calloutlist>*/
//<end id="maxent.examples.train.setup"/>
  }

  public static void main(String[] args) throws Exception {

    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();
    
    Option helpOpt = DefaultOptionCreator.helpOption();
    
    Option inputDirOpt = obuilder.withLongName("input").withRequired(true).withArgument(
      abuilder.withName("input").withMinimum(1).withMaximum(1).create()).withDescription(
      "The input directory, containing properly formatted files: "
          + "One doc per line, first entry on the line is the label, rest is the evidence")
        .withShortName("i").create();
    
    Option outputOpt = obuilder.withLongName("output").withRequired(true).withArgument(
      abuilder.withName("output").withMinimum(1).withMaximum(1).create()).withDescription(
      "The output directory").withShortName("o").create();
    
    
    Group group = gbuilder.withName("Options").withOption(helpOpt).withOption(
        inputDirOpt).withOption(outputOpt).create();
    
    //.withOption(gramSizeOpt).withOption(typeOpt)
    
    try {
// Path: src/main/java/com/tamingtext/util/FileUtil.java
// public class FileUtil {
// 
//   public static File[] buildFileList(File f) {
//     if (!f.isDirectory()) {
//       throw new IllegalArgumentException(f + " is not a directory or does not exit");
//     }
//     
//     // list training data.
//     File[] inputFiles = f.listFiles(new FileFilter() {
//       @Override
//       public boolean accept(File pathname) {
//         if (pathname.isFile()) {
//           String name = pathname.getName();
//           if (name.startsWith(".") || name.endsWith(".crc")) {
//             return false;
//           }
//           return true; // a file.
//         }
//         
//         return false; // not a file.
//       }
//     });
//     return inputFiles;
//   }
// 
// }


// Path: src/main/java/com/tamingtext/classifier/maxent/TrainMaxent.java
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import opennlp.tools.doccat.BagOfWordsFeatureGenerator;
import opennlp.tools.doccat.DoccatModel;
import opennlp.tools.doccat.DocumentCategorizerME;
import opennlp.tools.tokenize.SimpleTokenizer;
import opennlp.tools.tokenize.Tokenizer;
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.mahout.common.CommandLineUtil;
import org.apache.mahout.common.commandline.DefaultOptionCreator;
import org.slf4j.Logger;
import com.tamingtext.util.FileUtil;

<callout arearefs="tm.train">Train categorizer</callout>  
</calloutlist>*/
//<end id="maxent.examples.train.setup"/>
  }

  public static void main(String[] args) throws Exception {

    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();
    
    Option helpOpt = DefaultOptionCreator.helpOption();
    
    Option inputDirOpt = obuilder.withLongName("input").withRequired(true).withArgument(
      abuilder.withName("input").withMinimum(1).withMaximum(1).create()).withDescription(
      "The input directory, containing properly formatted files: "
          + "One doc per line, first entry on the line is the label, rest is the evidence")
        .withShortName("i").create();
    
    Option outputOpt = obuilder.withLongName("output").withRequired(true).withArgument(
      abuilder.withName("output").withMinimum(1).withMaximum(1).create()).withDescription(
      "The output directory").withShortName("o").create();
    
    
    Group group = gbuilder.withName("Options").withOption(helpOpt).withOption(
        inputDirOpt).withOption(outputOpt).create();
    
    //.withOption(gramSizeOpt).withOption(typeOpt)
    
    try {
      Parser parser = new Parser();