Package no.priv.garshol.duke.utils

Examples of no.priv.garshol.duke.utils.CommandLineParser$Option


   */
  public String[] init(String[] argv, int min, int max,
                       Collection<CommandLineParser.Option> options)
    throws IOException, SAXException {
    // parse command line
    parser = new CommandLineParser();
    parser.setMinimumArguments(min);
    parser.setMaximumArguments(max);
    parser.registerOption(new CommandLineParser.BooleanOption("reindex", 'I'));
    if (options != null)
      for (CommandLineParser.Option option : options)
View Full Code Here


public class CommandLineParserTest {
  private CommandLineParser parser;
 
  @Before
  public void setup() {
    parser = new CommandLineParser();
  }
View Full Code Here

    }
  }

  public static void main_(String[] argv) throws IOException {
    // parse command-line
    CommandLineParser parser = setupParser();
    try {
      argv = parser.parse(argv);
    } catch (CommandLineParser.CommandLineParserException e) {
      System.err.println("ERROR: " + e.getMessage());
      usage();
      System.exit(1);
    }

    // set up some initial options
    boolean datadebug = parser.getOptionState("showdata");
    Logger logger = new CommandLineLogger(parser.getOptionState("verbose") ?
                                          1 : 0);
    boolean progress = parser.getOptionState("progress");
    int count = 0;
    int batch_size = parser.getOptionInteger("batchsize", 40000);
    int threads = parser.getOptionInteger("threads", 1);

    // load the configuration
    Configuration config;
    try {
      config = ConfigLoader.load(argv[0]);
    } catch (FileNotFoundException e) {
      System.err.println("ERROR: Config file '" + argv[0] + "' not found!");
      return;
    } catch (SAXParseException e) {
      System.err.println("ERROR: Couldn't parse config file: " + e.getMessage());
      System.err.println("Error in " + e.getSystemId() + ":" +
                         e.getLineNumber() + ":" + e.getColumnNumber());
      return;
    } catch (SAXException e) {
      System.err.println("ERROR: Couldn't parse config file: " + e.getMessage());
      return;
    }

    // validate the configuration
    if (!datadebug) // unless --showdata
      config.validate();

    // if we're in data debug mode we branch out here
    if (datadebug) {
      showdata(config);
      return; // stop here
    }

    // set up listeners
    boolean noreindex = parser.getOptionState("noreindex");
    Processor processor = new Processor(config, !noreindex);
    processor.setLogger(logger);
    processor.setThreads(threads);

    // sanity check
    if (noreindex && processor.getDatabase().isInMemory()) {
      System.out.println("Option --noreindex not available with in-memory " +
                         "database");
      return;
    }

    // display lookup properties?
    if (parser.getOptionState("lookups")) {
      System.out.println("Lookup properties:");
      for (Property p : config.getLookupProperties())
        System.out.println("  " + p.getName());
      System.out.println();
    }

    boolean interactive = parser.getOptionState("interactive");
    boolean pretty = parser.getOptionState("pretty") || interactive;
    boolean showmatches = parser.getOptionState("showmatches") || interactive;
    PrintMatchListener listener =
      new PrintMatchListener(showmatches,
                             parser.getOptionState("showmaybe"),
                             progress,
                             !config.isDeduplicationMode(),
                             config.getProperties(),
                             pretty);
    processor.addMatchListener(listener);

    // needs to be before the link file handler, in case the link file
    // is the same as the test file
    TestFileListener testfile = null;
    if (parser.getOptionValue("testfile") != null) {
      testfile = new TestFileListener(parser.getOptionValue("testfile"),
                                      config,
                                      parser.getOptionState("testdebug"),
                                      processor,
                                      showmatches,
                                      pretty);
      testfile.setPessimistic(true);
      processor.addMatchListener(testfile);
    }

    AbstractLinkFileListener linkfile = null;
    if (parser.getOptionValue("linkfile") != null) {
      String fname = parser.getOptionValue("linkfile");
      if (fname.endsWith(".ntriples"))
        linkfile = new NTriplesLinkFileListener(fname, config.getIdentityProperties());
      else
        linkfile = new LinkFileListener(fname, config.getIdentityProperties(),
                                        interactive,
                                        parser.getOptionValue("testfile"));
      processor.addMatchListener(linkfile);
    }

    // --profile
    if (parser.getOptionState("profile"))
      processor.setPerformanceProfiling(true);

    // --singlematch setting
    boolean matchall = true;
    if (parser.getOptionState("singlematch")) {
      if (config.isDeduplicationMode())
        throw new DukeConfigException("--singlematch only works in record linkage mode");
      matchall = false;
    }

    // this is where we get started for real. the first thing we do
    // is to distinguish between modes.
    if (config.isDeduplicationMode())
      // deduplication mode
      processor.deduplicate(config.getDataSources(), batch_size);
    else {
      // record linkage mode
      if (noreindex) {
        // user has specified that they already have group 1 indexed up,
        // and don't want to do it again, for whatever reason. in that
        // case we just do the linking, and don't touch group 1 at all.
        processor.linkRecords(config.getDataSources(2), matchall);
      } else
        processor.link(config.getDataSources(1),
                       config.getDataSources(2),
                       matchall,
                       batch_size);
    }

    // close up shop, then finish
    if (parser.getOptionValue("linkfile") != null)
      linkfile.close();
    processor.close();
  }
