Example usage for org.apache.commons.cli2.commandline Parser parseAndHelp

List of usage examples for org.apache.commons.cli2.commandline Parser parseAndHelp

Introduction

In this page you can find the example usage for org.apache.commons.cli2.commandline Parser parseAndHelp.

Prototype

public CommandLine parseAndHelp(final String[] arguments) 

Source Link

Document

Parse the arguments according to the specified options and properties and displays the usage screen if the CommandLine is not valid or the help option was specified.

Usage

From source file:haflow.component.mahout.logistic.RunLogistic.java

private static boolean parseArgs(String[] args) {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create();

    Option auc = builder.withLongName("auc").withDescription("print AUC").create();
    Option confusion = builder.withLongName("confusion").withDescription("print confusion matrix").create();

    Option scores = builder.withLongName("scores").withDescription("print scores").create();

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFileOption = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option modelFileOption = builder.withLongName("model").withRequired(true)
            .withArgument(argumentBuilder.withName("model").withMaximum(1).create())
            .withDescription("where to get a model").create();
    Option outputFileOption = builder.withLongName("output").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription("where to store predicting data").create();
    Option accurateFileOption = builder.withLongName("accurate").withRequired(true)
            .withArgument(argumentBuilder.withName("accurate").withMaximum(1).create())
            .withDescription("where to store accurate information").create();
    Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(auc).withOption(scores)
            .withOption(confusion).withOption(inputFileOption).withOption(modelFileOption)
            .withOption(outputFileOption).withOption(accurateFileOption).create();

    Parser parser = new Parser();
    parser.setHelpOption(help);/*from   www .  j a va2 s.com*/
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        return false;
    }

    inputFile = getStringArgument(cmdLine, inputFileOption);
    modelFile = getStringArgument(cmdLine, modelFileOption);
    outputFile = getStringArgument(cmdLine, outputFileOption);
    accurateFile = getStringArgument(cmdLine, accurateFileOption);
    showAuc = getBooleanArgument(cmdLine, auc);
    showScores = getBooleanArgument(cmdLine, scores);
    showConfusion = getBooleanArgument(cmdLine, confusion);

    return true;
}

From source file:com.ml.ira.algos.RunLogistic.java

private static boolean parseArgs(String[] args) {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create();

    Option auc = builder.withLongName("auc").withDescription("print AUC").create();
    Option confusion = builder.withLongName("confusion").withDescription("print confusion matrix").create();

    Option scores = builder.withLongName("scores").withDescription("print scores").create();

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFileOption = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option modelFileOption = builder.withLongName("model").withRequired(true)
            .withArgument(argumentBuilder.withName("model").withMaximum(1).create())
            .withDescription("where to get a model").create();

    Option fieldNames = builder.withLongName("fdnames").withRequired(true)
            .withArgument(argumentBuilder.withName("fns").create())
            .withDescription("the field names of training data set").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(auc).withOption(scores)
            .withOption(confusion).withOption(inputFileOption).withOption(modelFileOption)
            .withOption(fieldNames).create();

    Parser parser = new Parser();
    parser.setHelpOption(help);/*from   w  w w  . j  a v  a2 s .  c  om*/
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        return false;
    }

    inputFile = getStringArgument(cmdLine, inputFileOption);
    modelFile = getStringArgument(cmdLine, modelFileOption);
    showAuc = getBooleanArgument(cmdLine, auc);
    showScores = getBooleanArgument(cmdLine, scores);
    showConfusion = getBooleanArgument(cmdLine, confusion);
    RunLogistic.fieldNames = getStringArgument(cmdLine, fieldNames);

    System.out.println("inputFile: " + inputFile);
    System.out.println("modelFile: " + modelFile);
    System.out.println("fieldNames: " + RunLogistic.fieldNames);

    return true;
}

From source file:com.cloudera.knittingboar.conf.cmdline.DataConverterCmdLineDriver.java

