Example usage for org.apache.commons.cli CommandLine getOptions

List of usage examples for org.apache.commons.cli CommandLine getOptions

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine getOptions.

Prototype

public Option[] getOptions() 

Source Link

Document

Returns an array of the processed Option s.

Usage

From source file:tikka.hhl.apps.CommandLineOptions.java

/**
 * //from   w  w  w .  j  a v a  2s.c  o  m
 * @param cline
 * @throws IOException
 */
public CommandLineOptions(CommandLine cline) throws IOException {

    String opt = null;

    for (Option option : cline.getOptions()) {
        String value = option.getValue();
        switch (option.getOpt().charAt(0)) {
        case 'a':
            alpha = Double.parseDouble(value);
            break;
        case 'b':
            beta = Double.parseDouble(value);
            break;
        case 'c':
            if (value.equals("conll2k")) {
                dataFormat = DataFormatEnum.DataFormat.CONLL2K;
            } else if (value.equals("hashslash")) {
                dataFormat = DataFormatEnum.DataFormat.HASHSLASH;
            } else if (value.equals("pipesep")) {
                dataFormat = DataFormatEnum.DataFormat.PIPESEP;
            } else if (value.equals("raw")) {
                dataFormat = DataFormatEnum.DataFormat.RAW;
            } else {
                System.err.println("\"" + value + "\" is an unknown data format option.");
                System.exit(1);
            }
            break;
        case 'd':
            if (value.endsWith("" + File.separator)) {
                trainDataDir = value.substring(0, value.length() - 1);
            } else {
                trainDataDir = value;
            }
            break;
        case 'e':
            experimentModel = value;
            break;
        case 'f':
            if (value.endsWith("" + File.separator)) {
                testDataDir = value.substring(0, value.length() - 1);
            } else {
                testDataDir = value;
            }
            break;
        case 'g':
            gamma = Double.parseDouble(value);
            break;
        case 'i':
            opt = option.getOpt();
            if (opt.equals("itr")) {
                numIterations = Integer.parseInt(value);
            } else if (opt.equals("ite")) {
                testSetBurninIterations = Integer.parseInt(value);
            }
            break;
        case 'j':
            if (value.endsWith("" + File.separator)) {
                annotatedTestTextOutDir = value.substring(0, value.length() - 1);
            } else {
                annotatedTestTextOutDir = value;
            }
            break;
        case 'k':
            opt = option.getOpt();
            if (opt.equals("ks")) {
                samples = Integer.parseInt(value);
            } else if (opt.equals("kl")) {
                lag = Integer.parseInt(value);
            }
            break;
        case 'l':
            modelInputPath = value;
            break;
        case 'm':
            modelOutputPath = value;
            break;
        case 'n':
            if (value.endsWith("" + File.separator)) {
                annotatedTrainTextOutDir = value.substring(0, value.length() - 1);
            } else {
                annotatedTrainTextOutDir = value;
            }
            break;
        case 'o':
            opt = option.getOpt();
            if (opt.equals("ot")) {
                tabularOutputFilename = value;
                tabulatedOutput = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(tabularOutputFilename)));
            } else if (opt.equals("oste")) {
                testDataSampleScoreOutputFilename = value;
                testDataSampleScoreOutput = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(testDataSampleScoreOutputFilename)));
            } else if (opt.equals("ostr")) {
                trainDataSampleScoreOutputFilename = value;
                trainDataSampleScoreOutput = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(trainDataSampleScoreOutputFilename)));
            }
            break;
        case 'p':
            opt = option.getOpt();
            if (opt.equals("pi")) {
                initialTemperature = Double.parseDouble(value);
            } else if (opt.equals("pr")) {
                targetTemperature = Double.parseDouble(value);
            } else if (opt.equals("pt")) {
                temperatureDecrement = Double.parseDouble(value);
            }
            break;
        case 'q':
            topicSubStates = Integer.valueOf(value);
            break;
        case 'r':
            randomSeed = Integer.valueOf(value);
            break;
        case 's':
            states = Integer.parseInt(value);
            break;
        case 't':
            topics = Integer.parseInt(value);
            break;
        case 'w':
            outputPerClass = Integer.parseInt(value);
            break;
        case 'x':
            opt = option.getOpt();
            if (opt.equals("xmustembase")) {
                muStemBase = Double.parseDouble(value);
            } else if (opt.equals("xmustem")) {
                muStem = Double.parseDouble(value);
            } else if (opt.equals("xbetastembase")) {
                betaStemBase = Double.parseDouble(value);
            } else if (opt.equals("xbetastem")) {
                betaStem = Double.parseDouble(value);
            } else if (opt.equals("xmuaffixbase")) {
                muAffixBase = Double.parseDouble(value);
            } else if (opt.equals("xmuaffix")) {
                muAffix = Double.parseDouble(value);
            } else if (opt.equals("xpsi")) {
                psi = Double.parseDouble(value);
            } else if (opt.equals("xxi")) {
                xi = Double.parseDouble(value);
            } else if (opt.equals("xstemboundaryprob")) {
                stemBoundaryProb = Double.parseDouble(value);
            } else if (opt.equals("xaffixboundaryprob")) {
                affixBoundaryProb = Double.parseDouble(value);
            }
            break;
        }
    }
}