View Full Code Here

    System.out.println("");
    System.out.println("Duke version " + getVersionString());
  }

  private static CommandLineParser setupParser() {
    CommandLineParser parser = new CommandLineParser();
    parser.setMinimumArguments(1);
    parser.setMaximumArguments(1);
    parser.addBooleanOption("progress", 'p');
    parser.addStringOption("linkfile", 'l');
    parser.addStringOption("linkendpoint", 'e');
    parser.addBooleanOption("showmatches", 's');
    parser.addBooleanOption("showmaybe", 'm');
    parser.addStringOption("testfile", 'T');
    parser.addBooleanOption("testdebug", 't');
    parser.addStringOption("batchsize", 'b');
    parser.addBooleanOption("verbose", 'v');
    parser.addStringOption("threads", 'P');
    parser.addBooleanOption("noreindex", 'N');
    parser.addBooleanOption("interactive", 'I');
    parser.addBooleanOption("showdata", 'D');
    parser.addBooleanOption("profile", 'o');
    parser.addStringOption("threads", 'n');
    parser.addBooleanOption("pretty", 'n');
    parser.addBooleanOption("singlematch", 'n');
    parser.addBooleanOption("lookups", 'L');
    return parser;
  }
View Full Code Here

*/
public class Driver {

  public static void main(String[] argv) throws IOException, SAXException {
    // parse command-line
    CommandLineParser parser = new CommandLineParser();
    parser.setMinimumArguments(1);
    parser.setMaximumArguments(1);
    parser.addStringOption("testfile", 'T');
    parser.addBooleanOption("scientific", 's');
    parser.addStringOption("generations", 'G');
    parser.addStringOption("population", 'P');
    parser.addStringOption("questions", 'Q');
    parser.addStringOption("output", 'O');
    parser.addStringOption("threads", 't');
    parser.addBooleanOption("active", 'A');
    parser.addStringOption("linkfile", 'l');
    parser.addBooleanOption("sparse", 'S');
    parser.addStringOption("mutation-rate", 'm');
    parser.addStringOption("recombination-rate", 'r');
    parser.addBooleanOption("no-comparators", 'C');
    parser.addStringOption("original", 'o');
    parser.addBooleanOption("incomplete-data", 'I');

    try {
      argv = parser.parse(argv);
    } catch (CommandLineParser.CommandLineParserException e) {
      System.err.println("ERROR: " + e.getMessage());
      usage();
      System.exit(1);
    }

    String testfile = parser.getOptionValue("testfile");
    if (parser.getOptionState("scientific") && testfile == null) {
      System.err.println("ERROR: scientific mode requires a test file");
      System.exit(1);
    }

    // get started
    Configuration config = ConfigLoader.load(argv[0]);
    GeneticAlgorithm genetic =
      new GeneticAlgorithm(config, testfile,
                           parser.getOptionState("scientific"));
    genetic.setPopulation(parser.getOptionInteger("population", 100));
    genetic.setGenerations(parser.getOptionInteger("generations", 100));
    genetic.setQuestions(parser.getOptionInteger("questions", 10));
    genetic.setConfigOutput(parser.getOptionValue("output"));
    genetic.setThreads(parser.getOptionInteger("threads", 1));
    genetic.setSparse(parser.getOptionState("sparse"));
    genetic.setMutationRate(parser.getOptionInteger("mutation-rate", -1));
    genetic.setRecombinationRate(parser.getOptionDouble("recombination-rate", -1.0));
    genetic.setEvolveComparators(!parser.getOptionState("no-comparators"));
    genetic.setCopiesOfOriginal(parser.getOptionInteger("original", 0));
    genetic.setIncompleteTest(parser.getOptionState("incomplete-data"));
    if (parser.getOptionState("active"))
      genetic.setActive(true);
    if (parser.getOptionValue("linkfile") != null)
      genetic.setLinkFile(parser.getOptionValue("linkfile"));
    genetic.run();
  }
View Full Code Here

    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(
View Full Code Here

  public static void main(String[] args) throws IOException {
    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")
        .withShortName("i").create();
   
    Option modelOpt = obuilder.withLongName("model").withRequired(true).withArgument(
      abuilder.withName("index").withMinimum(1).withMaximum(1).create()).withDescription(
      "The directory containing the index model").withShortName("m").create();

    Group group = gbuilder.withName("Options").withOption(helpOpt)
        .withOption(inputDirOpt).withOption(modelOpt).create();
View Full Code Here

  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")
        .withShortName("i").create();
   
    Option modelOpt = obuilder.withLongName("model").withRequired(true).withArgument(
      abuilder.withName("index").withMinimum(1).withMaximum(1).create()).withDescription(
      "The directory containing the index model").withShortName("m").create();
   
    Option categoryFieldOpt = obuilder.withLongName("categoryField").withRequired(true).withArgument(
        abuilder.withName("index").withMinimum(1).withMaximum(1).create()).withDescription(
        "Name of the field containing category information").withShortName("catf").create();

    Option contentFieldOpt = obuilder.withLongName("contentField").withRequired(true).withArgument(
        abuilder.withName("index").withMinimum(1).withMaximum(1).create()).withDescription(
        "Name of the field containing content information").withShortName("contf").create();
   
    Option maxResultsOpt = obuilder.withLongName("maxResults").withRequired(false).withArgument(
        abuilder.withName("gramSize").withMinimum(1).withMaximum(1).create()).withDescription(
        "Number of results to retrive, default: 10 ").withShortName("r").create();
   
    Option gramSizeOpt = obuilder.withLongName("gramSize").withRequired(false).withArgument(
      abuilder.withName("gramSize").withMinimum(1).withMaximum(1).create()).withDescription(
      "Size of the n-gram. Default Value: 1 ").withShortName("ng").create();
   
    Option typeOpt = obuilder.withLongName("classifierType").withRequired(false).withArgument(
      abuilder.withName("classifierType").withMinimum(1).withMaximum(1).create()).withDescription(
      "Type of classifier: knn|tfidf. Default: bayes").withShortName("type").create();
   
    Group group = gbuilder.withName("Options").withOption(gramSizeOpt).withOption(helpOpt).withOption(
        inputDirOpt).withOption(modelOpt).withOption(typeOpt).withOption(contentFieldOpt)
View Full Code Here

   
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();
   
    Option inputOpt = obuilder.withLongName("dir")
      .withRequired(true)
      .withArgument(
        abuilder.withName("dir")
          .withMinimum(1)
          .withMaximum(1).create())
      .withDescription("Lucene index directory containing input data")
      .withShortName("d").create();

    Option categoryOpt = obuilder.withLongName("categories")
    .withRequired(true)
    .withArgument(
      abuilder.withName("file")
        .withMinimum(1)
        .withMaximum(1).create())
    .withDescription("File containing a list of categories")
    .withShortName("c").create();
   
    Option outputOpt = obuilder.withLongName("output")
      .withRequired(false)
      .withArgument(
        abuilder.withName("output")
          .withMinimum(1)
          .withMaximum(1).create())
      .withDescription("Output directory")
      .withShortName("o").create();

    Option categoryFieldsOpt =
      obuilder.withLongName("category-fields")
      .withRequired(true)
      .withArgument(
        abuilder.withName("fields")
          .withMinimum(1)
          .withMaximum(1)
          .create())
      .withDescription("Fields to match categories against (comma-delimited)")
      .withShortName("cf").create();
   
    Option textFieldsOpt =
      obuilder.withLongName("text-fields")
      .withRequired(true)
      .withArgument(
        abuilder.withName("fields")
          .withMinimum(1)
          .withMaximum(1)
          .create())
      .withDescription("Fields from which to extract training text (comma-delimited)")
      .withShortName("tf").create();
   
    Option useTermVectorsOpt = obuilder.withLongName("use-term-vectors")
      .withDescription("Extract term vectors containing preprocessed data " +
          "instead of unprocessed, stored text values")
      .withShortName("tv").create();
   
    Option helpOpt = obuilder.withLongName("help")
      .withDescription("Print out help")
      .withShortName("h").create();
   
    Group group = gbuilder.withName("Options")
      .withOption(inputOpt)
View Full Code Here

 
  public boolean parseArgs(String[] args) {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();
    Option helpOpt = DefaultOptionCreator.helpOption();
   
    Option inputFileOpt = obuilder.withLongName("inputFile").withRequired(true).withArgument(
        abuilder.withName("inputFile").withMinimum(1).withMaximum(1).create()).withDescription(
        "The input file").withShortName("i").create();
   
    Option trainingOutputOpt = obuilder.withLongName("trainingOutputFile").withRequired(true).withArgument(
        abuilder.withName("trainingOutputFile").withMinimum(1).withMaximum(1).create()).withDescription(
        "The training data output file").withShortName("tr").create();
   
    Option testOutputOpt = obuilder.withLongName("testOutputFile").withRequired(true).withArgument(
        abuilder.withName("testOutputFile").withMinimum(1).withMaximum(1).create()).withDescription(
        "The test data output file").withShortName("te").create();
   
    Option trainingDataSizeOpt = obuilder.withLongName("trainingDataSize").withRequired(false).withArgument(
        abuilder.withName("trainingDataSize").withMinimum(1).withMaximum(1).create()).withDescription(
        "The number of questions to extract for training data").withShortName("trs").create();
   
    Option testDataSizeOpt = obuilder.withLongName("testDataSize").withRequired(false).withArgument(
        abuilder.withName("testDataSize").withMinimum(1).withMaximum(1).create()).withDescription(
        "The number of questions to extract for training data").withShortName("tes").create();

    Group group = gbuilder.withName("Options").withOption(inputFileOpt).withOption(trainingOutputOpt)
         .withOption(testOutputOpt).withOption(trainingDataSizeOpt).withOption(testDataSizeOpt).create();
View Full Code Here

TOP

Related Classes of no.priv.garshol.duke.utils.CommandLineParser$Option

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.