private static boolean parseArgs(String[] args) throws IOException {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    // Option quiet =
    // builder.withLongName("quiet").withDescription("be extra quiet").create();
    // Option scores =
    // builder.withLongName("scores").withDescription("output score diagnostics during training").create();

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFileOption = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get input data").create();

    Option outputFileOption = builder.withLongName("output").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription("where to write output data").create();

    Option recordsPerBlockOption = builder.withLongName("recordsPerBlock")
            .withArgument(/*from ww w  .  j a  va2s . co  m*/
                    argumentBuilder.withName("recordsPerBlock").withDefault("20000").withMaximum(1).create())
            .withDescription("the number of records per output file shard to write").create();

    // optionally can be { 20Newsgroups, rcv1 }
    Option RecordFactoryType = builder
            .withLongName("datasetType").withArgument(argumentBuilder.withName("recordFactoryType")
                    .withDefault("20Newsgroups").withMaximum(1).create())
            .withDescription("the type of dataset to convert").create();

    /*
     * Option passes = builder.withLongName("passes") .withArgument(
     * argumentBuilder.withName("passes") .withDefault("2")
     * .withMaximum(1).create())
     * .withDescription("the number of times to pass over the input data")
     * .create();
     * 
     * Option lambda = builder.withLongName("lambda")
     * .withArgument(argumentBuilder
     * .withName("lambda").withDefault("1e-4").withMaximum(1).create())
     * .withDescription("the amount of coefficient decay to use") .create();
     * 
     * Option rate = builder.withLongName("rate")
     * .withArgument(argumentBuilder.withName
     * ("learningRate").withDefault("1e-3").withMaximum(1).create())
     * .withDescription("the learning rate") .create();
     * 
     * Option noBias = builder.withLongName("noBias")
     * .withDescription("don't include a bias term") .create();
     */

    Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption)
            .withOption(outputFileOption).withOption(recordsPerBlockOption).withOption(RecordFactoryType)
            .create();

    Parser parser = new Parser();
    parser.setHelpOption(help);
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {

        System.out.println("null!");
        return false;
    }

    // "/Users/jpatterson/Downloads/datasets/20news-bydate/20news-bydate-train/"
    strInputFile = getStringArgument(cmdLine, inputFileOption);

    // "/Users/jpatterson/Downloads/datasets/20news-kboar/train4/"
    strOutputFile = getStringArgument(cmdLine, outputFileOption);

    strrecordsPerBlock = getStringArgument(cmdLine, recordsPerBlockOption);

    return true;
}

From source file:com.cloudera.knittingboar.conf.cmdline.ModelTrainerCmdLineDriver.java