From source file:tikka.hmm.apps.CommandLineOptions.java

/**
 *
 * @param cline//  w  ww.j a v a 2s . c o m
 * @throws IOException
 */
public CommandLineOptions(CommandLine cline) throws IOException {

    String opt = null;

    for (Option option : cline.getOptions()) {
        String value = option.getValue();
        switch (option.getOpt().charAt(0)) {
        case 'a':
            alpha = Double.parseDouble(value);
            break;
        case 'b':
            beta = Double.parseDouble(value);
            break;
        case 'c':
            if (value.equals("conll2k")) {
                dataFormat = DataFormatEnum.DataFormat.CONLL2K;
            } else if (value.equals("hashslash")) {
                dataFormat = DataFormatEnum.DataFormat.HASHSLASH;
            } else if (value.equals("pipesep")) {
                dataFormat = DataFormatEnum.DataFormat.PIPESEP;
            } else if (value.equals("raw")) {
                dataFormat = DataFormatEnum.DataFormat.RAW;
            } else {
                System.err.println("\"" + value + "\" is an unknown data format option.");
                System.exit(1);
            }
            break;
        case 'd':
            if (value.endsWith("" + File.separator)) {
                trainDataDir = value.substring(0, value.length() - 1);
            } else {
                trainDataDir = value;
            }
            break;
        case 'e':
            experimentModel = value;
            break;
        case 'f':
            if (value.endsWith("" + File.separator)) {
                testDataDir = value.substring(0, value.length() - 1);
            } else {
                testDataDir = value;
            }
            break;
        case 'g':
            gamma = Double.parseDouble(value);
            break;
        case 'i':
            opt = option.getOpt();
            if (opt.equals("itr")) {
                numIterations = Integer.parseInt(value);
            } else if (opt.equals("ite")) {
                testSetBurninIterations = Integer.parseInt(value);
            }
            break;
        case 'j':
            if (value.endsWith("" + File.separator)) {
                annotatedTestTextOutDir = value.substring(0, value.length() - 1);
            } else {
                annotatedTestTextOutDir = value;
            }
            break;
        case 'k':
            opt = option.getOpt();
            if (opt.equals("ks")) {
                samples = Integer.parseInt(value);
            } else if (opt.equals("kl")) {
                lag = Integer.parseInt(value);
            }
            break;
        case 'l':
            modelInputPath = value;
            break;
        case 'm':
            modelOutputPath = value;
            break;
        case 'n':
            if (value.endsWith("" + File.separator)) {
                annotatedTrainTextOutDir = value.substring(0, value.length() - 1);
            } else {
                annotatedTrainTextOutDir = value;
            }
            break;
        case 'o':
            opt = option.getOpt();
            if (opt.equals("ot")) {
                tabularOutputFilename = value;
                tabulatedOutput = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(tabularOutputFilename)));
            } else if (opt.equals("oste")) {
                testDataSampleScoreOutputFilename = value;
                testDataSampleScoreOutput = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(testDataSampleScoreOutputFilename)));
            } else if (opt.equals("ostr")) {
                trainDataSampleScoreOutputFilename = value;
                trainDataSampleScoreOutput = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(trainDataSampleScoreOutputFilename)));
            } else if (opt.equals("oe")) {
                evaluationOutputFilename = value;
                evaluationOutput = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(evaluationOutputFilename)));
            }
            break;
        case 'p':
            opt = option.getOpt();
            if (opt.equals("pi")) {
                initialTemperature = Double.parseDouble(value);
            } else if (opt.equals("pd")) {
                temperatureDecrement = Double.parseDouble(value);
            } else if (opt.equals("pt")) {
                targetTemperature = Double.parseDouble(value);
            }
            break;
        case 'q':
            delta = Double.parseDouble(value);
            break;
        case 'r':
            randomSeed = Integer.valueOf(value);
            break;
        case 's':
            states = Integer.parseInt(value);
            break;
        case 't':
            topics = Integer.parseInt(value);
            break;
        case 'u':
            opt = option.getOpt();
            if (opt.equals("ut")) {
                if (value.equals("b")) {
                    tagSet = TagSetEnum.TagSet.BROWN;
                } else if (value.equals("p")) {
                    tagSet = TagSetEnum.TagSet.PTB;
                } else if (value.equals("t")) {
                    tagSet = TagSetEnum.TagSet.TIGER;
                }
            } else if (opt.equals("ur")) {
                int val = Integer.parseInt(value);
                if (val == 0) {
                    reductionLevel = TagSetEnum.ReductionLevel.FULL;
                } else {
                    reductionLevel = TagSetEnum.ReductionLevel.REDUCED;
                }
            }
            break;

        case 'w':
            outputPerClass = Integer.parseInt(value);
            break;
        }
    }
}

