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

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

Introduction

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

Prototype

public void setHelpTrigger(final String helpTrigger) 

Source Link

Document

Sets the help option to use with the simplified parsing.

Usage

From source file:org.apache.mahout.classifier.sgd.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();

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

    Parser parser = new Parser();
    parser.setHelpOption(help);/*  ww  w. jav  a2 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);
    showAuc = getBooleanArgument(cmdLine, auc);
    showScores = getBooleanArgument(cmdLine, scores);
    showConfusion = getBooleanArgument(cmdLine, confusion);

    return true;
}

From source file:org.apache.mahout.classifier.sgd.TestASFEmail.java

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

    Option help = builder.withLongName("help").withDescription("print this list").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();

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

    Parser parser = new Parser();
    parser.setHelpOption(help);// www.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) {
        return false;
    }

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

From source file:org.apache.mahout.classifier.sgd.TrainAdaptiveLogistic.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();

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option showperf = builder.withLongName("showperf")
            .withDescription("output performance measures during training").create();

    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 write the model content").create();

    Option threads = builder.withLongName("threads")
            .withArgument(argumentBuilder.withName("threads").withDefault("4").create())
            .withDescription("the number of threads AdaptiveLogisticRegression uses").create();

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

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

    Option target = builder.withLongName("target").withDescription("the name of the target variable")
            .withRequired(true).withArgument(argumentBuilder.withName("target").withMaximum(1).create())
            .create();/* w  ww.ja  va  2  s  .co m*/

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

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

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

    Option interval = builder.withLongName("interval")
            .withArgument(argumentBuilder.withName("interval").withDefault("500").create())
            .withDescription("the interval property of AdaptiveLogisticRegression").create();

    Option window = builder.withLongName("window")
            .withArgument(argumentBuilder.withName("window").withDefault("800").create())
            .withDescription("the average propery of AdaptiveLogisticRegression").create();

    Option skipperfnum = builder.withLongName("skipperfnum")
            .withArgument(argumentBuilder.withName("skipperfnum").withDefault("99").create())
            .withDescription("show performance measures every (skipperfnum + 1) rows").create();

    Option prior = builder.withLongName("prior")
            .withArgument(argumentBuilder.withName("prior").withDefault("L1").create())
            .withDescription("the prior algorithm to use: L1, L2, ebp, tp, up").create();

    Option priorOption = builder.withLongName("prioroption")
            .withArgument(argumentBuilder.withName("prioroption").create())
            .withDescription("constructor parameter for ElasticBandPrior and TPrior").create();

    Option auc = builder.withLongName("auc")
            .withArgument(argumentBuilder.withName("auc").withDefault("global").create())
            .withDescription("the auc to use: global or grouped").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(inputFile)
            .withOption(outputFile).withOption(target).withOption(targetCategories).withOption(predictors)
            .withOption(types).withOption(passes).withOption(interval).withOption(window).withOption(threads)
            .withOption(prior).withOption(features).withOption(showperf).withOption(skipperfnum)
            .withOption(priorOption).withOption(auc).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;
    }

    TrainAdaptiveLogistic.inputFile = getStringArgument(cmdLine, inputFile);
    TrainAdaptiveLogistic.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 AdaptiveLogisticModelParameters();
    lmp.setTargetVariable(getStringArgument(cmdLine, target));
    lmp.setMaxTargetCategories(getIntegerArgument(cmdLine, targetCategories));
    lmp.setNumFeatures(getIntegerArgument(cmdLine, features));
    lmp.setInterval(getIntegerArgument(cmdLine, interval));
    lmp.setAverageWindow(getIntegerArgument(cmdLine, window));
    lmp.setThreads(getIntegerArgument(cmdLine, threads));
    lmp.setAuc(getStringArgument(cmdLine, auc));
    lmp.setPrior(getStringArgument(cmdLine, prior));
    if (cmdLine.getValue(priorOption) != null) {
        lmp.setPriorOption(getDoubleArgument(cmdLine, priorOption));
    }
    lmp.setTypeMap(predictorList, typeList);
    TrainAdaptiveLogistic.showperf = getBooleanArgument(cmdLine, showperf);
    TrainAdaptiveLogistic.skipperfnum = getIntegerArgument(cmdLine, skipperfnum);
    TrainAdaptiveLogistic.passes = getIntegerArgument(cmdLine, passes);

    lmp.checkParameters();

    return true;
}