private static boolean parseArgs(String[] args) {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    // Option quiet =
    // builder.withLongName("quiet").withDescription("be extra quiet").create();
    // Option scores =
    // builder.withLongName("scores").withDescription("output score diagnostics during training").create();

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFile = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option outputFile = builder.withLongName("output").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option features = builder.withLongName("features")
            .withArgument(argumentBuilder.withName("numFeatures").withDefault("1000").withMaximum(1).create())
            .withDescription("the number of internal hashed features to use").create();

    // optionally can be { 20Newsgroups, rcv1 }
    Option RecordFactoryType = builder.withLongName("recordFactoryType")
            .withArgument(argumentBuilder.withName("recordFactoryType").withDefault("20Newsgroups")
                    .withMaximum(1).create())
            .withDescription("the record vectorization factory to use").create();

    Option passes = builder.withLongName("passes")
            .withArgument(argumentBuilder.withName("passes").withDefault("2").withMaximum(1).create())
            .withDescription("the number of times to pass over the input data").create();

    Option lambda = builder.withLongName("lambda")
            .withArgument(argumentBuilder.withName("lambda").withDefault("1e-4").withMaximum(1).create())
            .withDescription("the amount of coefficient decay to use").create();

    Option rate = builder.withLongName("rate")
            .withArgument(argumentBuilder.withName("learningRate").withDefault("1e-3").withMaximum(1).create())
            .withDescription("the learning rate").create();

    Option noBias = builder.withLongName("noBias").withDescription("don't include a bias term").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFile).withOption(outputFile)
            .withOption(RecordFactoryType).withOption(passes).withOption(lambda).withOption(rate)
            .withOption(noBias).withOption(features).create();

    Parser parser = new Parser();
    parser.setHelpOption(help);// w  w  w. j  a va 2  s .c o m
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {

        System.out.println("null!");
        return false;
    }

    input_dir = getStringArgument(cmdLine, inputFile);
    output_dir = getStringArgument(cmdLine, outputFile);

    /*
     * TrainLogistic.inputFile = getStringArgument(cmdLine, inputFile);
     * TrainLogistic.outputFile = getStringArgument(cmdLine, outputFile);
     * 
     * List<String> typeList = Lists.newArrayList(); for (Object x :
     * cmdLine.getValues(types)) { typeList.add(x.toString()); }
     * 
     * List<String> predictorList = Lists.newArrayList(); for (Object x :
     * cmdLine.getValues(predictors)) { predictorList.add(x.toString()); }
     * 
     * lmp = new LogisticModelParameters();
     * lmp.setTargetVariable(getStringArgument(cmdLine, target));
     * lmp.setMaxTargetCategories(getIntegerArgument(cmdLine,
     * targetCategories)); lmp.setNumFeatures(getIntegerArgument(cmdLine,
     * features)); lmp.setUseBias(!getBooleanArgument(cmdLine, noBias));
     * lmp.setTypeMap(predictorList, typeList);
     * 
     * lmp.setLambda(getDoubleArgument(cmdLine, lambda));
     * lmp.setLearningRate(getDoubleArgument(cmdLine, rate));
     * 
     * TrainLogistic.scores = getBooleanArgument(cmdLine, scores);
     * TrainLogistic.passes = getIntegerArgument(cmdLine, passes);
     */
    return true;
}

From source file:com.ml.ira.algos.TrainLogistic.java