From source file:tool.export.LuceneSearch.java

public static void main(String[] args)
        throws IOException, ParseException, org.apache.commons.cli.ParseException {
    Options options = new Options();

    options.addOption("index", true, "Lucene Index Path");
    options.addOption("subject", true, "Subject");
    options.addOption("verb", true, "Verb");
    options.addOption("object", true, "Object");

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("index") && cmd.getOptions().length > 1) {
        IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(cmd.getOptionValue("index"))));
        IndexSearcher searcher = new IndexSearcher(reader);

        BooleanQuery booleanQuery = new BooleanQuery();
        BooleanQuery booleanSubjectQuery = new BooleanQuery();
        BooleanQuery booleanVerbQuery = new BooleanQuery();
        BooleanQuery booleanObjectQuery = new BooleanQuery();
        if (cmd.hasOption("subject")) {
            booleanSubjectQuery.add(/*from  w ww. j a v a2 s. c o  m*/
                    new TermQuery(new Term("SBJ-Y", cmd.getOptionValue("subject").toLowerCase())),
                    BooleanClause.Occur.SHOULD);
            booleanSubjectQuery.add(
                    new TermQuery(new Term("SBJ-T", cmd.getOptionValue("subject").toLowerCase())),
                    BooleanClause.Occur.SHOULD);
            booleanQuery.add(booleanSubjectQuery, BooleanClause.Occur.MUST);
        }

        if (cmd.hasOption("verb")) {
            booleanVerbQuery.add(new TermQuery(new Term("VERB", cmd.getOptionValue("verb").toLowerCase())),
                    BooleanClause.Occur.MUST);
            booleanQuery.add(booleanVerbQuery, BooleanClause.Occur.MUST);
        }

        if (cmd.hasOption("object")) {
            booleanObjectQuery.add(new TermQuery(new Term("OBJ-Y", cmd.getOptionValue("object").toLowerCase())),
                    BooleanClause.Occur.SHOULD);
            booleanObjectQuery.add(new TermQuery(new Term("OBJ-T", cmd.getOptionValue("object").toLowerCase())),
                    BooleanClause.Occur.SHOULD);
            booleanQuery.add(booleanObjectQuery, BooleanClause.Occur.MUST);
        }

        Sort sort = new Sort(new SortField("probability", SortField.Type.DOUBLE, true));

        TopDocs hits = searcher.search(booleanQuery, null, 1000, sort);

        for (int i = 0; i < hits.scoreDocs.length; i++) {
            Document document = searcher.doc(hits.scoreDocs[i].doc);
            for (IndexableField field : document.getFields()) {
                System.out.print(field.name() + ": " + field.stringValue() + "\t\t");
            }
            System.out.println();
        }
    } else {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("lucenesearch", options);
    }
}