From source file:org.apache.mahout.classifier.sgd.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 .  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 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) {
        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:org.apache.mahout.classifier.sgd.ValidateAdaptiveLogistic.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 validate data").create();

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

    Option defaultCagetoryOption = builder.withLongName("defaultCategory").withRequired(false)
            .withArgument(/*from  ww  w. j  a  v a 2s  . c o m*/
                    argumentBuilder.withName("defaultCategory").withMaximum(1).withDefault("unknown").create())
            .withDescription("the default category value to use").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(auc).withOption(scores)
            .withOption(confusion).withOption(inputFileOption).withOption(modelFileOption)
            .withOption(defaultCagetoryOption).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;
    }

    inputFile = getStringArgument(cmdLine, inputFileOption);
    modelFile = getStringArgument(cmdLine, modelFileOption);
    defaultCategory = getStringArgument(cmdLine, defaultCagetoryOption);
    showAuc = getBooleanArgument(cmdLine, auc);
    showScores = getBooleanArgument(cmdLine, scores);
    showConfusion = getBooleanArgument(cmdLine, confusion);

    return true;
}

From source file:org.apache.mahout.clustering.streaming.tools.ClusterQualitySummarizer.java

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

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

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFileOption = builder.withLongName("input").withShortName("i").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get seq files with the vectors (training set)").create();

    Option testInputFileOption = builder.withLongName("testInput").withShortName("itest")
            .withArgument(argumentBuilder.withName("testInput").withMaximum(1).create())
            .withDescription("where to get seq files with the vectors (test set)").create();

    Option centroidsFileOption = builder.withLongName("centroids").withShortName("c").withRequired(true)
            .withArgument(argumentBuilder.withName("centroids").withMaximum(1).create())
            .withDescription(//from  w ww .  jav a  2  s. c  o m
                    "where to get seq files with the centroids (from Mahout KMeans or StreamingKMeansDriver)")
            .create();

    Option centroidsCompareFileOption = builder.withLongName("centroidsCompare").withShortName("cc")
            .withRequired(false)
            .withArgument(argumentBuilder.withName("centroidsCompare").withMaximum(1).create())
            .withDescription("where to get seq files with the second set of centroids (from Mahout KMeans or "
                    + "StreamingKMeansDriver)")
            .create();

    Option outputFileOption = builder.withLongName("output").withShortName("o").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription("where to dump the CSV file with the results").create();

    Option mahoutKMeansFormatOption = builder.withLongName("mahoutkmeansformat").withShortName("mkm")
            .withDescription("if set, read files as (IntWritable, ClusterWritable) pairs")
            .withArgument(argumentBuilder.withName("numpoints").withMaximum(1).create()).create();

    Option mahoutKMeansCompareFormatOption = builder.withLongName("mahoutkmeansformatCompare")
            .withShortName("mkmc").withDescription("if set, read files as (IntWritable, ClusterWritable) pairs")
            .withArgument(argumentBuilder.withName("numpoints").withMaximum(1).create()).create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption)
            .withOption(testInputFileOption).withOption(outputFileOption).withOption(centroidsFileOption)
            .withOption(centroidsCompareFileOption).withOption(mahoutKMeansFormatOption)
            .withOption(mahoutKMeansCompareFormatOption).create();

    Parser parser = new Parser();
    parser.setHelpOption(help);
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 150));

    CommandLine cmdLine = parser.parseAndHelp(args);
    if (cmdLine == null) {
        return false;
    }

    trainFile = (String) cmdLine.getValue(inputFileOption);
    if (cmdLine.hasOption(testInputFileOption)) {
        testFile = (String) cmdLine.getValue(testInputFileOption);
    }
    centroidFile = (String) cmdLine.getValue(centroidsFileOption);
    if (cmdLine.hasOption(centroidsCompareFileOption)) {
        centroidCompareFile = (String) cmdLine.getValue(centroidsCompareFileOption);
    }
    outputFile = (String) cmdLine.getValue(outputFileOption);
    if (cmdLine.hasOption(mahoutKMeansFormatOption)) {
        mahoutKMeansFormat = true;
    }
    if (cmdLine.hasOption(mahoutKMeansCompareFormatOption)) {
        mahoutKMeansFormatCompare = true;
    }
    return true;
}