private static boolean parseArgs(String[] args) {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create();
    Option scores = builder.withLongName("scores").withDescription("output score diagnostics during training")
            .create();//w  w w .  j a  v a2 s .co  m

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFile = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option outputFile = builder.withLongName("output").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option predictors = builder.withLongName("predictors").withRequired(true)
            .withArgument(argumentBuilder.withName("p").create())
            .withDescription("a list of predictor variables").create();

    Option types = builder.withLongName("types").withRequired(true)
            .withArgument(argumentBuilder.withName("t").create())
            .withDescription("a list of predictor variable types (numeric, word, or text)").create();

    Option target = builder.withLongName("target").withRequired(true)
            .withArgument(argumentBuilder.withName("target").withMaximum(1).create())
            .withDescription("the name of the target variable").create();

    Option features = builder.withLongName("features")
            .withArgument(argumentBuilder.withName("numFeatures").withDefault("1000").withMaximum(1).create())
            .withDescription("the number of internal hashed features to use").create();

    Option passes = builder.withLongName("passes")
            .withArgument(argumentBuilder.withName("passes").withDefault("2").withMaximum(1).create())
            .withDescription("the number of times to pass over the input data").create();

    Option lambda = builder.withLongName("lambda")
            .withArgument(argumentBuilder.withName("lambda").withDefault("1e-4").withMaximum(1).create())
            .withDescription("the amount of coefficient decay to use").create();

    Option rate = builder.withLongName("rate")
            .withArgument(argumentBuilder.withName("learningRate").withDefault("1e-3").withMaximum(1).create())
            .withDescription("the learning rate").create();

    Option noBias = builder.withLongName("noBias").withDescription("don't include a bias term").create();

    Option targetCategories = builder.withLongName("categories").withRequired(true)
            .withArgument(argumentBuilder.withName("number").withMaximum(1).create())
            .withDescription("the number of target categories to be considered").create();

    Option fieldNames = builder.withLongName("fdnames").withRequired(true)
            .withArgument(argumentBuilder.withName("fns").create())
            .withDescription("the field names of training data set").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(inputFile)
            .withOption(outputFile).withOption(target).withOption(targetCategories).withOption(predictors)
            .withOption(types).withOption(passes).withOption(lambda).withOption(rate).withOption(noBias)
            .withOption(features).withOption(fieldNames).create();

    Parser parser = new Parser();
    parser.setHelpOption(help);
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        return false;
    }

    TrainLogistic.inputFile = getStringArgument(cmdLine, inputFile);
    TrainLogistic.outputFile = getStringArgument(cmdLine, outputFile);
    TrainLogistic.fieldNames = getStringArgument(cmdLine, fieldNames);

    List<String> typeList = Lists.newArrayList();
    String tmp = getStringArgument(cmdLine, types);
    if (tmp != null) {
        typeList.addAll(Arrays.asList(tmp.split(",")));
    }

    tmp = getStringArgument(cmdLine, predictors);
    List<String> predictorList = Lists.newArrayList();
    if (tmp != null) {
        predictorList.addAll(Arrays.asList(tmp.split(",")));
    }

    lmp = new LogisticModelParameters();
    lmp.setTargetVariable(getStringArgument(cmdLine, target));
    lmp.setMaxTargetCategories(getIntegerArgument(cmdLine, targetCategories));
    lmp.setNumFeatures(getIntegerArgument(cmdLine, features));
    lmp.setUseBias(!getBooleanArgument(cmdLine, noBias));
    lmp.setTypeMap(predictorList, typeList);
    lmp.setFieldNames(TrainLogistic.fieldNames);
    lmp.setLambda(getDoubleArgument(cmdLine, lambda));
    lmp.setLearningRate(getDoubleArgument(cmdLine, rate));

    TrainLogistic.scores = getBooleanArgument(cmdLine, scores);
    TrainLogistic.passes = getIntegerArgument(cmdLine, passes);

    System.out.println("@Train inputFile: " + TrainLogistic.inputFile);
    System.out.println("@Train fieldNames: " + TrainLogistic.fieldNames);
    System.out.println("@Train typeList: " + typeList);
    System.out.println("@Train predictorList: " + predictorList);

    return true;
}

From source file:haflow.component.mahout.logistic.TrainLogistic.java