From source file:tv.icntv.log.stb.core.AbstractJob.java

@Override
public int run(String[] args) throws Exception {
    if (null == args || args.length < 1) {
        logger.error("usage :-ruleFile <rule_file>");
        return -1;
    }/*w  ww  . j av  a 2  s  . com*/
    Map temp = Maps.newConcurrentMap();
    CommandLineParser parser = new PosixParser();
    CommandLine line = parser.parse(init(), args);

    for (Option option : line.getOptions()) {
        System.out.println(maps.get(option.getOpt()) + "\t" + option.getValue());
        temp.put(maps.get(option.getOpt()), option.getValue());
    }
    ;

    Configuration conf = super.getConf();

    conf.set("mapreduce.output.fileoutputformat.compress", "true");
    conf.set("mapreduce.output.fileoutputformat.compress.codec", "com.hadoop.compression.lzo.LzopCodec");
    conf.set("mapreduce.map.output.compress", "true");
    conf.set("mapreduce.map.output.compress.codec", "com.hadoop.compression.lzo.LzopCodec");
    return run(temp) ? 0 : 1;
}

From source file:uk.ac.ebi.smsd.cmd.ArgumentHandler.java

/**
 * Parses the options in the command line arguments and returns an array of
 * strings corresponding to the filenames given as arguments only
 *
 * @param args/*from  w w  w .ja v  a  2s .  com*/
 * @throws org.apache.commons.cli.ParseException
 */
