Package joshua.util

Examples of joshua.util.CommandLineParser$Option


   *
   * @param args Command line arguments
   */
  public static void main(String[] args) {

    CommandLineParser commandLine = new CommandLineParser();
   
    Option<String> source_file = commandLine.addStringOption('s',"source-text","SOURCE_FILENAME","name of file containing source language corpus");
    //Option<String> source_file_encoding = commandLine.addStringOption("source-encoding","SOURCE_ENCODING","ISO-8859-1","source language file encoding");
    Option<String> source_file_encoding = commandLine.addStringOption("source-encoding","SOURCE_ENCODING","UTF-8","source language file encoding");
    Option<Boolean> source_file_gz = commandLine.addBooleanOption("source-text-gzipped",false,"is the source text gzipped");
   
    Option<String> target_file = commandLine.addStringOption('t',"target-text","TARGET_FILENAME","name of file containing target language corpus");
    //Option<String> target_file_encoding = commandLine.addStringOption("target-encoding","TARGET_ENCODING","ISO-8859-1","target language file encoding");
    Option<String> target_file_encoding = commandLine.addStringOption("target-encoding","TARGET_ENCODING","UTF-8","target language file encoding");
    Option<Boolean> target_file_gz = commandLine.addBooleanOption("target-text-gzipped",false,"is the target text gzipped");
   
    Option<String> alignment_file = commandLine.addStringOption('a',"alignment","ALIGNMENT_FILENAME","name of file containing word alignments for the sentences in the corpus");
    Option<Boolean> alignment_file_gz = commandLine.addBooleanOption("alignment-file-gzipped",false,"is the alignment file gzipped");

    Option<Integer> num_lines = commandLine.addIntegerOption('l',"lines","LINE_COUNT","number of aligned sentences in the corpus");
   
    Option<String> output_file = commandLine.addStringOption('o',"output","OUTPUT_FILENAME","file where aligned word pairs will be written");
    Option<String> output_file_encoding = commandLine.addStringOption("output-encoding","OUTPUT_ENCODING","UTF-8","output file encoding");
    Option<Boolean> output_file_gz = commandLine.addBooleanOption("output-text-gzipped",false,"should the output file be gzipped");
   
    commandLine.parse(args);
   
   
    try {
     
      // Set System.out and System.err to use the provided character encoding
      try {
        System.setOut(new PrintStream(System.out, true, commandLine.getValue(source_file_encoding)));
        System.setErr(new PrintStream(System.err, true, commandLine.getValue(source_file_encoding)));
      } catch (UnsupportedEncodingException e1) {
        System.err.println(commandLine.getValue(source_file_encoding) + " is not a valid encoding; using system default encoding for System.out and System.err.");
      } catch (SecurityException e2) {
        System.err.println("Security manager is configured to disallow changes to System.out or System.err; using system default encoding.");
      }
     
      // The number of lines to read
      int number_of_lines = commandLine.getValue(num_lines);

      // Set up the source text for reading
      Scanner source_text;
      if (commandLine.getValue(source_file).endsWith(".gz") || commandLine.getValue(source_file_gz)) {
        source_text = new Scanner(new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(commandLine.getValue(source_file))),commandLine.getValue(source_file_encoding))));
      } else {
        source_text = new Scanner( new File(commandLine.getValue(source_file)), commandLine.getValue(source_file_encoding));
      }
     
      // Set up the target text for reading
      Scanner target_text;
      if (commandLine.getValue(target_file).endsWith(".gz") || commandLine.getValue(target_file_gz)) {
        target_text = new Scanner(new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(commandLine.getValue(target_file))),commandLine.getValue(target_file_encoding))));
      } else {
        target_text = new Scanner( new File(commandLine.getValue(target_file)), commandLine.getValue(target_file_encoding));
      }
     
      // Set up the alignment file for reading
      Scanner alignments;
      if (commandLine.getValue(alignment_file).endsWith(".gz") || commandLine.getValue(alignment_file_gz)) {
        alignments = new Scanner(new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(commandLine.getValue(alignment_file))))));
      } else {
        alignments = new Scanner( new File(commandLine.getValue(alignment_file)));
      }
     
     
      // Set up the output file for writing
      Writer outputFile;
      if (commandLine.getValue(output_file).endsWith(".gz") || commandLine.getValue(output_file_gz)) {
        outputFile = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(commandLine.getValue(output_file))),commandLine.getValue(output_file_encoding));
      } else {
        outputFile = new OutputStreamWriter(new FileOutputStream(commandLine.getValue(output_file)),commandLine.getValue(output_file_encoding));
      }
     
      try {
        extract(number_of_lines, source_text, target_text, alignments, outputFile);
      } catch (NoSuchElementException e) {
        System.err.println("There are more than " + number_of_lines + " lines of input. Please determine the actual number of lines of input, and re-run with the appropriate command line flag.");
        commandLine.printUsage();
        System.exit(-1);
      }

    } catch (FileNotFoundException e) {
      e.printStackTrace();
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

 
  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 countFileOpt = obuilder.withLongName("countFile").withRequired(true).withArgument(
        abuilder.withName("countFile").withMinimum(1).withMaximum(1).create()).withDescription(
        "The tag count file").withShortName("c").create();
   
    Option outputFileOpt = obuilder.withLongName("outputFile").withRequired(true).withArgument(
        abuilder.withName("outputFile").withMinimum(1).withMaximum(1).create()).withDescription(
        "The output file").withShortName("c").create();
   
    Option solrUrlOpt = obuilder.withLongName("solrUrl").withRequired(true).withArgument(
        abuilder.withName("solrUrl").withMinimum(1).withMaximum(1).create()).withDescription(
        "URL of the solr server").withShortName("s").create();
   
    Group group = gbuilder.withName("Options")
      .withOption(inputFileOpt)
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 outputFileOpt = obuilder.withLongName("outputFile").withRequired(true).withArgument(
        abuilder.withName("outputFile").withMinimum(1).withMaximum(1).create()).withDescription(
        "The output file").withShortName("o").create();

    Option limitOpt = obuilder.withLongName("limit").withRequired(false).withArgument(
        abuilder.withName("limit").withMinimum(1).withMaximum(1).create()).withDescription(
        "Emit this many of the most frequent tags").withShortName("l").create();
   
    Option cutoffOpt = obuilder.withLongName("cutoff").withRequired(false).withArgument(
        abuilder.withName("cutoff").withMinimum(1).withMaximum(1).create()).withDescription(
        "Drop tags with a count less than this number").withShortName("c").create();
   
    Group group = gbuilder.withName("Options").withOption(inputFileOpt)
      .withOption(outputFileOpt).withOption(limitOpt)
View Full Code Here

   
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();
   
    Option inputOpt = obuilder.withLongName("input")
      .withRequired(true)
      .withArgument(
        abuilder.withName("input")
          .withMinimum(1)
          .withMaximum(1).create())
      .withDescription("Input file")
      .withShortName("i").create();
   
    Option modelOpt = obuilder.withLongName("model")
    .withRequired(true)
    .withArgument(
      abuilder.withName("model")
        .withMinimum(1)
        .withMaximum(1).create())
    .withDescription("Model to use when classifying data")
    .withShortName("m").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 static void main(String[] args) throws Exception {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option wikipediaFileOpt = obuilder.withLongName("wikiFile").withRequired(true).withArgument(
            abuilder.withName("wikiFile").withMinimum(1).withMaximum(1).create()).
            withDescription("The path to the wikipedia dump file.  Maybe a directory containing wikipedia dump files." +
                    "  If a directory is specified, only .xml files are used.").withShortName("w").create();

    Option numDocsOpt = obuilder.withLongName("numDocs").withRequired(false).withArgument(
            abuilder.withName("numDocs").withMinimum(1).withMaximum(1).create()).
            withDescription("The number of docs to index").withShortName("n").create();

    Option solrURLOpt = obuilder.withLongName("solrURL").withRequired(false).withArgument(
            abuilder.withName("solrURL").withMinimum(1).withMaximum(1).create()).
            withDescription("The URL where Solr lives").withShortName("s").create();

    Option solrBatchOpt = obuilder.withLongName("batch").withRequired(false).withArgument(
            abuilder.withName("batch").withMinimum(1).withMaximum(1).create()).
            withDescription("The number of docs to include in each indexing batch").withShortName("b").create();

    Group group = gbuilder.withName("Options").withOption(wikipediaFileOpt).withOption(numDocsOpt).withOption(solrURLOpt).withOption(solrBatchOpt).create();
View Full Code Here

TOP

Related Classes of joshua.util.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.