private static boolean parseArgs(String[] args) {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create();
    Option scores = builder.withLongName("scores").withDescription("output score diagnostics during training")
            .create();/*from  w  w w .  ja  v  a  2  s.c om*/

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFile = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option outputFile = builder.withLongName("output").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription("where to get training data").create();
    Option inforFile = builder.withLongName("infor").withRequired(true)
            .withArgument(argumentBuilder.withName("infor").withMaximum(1).create())
            .withDescription("where to store information about the training").create();

    Option predictors = builder.withLongName("predictors").withRequired(true)
            .withArgument(argumentBuilder.withName("p").create())
            .withDescription("a list of predictor variables").create();

    Option types = builder.withLongName("types").withRequired(true)
            .withArgument(argumentBuilder.withName("t").create())
            .withDescription("a list of predictor variable types (numeric, word, or text)").create();

    Option target = builder.withLongName("target").withRequired(true)
            .withArgument(argumentBuilder.withName("target").withMaximum(1).create())
            .withDescription("the name of the target variable").create();

    Option features = builder.withLongName("features")
            .withArgument(argumentBuilder.withName("numFeatures").withDefault("1000").withMaximum(1).create())
            .withDescription("the number of internal hashed features to use").create();

    Option passes = builder.withLongName("passes")
            .withArgument(argumentBuilder.withName("passes").withDefault("2").withMaximum(1).create())
            .withDescription("the number of times to pass over the input data").create();

    Option lambda = builder.withLongName("lambda")
            .withArgument(argumentBuilder.withName("lambda").withDefault("1e-4").withMaximum(1).create())
            .withDescription("the amount of coefficient decay to use").create();

    Option rate = builder.withLongName("rate")
            .withArgument(argumentBuilder.withName("learningRate").withDefault("1e-3").withMaximum(1).create())
            .withDescription("the learning rate").create();

    Option noBias = builder.withLongName("noBias").withDescription("don't include a bias term").create();

    Option targetCategories = builder.withLongName("categories").withRequired(true)
            .withArgument(argumentBuilder.withName("number").withMaximum(1).create())
            .withDescription("the number of target categories to be considered").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(inputFile)
            .withOption(outputFile).withOption(inforFile).withOption(target).withOption(targetCategories)
            .withOption(predictors).withOption(types).withOption(passes).withOption(lambda).withOption(rate)
            .withOption(noBias).withOption(features).create();

    Parser parser = new Parser();
    parser.setHelpOption(help);
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        return false;
    }

    TrainLogistic.inputFile = getStringArgument(cmdLine, inputFile);
    TrainLogistic.outputFile = getStringArgument(cmdLine, outputFile);
    TrainLogistic.inforFile = getStringArgument(cmdLine, inforFile);

    List<String> typeList = Lists.newArrayList();
    for (Object x : cmdLine.getValues(types)) {
        typeList.add(x.toString());
    }

    List<String> predictorList = Lists.newArrayList();
    for (Object x : cmdLine.getValues(predictors)) {
        predictorList.add(x.toString());
    }

    lmp = new LogisticModelParameters();
    lmp.setTargetVariable(getStringArgument(cmdLine, target));
    lmp.setMaxTargetCategories(getIntegerArgument(cmdLine, targetCategories));
    lmp.setNumFeatures(getIntegerArgument(cmdLine, features));
    lmp.setUseBias(!getBooleanArgument(cmdLine, noBias));
    lmp.setTypeMap(predictorList, typeList);

    lmp.setLambda(getDoubleArgument(cmdLine, lambda));
    lmp.setLearningRate(getDoubleArgument(cmdLine, rate));

    TrainLogistic.scores = getBooleanArgument(cmdLine, scores);
    TrainLogistic.passes = getIntegerArgument(cmdLine, passes);
    System.out.print("infor:" + TrainLogistic.inforFile);

    System.out.println("target:" + getStringArgument(cmdLine, target));
    System.out.println("targetCategories:" + String.valueOf(getStringArgument(cmdLine, targetCategories)));
    System.out.println("features:" + String.valueOf(getStringArgument(cmdLine, features)));
    System.out.println("lambda:" + String.valueOf(getStringArgument(cmdLine, lambda)));
    System.out.println("rate:" + String.valueOf(getStringArgument(cmdLine, rate)));
    return true;
}

From source file:TrainLogistic.java