@SuppressWarnings("static-access")
public void parseCommandLineOptions(String[] args) throws ParseException {

    options = new Options();

    options.addOption("h", "help", false, "Help page for command usage");

    options.addOption("s", false, "SubStructure detection");

    options.addOption("a", false, "Add Hydrogen");

    options.addOption("x", false, "Match Atom Type");

    options.addOption("r", false, "Remove Hydrogen");

    options.addOption("z", false, "Ring matching");

    options.addOption("b", false, "Match Bond types (Single, Double etc)");

    options.addOption(Option.builder("q").argName("query_file").hasArg().desc("Query filename").build());

    options.addOption(Option.builder("t").argName("target_file").hasArg().desc("Target filename").build());
    options.addOption(Option.builder("S").argName("suffix").hasArg().desc("Add suffix to the files").build());

    options.addOption("g", false, "create png of the mapping");

    options.addOption(Option.builder("d").argName("WIDTHxHEIGHT").hasArg()
            .desc("Dimension of the image in pixels").build());

    options.addOption("m", false, "Report all Mappings");

    String filterDescr = "Default: 0, Stereo: 1, " + "Stereo+Fragment: 2, Stereo+Fragment+Energy: 3";

    options.addOption(Option.builder("f").argName("filter_number").hasArg().desc(filterDescr).build());

    options.addOption("A", false, "Appends output to existing files, else creates new files");

    options.addOption(Option.builder("N").desc("Do N-way MCS on the target SD file").build());

    options.addOption(
            Option.builder("Q").argName("query_type").hasArg().desc("Query type (MOL, SMI, etc.)").build());

    options.addOption(Option.builder("T").argName("target_type").hasArg()
            .desc("Target type (MOL, SMI, SMIF, etc.)").build());

    options.addOption(
            Option.builder("o").argName("filename").hasArg().desc("Output the substructure to a file").build());

    options.addOption(Option.builder("O").argName("type").hasArg().desc("Output type (SMI, MOL)").build());

    options.addOption(Option.builder("I").argName("option=value").hasArg().desc("Image options").build());

    DefaultParser parser = new DefaultParser();
    CommandLine line = parser.parse(options, args, true);

    if (line.hasOption('Q')) {
        queryType = line.getOptionValue("Q");
    } //else {
    //            queryType = "MOL";
    //        } //XXX default type?

    if (line.hasOption('T')) {
        targetType = line.getOptionValue("T");
    } else {
        targetType = "MOL";
    }

    if (line.hasOption('a')) {
        this.setApplyHAdding(true);
    }

    if (line.hasOption('r')) {
        this.setApplyHRemoval(true);
    }

    if (line.hasOption('m')) {
        this.setAllMapping(true);
    }

    if (line.hasOption('s')) {
        this.setSubstructureMode(true);
    }

    if (line.hasOption('g')) {
        this.setImage(true);
    }

    if (line.hasOption('b')) {
        this.setMatchBondType(true);
    }

    if (line.hasOption('z')) {
        this.setMatchRingType(true);
    }

    if (line.hasOption('x')) {
        this.setMatchAtomType(true);
    }

    remainingArgs = line.getArgs();

    if (line.hasOption('h') || line.getOptions().length == 0) {
        //            System.out.println("Hello");
        helpRequested = true;
    }

    if (line.hasOption('S')) {
        String[] suffix_reader = line.getOptionValues('S');
        if (suffix_reader.length < 1) {
            System.out.println("Suffix required!");
            helpRequested = true;
        }
        setSuffix(suffix_reader[0]);
        setApplySuffix(true);
    }

    if (line.hasOption('f')) {
        String[] filters = line.getOptionValues('f');
        if (filters.length < 1) {
            System.out.println("Chemical filter required (Ranges: 0 to 3)!");
            helpRequested = true;
        }
        setChemFilter((int) new Integer(filters[0]));
    }

    if (line.hasOption('q')) {
        queryFilepath = line.getOptionValue('q');
    }

    if (line.hasOption('t')) {
        targetFilepath = line.getOptionValue('t');
    }

    if (line.hasOption("A")) {
        this.setAppendMode(true);
    }

    if (line.hasOption("N")) {
        setNMCS(true);
    }

    if (line.hasOption("o")) {
        outputSubgraph = true;
        outputFilepath = line.getOptionValue("o");
    }

    if (line.hasOption("O")) {
        outputFiletype = line.getOptionValue("O");
    } else {
        outputFiletype = "MOL";
    }

    if (line.hasOption("d")) {
        String dimensionString = line.getOptionValue("d");
        if (dimensionString.contains("x")) {
            String[] parts = dimensionString.split("x");
            try {
                setImageWidth(Integer.parseInt(parts[0]));
                setImageHeight(Integer.parseInt(parts[1]));
                System.out.println("set image dim to " + getImageWidth() + "x" + getImageHeight());
            } catch (NumberFormatException nfe) {
                throw new ParseException("Malformed dimension string " + dimensionString);
            }
        } else {
            throw new ParseException("Malformed dimension string " + dimensionString);
        }
    }

    if (line.hasOption("I")) {
        imageProperties = line.getOptionProperties("I");
        if (imageProperties.isEmpty()) {
            // used just "-I" by itself
            isImageOptionHelp = true;
        }
    }
}

From source file:uk.gov.gchq.gaffer.miniaccumulocluster.MiniAccumuloClusterController.java

protected MiniAccumuloClusterController(final String[] args) {
    final Options options = new Options();
    options.addOption("h", "help", false, "help");
    options.addOption("d", "dirName", true, "directory name");
    options.addOption("p", "password", true, "root password");
    options.addOption("n", "instanceName", true, "instance name");
    options.addOption("t", "useTempDir", false, "use a temporary directory");
    options.addOption("s", "heapSize", true, "heap size");

    final CommandLineParser parser = new BasicParser();
    try {//from   w  ww  . j a v  a2s  . com
        final CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            printHelp(options);
            System.exit(0);
        }
        if (cmd.getOptions().length == 0 && args.length > 0) {
            parseArgsOldFormat(args, options);
        } else {
            dirName = cmd.getOptionValue("d", DEFAULT_DIR_NAME);
            isTempDir = cmd.hasOption("t") || DEFAULT_IS_TEMP_DIR;
            password = cmd.getOptionValue("p", DEFAULT_PASSWORD);
            instanceName = cmd.getOptionValue("i", DEFAULT_INSTANCE_NAME);
            final String heapSizeStr = cmd.getOptionValue("s");
            if (null != heapSizeStr) {
                heapSize = Integer.parseInt(heapSizeStr);
            }
        }
    } catch (final ParseException e) {
        parseArgsOldFormat(args, options);
    }

    shutdownHook = true;
}

