Package no.priv.garshol.duke.utils

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


   */
  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

TOP

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

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.