private static boolean parseArgs(String[] args) {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create();
    Option scores = builder.withLongName("scores").withDescription("output score diagnostics during training")
            .create();//from   w  ww.j  a  va2  s.c o m

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFile = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option outputFile = builder.withLongName("output").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option predictors = builder.withLongName("predictors").withRequired(true)
            .withArgument(argumentBuilder.withName("p").create())
            .withDescription("a list of predictor variables").create();

    Option types = builder.withLongName("types").withRequired(true)
            .withArgument(argumentBuilder.withName("t").create())
            .withDescription("a list of predictor variable types (numeric, word, or text)").create();

    Option target = builder.withLongName("target").withRequired(true)
            .withArgument(argumentBuilder.withName("target").withMaximum(1).create())
            .withDescription("the name of the target variable").create();

    Option features = builder.withLongName("features")
            .withArgument(argumentBuilder.withName("numFeatures").withDefault("1000").withMaximum(1).create())
            .withDescription("the number of internal hashed features to use").create();

    Option passes = builder.withLongName("passes")
            .withArgument(argumentBuilder.withName("passes").withDefault("2").withMaximum(1).create())
            .withDescription("the number of times to pass over the input data").create();

    Option lambda = builder.withLongName("lambda")
            .withArgument(argumentBuilder.withName("lambda").withDefault("1e-4").withMaximum(1).create())
            .withDescription("the amount of coefficient decay to use").create();

    Option rate = builder.withLongName("rate")
            .withArgument(argumentBuilder.withName("learningRate").withDefault("1e-3").withMaximum(1).create())
            .withDescription("the learning rate").create();

    Option noBias = builder.withLongName("noBias").withDescription("don't include a bias term").create();

    Option targetCategories = builder.withLongName("categories").withRequired(true)
            .withArgument(argumentBuilder.withName("number").withMaximum(1).create())
            .withDescription("the number of target categories to be considered").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(inputFile)
            .withOption(outputFile).withOption(target).withOption(targetCategories).withOption(predictors)
            .withOption(types).withOption(passes).withOption(lambda).withOption(rate).withOption(noBias)
            .withOption(features).create();

    Parser parser = new Parser();
    parser.setHelpOption(help);
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        System.out.println(args);
        return false;
    }

    TrainLogistic.inputFile = getStringArgument(cmdLine, inputFile);
    TrainLogistic.outputFile = getStringArgument(cmdLine, outputFile);

    List<String> typeList = Lists.newArrayList();
    for (Object x : cmdLine.getValues(types)) {
        typeList.add(x.toString());
    }

    List<String> predictorList = Lists.newArrayList();
    for (Object x : cmdLine.getValues(predictors)) {
        predictorList.add(x.toString());
    }

    lmp = new LogisticModelParameters();
    lmp.setTargetVariable(getStringArgument(cmdLine, target));
    lmp.setMaxTargetCategories(getIntegerArgument(cmdLine, targetCategories));
    lmp.setNumFeatures(getIntegerArgument(cmdLine, features));
    lmp.setUseBias(!getBooleanArgument(cmdLine, noBias));
    lmp.setTypeMap(predictorList, typeList);

    lmp.setLambda(getDoubleArgument(cmdLine, lambda));
    lmp.setLearningRate(getDoubleArgument(cmdLine, rate));

    TrainLogistic.scores = getBooleanArgument(cmdLine, scores);
    TrainLogistic.passes = getIntegerArgument(cmdLine, passes);

    return true;
}

From source file:broadwick.CliOptions.java

/**
 * Construct and provide GNU-compatible Options. Read the command line extracting the arguments, this
 * additionally displays the help message if the command line is empty.
 *
 * @param args the command line arguments.
 *//*w  w  w .  ja v  a 2 s . c o m*/
public CliOptions(final String[] args) {
    buildCommandLineArguments();

    final Parser parser = new Parser();
    parser.setGroup(options);
    final HelpFormatter hf = new HelpFormatter(SPACE, SPACE, SPACE, LINEWIDTH);
    parser.setHelpFormatter(hf);
    parser.setHelpTrigger("--help");
    cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        hf.printHeader();
        throw new BroadwickException("Empty command line.");
    }

    validateCommandLineArguments();
}

From source file:com.memonews.mahout.sentiment.SentimentModelTester.java

boolean parseArgs(final String[] args) {
    final DefaultOptionBuilder builder = new DefaultOptionBuilder();

    final Option help = builder.withLongName("help").withDescription("print this list").create();

    final ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    final Option inputFileOption = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    final Option modelFileOption = builder.withLongName("model").withRequired(true)
            .withArgument(argumentBuilder.withName("model").withMaximum(1).create())
            .withDescription("where to get a model").create();

    final Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption)
            .withOption(modelFileOption).create();

    final Parser parser = new Parser();
    parser.setHelpOption(help);//from  ww  w. j a v a  2s  . c o  m
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    final CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        return false;
    }

    inputFile = (String) cmdLine.getValue(inputFileOption);
    modelFile = (String) cmdLine.getValue(modelFileOption);
    return true;
}

From source file:org.apache.mahout.classifier.mlp.RunMultilayerPerceptron.java