From source file:org.apache.mahout.clustering.streaming.tools.ResplitSequenceFiles.java

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

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

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFileOption = builder.withLongName("input").withShortName("i").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription(// ww w. j av  a2 s . c o m
                    "what the base folder for sequence files is (they all must have the same key/value type")
            .create();

    Option outputFileOption = builder.withLongName("output").withShortName("o").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription(
                    "the base name of the file split that the files will be split it; the i'th split has the "
                            + "suffix -i")
            .create();

    Option numSplitsOption = builder.withLongName("numSplits").withShortName("ns").withRequired(true)
            .withArgument(argumentBuilder.withName("numSplits").withMaximum(1).create())
            .withDescription("how many splits to use for the given files").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption)
            .withOption(outputFileOption).withOption(numSplitsOption).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;
    }

    inputFile = (String) cmdLine.getValue(inputFileOption);
    outputFileBase = (String) cmdLine.getValue(outputFileOption);
    numSplits = Integer.parseInt((String) cmdLine.getValue(numSplitsOption));
    return true;
}

From source file:org.apache.mahout.knn.tools.TestNewsGroupsKMeanLogisticRegression.java

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

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

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFileOption = builder.withLongName("input").withShortName("i").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get test data (encoded with tf-idf)").create();

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

    Option centroidsFileOption = builder.withLongName("centroids").withShortName("c").withRequired(true)
            .withArgument(argumentBuilder.withName("centroids").withMaximum(1).create())
            .withDescription("where to get the centroids seqfile").create();

    Option labelFileOption = builder.withLongName("labels").withShortName("l").withRequired(true)
            .withArgument(argumentBuilder.withName("labels").withMaximum(1).create())
            .withDescription("CSV file containing the cluster labels").create();

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

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

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

    inputFile = (String) cmdLine.getValue(inputFileOption);
    modelFile = (String) cmdLine.getValue(modelFileOption);
    centroidsFile = (String) cmdLine.getValue(centroidsFileOption);
    labelFile = (String) cmdLine.getValue(labelFileOption);
    return true;
}

From source file:org.apache.mahout.regression.penalizedlinear.Job.java

private static boolean parseJobArgs(String[] args)
        throws IOException, InterruptedException, ClassNotFoundException {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

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

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFile = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription(/*  w  ww. ja v a  2  s.c  o  m*/
                    "where to get training data (Mahout sequence file of VectorWritable or white-spaced TEXT file); in each line, the first element is response; rest are predictors.")
            .create();

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

    Option lambda = builder.withLongName("lambda")
            .withArgument(argumentBuilder.withName("lambda").withDefault("0").withMinimum(1).create())
            .withDescription("an increasing positive sequence of penalty coefficient, "
                    + "with length n >= 0; if lambda is not specified, the sequence is chosen by algorithm.")
            .create();

    Option alpha = builder.withLongName("alpha")
            .withArgument(
                    argumentBuilder.withName("alpha").withDefault("1").withMinimum(1).withMaximum(1).create())
            .withDescription("the elastic-net coefficient with default value 1 (LASSO)").create();

    Option bias = builder.withLongName("bias").withDescription("include a bias term").create();

    Option numOfCV = builder.withLongName("numOfCV")
            .withArgument(
                    argumentBuilder.withName("numOfCV").withDefault("5").withMinimum(0).withMaximum(1).create())
            .withDescription("number of cross validation, the rule of thumb is 5 or 10").create();

    Option convert = builder.withLongName("convert")
            .withDescription(
                    "pre-processing step if the input file is not Mahout sequence files of VectorWritable: "
                            + "converting space-delimited TEXT file containing floating point numbers into "
                            + "Mahout sequence files of VectorWritable suitable for input of Map-Reduce job.")
            .create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFile).withOption(outputFile)
            .withOption(lambda).withOption(alpha).withOption(bias).withOption(numOfCV).withOption(convert)
            .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;
    }

    Path input = new Path((String) cmdLine.getValue(inputFile));
    Path output = new Path((String) cmdLine.getValue(outputFile), DIRECTORY_CONTAINING_CONVERTED_INPUT);
    if (cmdLine.hasOption(convert)) {
        jobArgs = new String[args.length - 1];
        int index = 0;
        for (int i = 0; i < args.length; ++i) {
            if (args[i].equals("--convert")) {
                continue;
            }
            jobArgs[index++] = args[i];
            if (args[i].equals("--input")) {
                args[i + 1] = output.toString();
                InputDriver.runJob(input, output, "org.apache.mahout.math.RandomAccessSparseVector");
            }
            if (args[i].equals("--output")) {
                args[i + 1] = (new Path((String) cmdLine.getValue(outputFile), DIRECTORY_CONTAINING_OUTPUT))
                        .toString();
            }
        }
    } else {
        jobArgs = args;
    }
    return true;
}