From source file:vpp.Main.java

private VppOptions parseArgs() throws ParseException {
    final Option outputPathOption = new Option("o", "output-path", true,
            "The output file or directory. If not specified then the "
                    + "output is written to standard output.");

    final Option helpOption = new Option("h", "help", false, "Print help for this application and exit");

    final Options options = new Options();
    options.addOption(outputPathOption);
    options.addOption(helpOption);/*from w w  w .  j av  a  2 s .  c  o m*/

    final GnuParser parser = new GnuParser();
    final CommandLine parsedArgs = parser.parse(options, this.args);
    final VppOptions vppOptions = new VppOptions();
    final String[] leftoverArgs = parsedArgs.getArgs();

    boolean printHelp = false;
    final Option[] parsedOptions = parsedArgs.getOptions();
    for (final Option option : parsedOptions) {
        final String value = option.getValue();
        if (option.getOpt().equals(helpOption.getOpt())) {
            printHelp = true;
        } else if (option.getOpt().equals(outputPathOption.getOpt())) {
            vppOptions.setDefine(value, "{post" + value + "}");
        }
    }

    for (final String leftoverArg : leftoverArgs) {
        vppOptions.addInputPath(leftoverArg);
    }

    if (printHelp) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("[options] [input paths]", options);
        return null;
    }

    return vppOptions;
}

From source file:w2v.WordToVec.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    Builder b = new Builder();
    Options options = new Options();
    options.addOption(OptionBuilder.hasArg().withArgName("file")
            .withDescription("Use text data from <file> to train the model").create("train"));
    options.addOption(OptionBuilder.hasArg().withArgName("file")
            .withDescription("Use <file> to save the resulting word vectors / word clusters").create("output"));
    options.addOption(OptionBuilder.hasArg().withArgName("int")
            .withDescription("Set size of word vectors; default is " + b.layerOneSize).create("size"));
    options.addOption(OptionBuilder.hasArg().withArgName("int")
            .withDescription("Set max skip length between words; default is " + b.window).create("window"));
    options.addOption(OptionBuilder.hasArg().withArgName("int").withDescription(
            "Set threshold for occurrence of words (0=off). Those that appear with higher frequency in the training data will be randomly down-sampled; default is "
                    + b.sample + ", useful value is 1e-5")
            .create("sample"));
    options.addOption(new Option("noHs", false,
            "Disable use of Hierarchical Softmax; " + (b.noHs ? "off" : "on") + " by default"));
    options.addOption(/*ww w.j  a v a  2  s. c  om*/
            OptionBuilder.hasArg().withArgName("int").withDescription("Number of negative examples; default is "
                    + b.negative + ", common values are 5 - 10 (0 = not used)").create("negative"));
    options.addOption(OptionBuilder.hasArg().withArgName("int")
            .withDescription("Use <int> threads (default " + b.numThreads + ")").create("threads"));
    options.addOption(OptionBuilder.hasArg().withArgName("int")
            .withDescription(
                    "This will discard words that appear less than <int> times; default is " + b.minCount)
            .create("minCount"));
    options.addOption(OptionBuilder.hasArg().withArgName("float")
            .withDescription("Set the starting learning rate; default is " + b.startingAlpha)
            .create("startingAlpha"));
    options.addOption(OptionBuilder.hasArg().withArgName("int")
            .withDescription(
                    "Number of word classes to output, or 0 to output word vectors; default is " + b.classes)
            .create("classes"));
    options.addOption(new Option("binary", false,
            "Save the resulting vectors in binary moded; " + (b.binary ? "on" : "off") + " by default"));
    options.addOption(OptionBuilder.hasArg().withArgName("file")
            .withDescription("The vocabulary will be saved to <file>").create("saveVocab"));
    options.addOption(OptionBuilder.hasArg().withArgName("file")
            .withDescription("The vocabulary will be read from <file>, not constructed from the training data")
            .create("readVocab"));
    options.addOption(new Option("cbow", false, "Use the continuous bag of words model; "
            + (b.cbow ? "on" : "off") + " by default (skip-gram model)"));

    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cl = parser.parse(options, args);
        if (cl.getOptions().length == 0) {
            new HelpFormatter().printHelp(WordToVec.class.getSimpleName(), options);
            System.exit(0);
        }
        if (cl.hasOption("size")) {
            b.layerOneSize = Integer.parseInt(cl.getOptionValue("size"));
        }
        if (cl.hasOption("train")) {
            b.trainFile = new File(cl.getOptionValue("train"));
        }
        if (cl.hasOption("saveVocab")) {
            b.saveVocabFile = new File(cl.getOptionValue("saveVocab"));
        }
        if (cl.hasOption("readVocab")) {
            b.readVocabFile = new File(cl.getOptionValue("readVocab"));
        }
        if (cl.hasOption("binary")) {
            b.binary = true;
        }
        if (cl.hasOption("cbow")) {
            b.cbow = true;
        }
        if (cl.hasOption("startingAlpha")) {
            b.startingAlpha = Float.parseFloat(cl.getOptionValue("startingAlpha"));
        }
        if (cl.hasOption("output")) {
            b.outputFile = new File(cl.getOptionValue("output"));
        }
        if (cl.hasOption("window")) {
            b.window = Integer.parseInt(cl.getOptionValue("window"));
        }
        if (cl.hasOption("sample")) {
            b.sample = Float.parseFloat(cl.getOptionValue("sample"));
        }
        if (cl.hasOption("noHs")) {
            b.noHs = true;
        }
        if (cl.hasOption("negative")) {
            b.negative = Integer.parseInt(cl.getOptionValue("negative"));
        }
        if (cl.hasOption("threads")) {
            b.numThreads = Integer.parseInt(cl.getOptionValue("threads"));
        }
        if (cl.hasOption("minCount")) {
            b.minCount = Integer.parseInt(cl.getOptionValue("minCount"));
        }
        if (cl.hasOption("classes")) {
            b.classes = Integer.parseInt(cl.getOptionValue("classes"));
        }
    } catch (Exception e) {
        System.err.println("Parsing command-line arguments failed. Reason: " + e.getMessage());
        new HelpFormatter().printHelp("word2vec", options);
        System.exit(1);
    }
    WordToVec word2vec = new WordToVec(b);
    word2vec.trainModel();
    System.exit(0);
}