/**
 * Parse the arguments.//from   www. ja v a2  s .  c o m
 *
 * @param args The input arguments.
 * @param parameters  The parameters need to be filled.
 * @return true or false
 * @throws Exception
 */
private static boolean parseArgs(String[] args, Parameters parameters) throws Exception {
    // build the options
    log.info("Validate and parse arguments...");
    DefaultOptionBuilder optionBuilder = new DefaultOptionBuilder();
    GroupBuilder groupBuilder = new GroupBuilder();
    ArgumentBuilder argumentBuilder = new ArgumentBuilder();

    Option inputFileFormatOption = optionBuilder
            .withLongName("format").withShortName("f").withArgument(argumentBuilder.withName("file type")
                    .withDefault("csv").withMinimum(1).withMaximum(1).create())
            .withDescription("type of input file, currently support 'csv'").create();

    List<Integer> columnRangeDefault = Lists.newArrayList();
    columnRangeDefault.add(0);
    columnRangeDefault.add(Integer.MAX_VALUE);

    Option skipHeaderOption = optionBuilder.withLongName("skipHeader").withShortName("sh").withRequired(false)
            .withDescription("whether to skip the first row of the input file").create();

    Option inputColumnRangeOption = optionBuilder.withLongName("columnRange").withShortName("cr")
            .withDescription("the column range of the input file, start from 0").withArgument(argumentBuilder
                    .withName("range").withMinimum(2).withMaximum(2).withDefaults(columnRangeDefault).create())
            .create();

    Group inputFileTypeGroup = groupBuilder.withOption(skipHeaderOption).withOption(inputColumnRangeOption)
            .withOption(inputFileFormatOption).create();

    Option inputOption = optionBuilder.withLongName("input").withShortName("i").withRequired(true)
            .withArgument(argumentBuilder.withName("file path").withMinimum(1).withMaximum(1).create())
            .withDescription("the file path of unlabelled dataset").withChildren(inputFileTypeGroup).create();

    Option modelOption = optionBuilder.withLongName("model").withShortName("mo").withRequired(true)
            .withArgument(argumentBuilder.withName("model file").withMinimum(1).withMaximum(1).create())
            .withDescription("the file path of the model").create();

    Option labelsOption = optionBuilder.withLongName("labels").withShortName("labels")
            .withArgument(argumentBuilder.withName("label-name").withMinimum(2).create())
            .withDescription("an ordered list of label names").create();

    Group labelsGroup = groupBuilder.withOption(labelsOption).create();

    Option outputOption = optionBuilder.withLongName("output").withShortName("o").withRequired(true)
            .withArgument(
                    argumentBuilder.withConsumeRemaining("file path").withMinimum(1).withMaximum(1).create())
            .withDescription("the file path of labelled results").withChildren(labelsGroup).create();

    // parse the input
    Parser parser = new Parser();
    Group normalOption = groupBuilder.withOption(inputOption).withOption(modelOption).withOption(outputOption)
            .create();
    parser.setGroup(normalOption);
    CommandLine commandLine = parser.parseAndHelp(args);
    if (commandLine == null) {
        return false;
    }

    // obtain the arguments
    parameters.inputFilePathStr = TrainMultilayerPerceptron.getString(commandLine, inputOption);
    parameters.inputFileFormat = TrainMultilayerPerceptron.getString(commandLine, inputFileFormatOption);
    parameters.skipHeader = commandLine.hasOption(skipHeaderOption);
    parameters.modelFilePathStr = TrainMultilayerPerceptron.getString(commandLine, modelOption);
    parameters.outputFilePathStr = TrainMultilayerPerceptron.getString(commandLine, outputOption);

    List<?> columnRange = commandLine.getValues(inputColumnRangeOption);
    parameters.columnStart = Integer.parseInt(columnRange.get(0).toString());
    parameters.columnEnd = Integer.parseInt(columnRange.get(1).toString());

    return true;
}