From source file:org.apache.mahout.regression.penalizedlinear.LinearCrossValidation.java

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

    Option help = builder.withLongName("help").withDescription("print this list").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 (CSV or white-spaced TEXT file)").create();

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

    Option dependent = builder.withLongName("dependent").withRequired(true)
            .withArgument(argumentBuilder.withName("dependent").withMinimum(1).withMaximum(1).create())
            .withDescription("the dependent features").create();

    Option independent = builder.withLongName("independent").withRequired(true)
            .withArgument(argumentBuilder.withName("independent").create())
            .withDescription("the independent features").create();

    Option interaction = builder.withLongName("interaction").withRequired(true)
            .withArgument(argumentBuilder.withName("interaction").withMinimum(0).create())
            .withDescription(//from  w w w  .j ava 2 s  . co m
                    "the interactions of features, the format is: feature1:feature2 (identical features are OK)")
            .create();

    Option bias = builder.withLongName("bias").withDescription("include a bias term").create();

    Option lambda = builder.withLongName("lambda")
            .withArgument(argumentBuilder.withName("lambda").withDefault("0").withMinimum(1).create())
            .withDescription("an increasing positive sequence of penalty coefficient, "
                    + "with length n >= 0; if lambda is not specified, the sequence is chosen by algorithm.")
            .create();

    Option alpha = builder.withLongName("alpha")
            .withArgument(
                    argumentBuilder.withName("alpha").withDefault("1").withMinimum(1).withMaximum(1).create())
            .withDescription("the elastic-net coefficient with default value 1 (LASSO)").create();

    Option numOfCV = builder.withLongName("numOfCV")
            .withArgument(
                    argumentBuilder.withName("numOfCV").withDefault("5").withMinimum(0).withMaximum(1).create())
            .withDescription("number of cross validation, the rule of thumb is 5 or 10").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFile).withOption(outputFile)
            .withOption(dependent).withOption(independent).withOption(interaction).withOption(bias)
            .withOption(lambda).withOption(alpha).withOption(numOfCV).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;
    }

    parameter = new LinearCrossValidationParameter();
    parameter.numOfCV = Integer.parseInt((String) cmdLine.getValue(numOfCV));
    parameter.alpha = Float.parseFloat((String) cmdLine.getValue(alpha));
    parameter.intercept = cmdLine.hasOption(bias);
    parameter.dependent = (String) cmdLine.getValue(dependent);
    String independentString = "";
    for (Object x : cmdLine.getValues(independent)) {
        independentString += x.toString() + ",";
    }
    parameter.independent = independentString.substring(0, Math.max(independentString.length() - 1, 0));
    String interactionString = "";
    for (Object x : cmdLine.getValues(interaction)) {
        interactionString += x.toString() + ",";
    }
    parameter.interaction = interactionString.substring(0, Math.max(interactionString.length() - 1, 0));

    if (!processLambda(parameter, cmdLine, lambda) || parameter.alpha < 0.0 || parameter.alpha > 1.0
            || parameter.numOfCV < 1 || parameter.numOfCV > 20) {
        log.error(
                "please make sure the lambda sequence is positive and increasing, and 0.0 <= alphaValue <= 1.0 and 1 <= numofCV <= 20");
        return false;
    }

    input = (String) cmdLine.getValue(inputFile);
    output = (String) cmdLine.getValue(outputFile);
    return true;
}