From source file:wvw.utils.cmd.CmdUtils.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public boolean process(String[] args) {
    if (ArrayUtils.contains(args, "-help")) {
        help();//from w w  w  .j  a  v a  2  s  .com

        return false;
    }

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);

    } catch (ParseException e) {
        error(e);

        return false;
    }

    Option[] options = cmd.getOptions();
    for (Option option : options) {

        final String name = option.getOpt();
        CmdOption cmdOption = find(name);

        Object value = option.getValue();
        if (cmdOption.hasArg()) {

            if (value == null) {
                error("require value for option \"" + name + "\"");

                return false;
            }

            if (cmdOption.hasArgClz()) {

                if (cmdOption.getArgClz().equals(Integer.class)) {
                    try {
                        value = Integer.parseInt((String) value);

                    } catch (NumberFormatException e) {
                        error(e);

                        return false;
                    }

                } else if (cmdOption.getArgClz().equals(Double.class)) {
                    try {
                        value = Double.parseDouble((String) value);

                    } catch (NumberFormatException e) {
                        error(e);

                        return false;
                    }

                } else if (cmdOption.getArgClz().equals(String.class)) {

                } else {
                    error("unsupported argument class: " + cmdOption.getArgClzName());

                    return false;
                }
            }

            if (cmdOption.getOptions() != null) {

                if (!ArrayUtils.contains(cmdOption.getOptions(), value)) {
                    error("unsupported argument \"" + value + "\"");

                    return false;
                }
            }
        }

        if (!listener.cmdOptionValue(name, value))
            return false;
    }

    this.processedOptions = new ArrayList(Arrays.asList(options));

    if (!doPostCheck(options))
        return false;

    return true;
}