Example usage for org.apache.commons.cli2 CommandLine hasOption

List of usage examples for org.apache.commons.cli2 CommandLine hasOption

Introduction

In this page you can find the example usage for org.apache.commons.cli2 CommandLine hasOption.

Prototype

boolean hasOption(final Option option);

Source Link

Document

Detects the presence of an option in this CommandLine.

Usage

From source file:org.apache.mahout.df.tools.Describe.java

public static void main(String[] args) throws IOException, DescriptorException {

    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option pathOpt = obuilder.withLongName("path").withShortName("p").withRequired(true)
            .withArgument(abuilder.withName("path").withMinimum(1).withMaximum(1).create())
            .withDescription("Data path").create();

    Option descriptorOpt = obuilder.withLongName("descriptor").withShortName("d").withRequired(true)
            .withArgument(abuilder.withName("descriptor").withMinimum(1).create())
            .withDescription("data descriptor").create();

    Option descPathOpt = obuilder.withLongName("file").withShortName("f").withRequired(true)
            .withArgument(abuilder.withName("file").withMinimum(1).withMaximum(1).create())
            .withDescription("Path to generated descriptor file").create();

    Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h")
            .create();//from   w ww .ja  va  2  s .  c om

    Group group = gbuilder.withName("Options").withOption(pathOpt).withOption(descPathOpt)
            .withOption(descriptorOpt).withOption(helpOpt).create();

    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        String dataPath = cmdLine.getValue(pathOpt).toString();
        String descPath = cmdLine.getValue(descPathOpt).toString();
        List<String> descriptor = convert(cmdLine.getValues(descriptorOpt));

        log.debug("Data path : {}", dataPath);
        log.debug("Descriptor path : {}", descPath);
        log.debug("Descriptor : {}", descriptor);

        runTool(dataPath, descriptor, descPath);
    } catch (OptionException e) {
        log.warn(e.toString());
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.fpm.pfpgrowth.DeliciousTagsExample.java

public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();
    Option inputDirOpt = DefaultOptionCreator.inputOption().create();

    Option outputOpt = DefaultOptionCreator.outputOption().create();

    Option helpOpt = DefaultOptionCreator.helpOption();
    Option recordSplitterOpt = obuilder.withLongName("splitterPattern")
            .withArgument(abuilder.withName("splitterPattern").withMinimum(1).withMaximum(1).create())
            .withDescription("Regular Expression pattern used to split given line into fields."
                    + " Default value splits comma or tab separated fields."
                    + " Default Value: \"[ ,\\t]*\\t[ ,\\t]*\" ")
            .withShortName("regex").create();
    Option encodingOpt = obuilder.withLongName("encoding")
            .withArgument(abuilder.withName("encoding").withMinimum(1).withMaximum(1).create())
            .withDescription("(Optional) The file encoding.  Default value: UTF-8").withShortName("e").create();
    Group group = gbuilder.withName("Options").withOption(inputDirOpt).withOption(outputOpt).withOption(helpOpt)
            .withOption(recordSplitterOpt).withOption(encodingOpt).create();

    try {//from  w  w w . j  a  v a  2  s  .c o  m
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }
        Parameters params = new Parameters();
        if (cmdLine.hasOption(recordSplitterOpt)) {
            params.set("splitPattern", (String) cmdLine.getValue(recordSplitterOpt));
        }

        String encoding = "UTF-8";
        if (cmdLine.hasOption(encodingOpt)) {
            encoding = (String) cmdLine.getValue(encodingOpt);
        }
        params.set("encoding", encoding);
        String inputDir = (String) cmdLine.getValue(inputDirOpt);
        String outputDir = (String) cmdLine.getValue(outputOpt);
        params.set("input", inputDir);
        params.set("output", outputDir);
        params.set("groupingFieldCount", "2");
        params.set("gfield0", "1");
        params.set("gfield1", "2");
        params.set("selectedFieldCount", "1");
        params.set("field0", "3");
        params.set("maxTransactionLength", "100");
        KeyBasedStringTupleGrouper.startJob(params);

    } catch (OptionException ex) {
        CommandLineUtil.printHelp(group);
    }

}

From source file:org.apache.mahout.fpm.pfpgrowth.FPGrowthDriver.java

/**
 * Run TopK FPGrowth given the input file,
 *//*from www . j  a  va2  s  . c  om*/
public static void main(String[] args) throws Exception {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option inputDirOpt = obuilder.withLongName("input").withRequired(true)
            .withArgument(abuilder.withName("input").withMinimum(1).withMaximum(1).create())
            .withDescription("The Directory on HDFS containing the transaction files").withShortName("i")
            .create();

    Option outputOpt = DefaultOptionCreator.outputOption().create();

    Option helpOpt = DefaultOptionCreator.helpOption();

    // minSupport(3), maxHeapSize(50), numGroups(1000)
    Option minSupportOpt = obuilder.withLongName("minSupport")
            .withArgument(abuilder.withName("minSupport").withMinimum(1).withMaximum(1).create())
            .withDescription("(Optional) Minimum Support. Default Value: 3").withShortName("s").create();

    Option maxHeapSizeOpt = obuilder.withLongName("maxHeapSize")
            .withArgument(abuilder.withName("maxHeapSize").withMinimum(1).withMaximum(1).create())
            .withDescription(
                    "(Optional) Maximum Heap Size k, to denote the requirement to mine top K items. Default value: 50")
            .withShortName("k").create();

    Option numGroupsOpt = obuilder.withLongName("numGroups")
            .withArgument(abuilder.withName("numGroups").withMinimum(1).withMaximum(1).create())
            .withDescription(
                    "(Optional) Number of groups the features should be divided in the map-reduce version."
                            + " Doesn't work in sequential version Default Value:1000")
            .withShortName("g").create();

    Option recordSplitterOpt = obuilder.withLongName("splitterPattern")
            .withArgument(abuilder.withName("splitterPattern").withMinimum(1).withMaximum(1).create())
            .withDescription("Regular Expression pattern used to split given string transaction into itemsets."
                    + " Default value splits comma separated itemsets.  Default Value:"
                    + " \"[ ,\\t]*[,|\\t][ ,\\t]*\" ")
            .withShortName("regex").create();

    Option treeCacheOpt = obuilder.withLongName("numTreeCacheEntries")
            .withArgument(abuilder.withName("numTreeCacheEntries").withMinimum(1).withMaximum(1).create())
            .withDescription(
                    "(Optional) Number of entries in the tree cache to prevent duplicate tree building. "
                            + "(Warning) a first level conditional FP-Tree might consume a lot of memory, "
                            + "so keep this value small, but big enough to prevent duplicate tree building. "
                            + "Default Value:5 Recommended Values: [5-10]")
            .withShortName("tc").create();

    Option methodOpt = obuilder.withLongName("method").withRequired(true)
            .withArgument(abuilder.withName("method").withMinimum(1).withMaximum(1).create())
            .withDescription("Method of processing: sequential|mapreduce").withShortName("method").create();
    Option encodingOpt = obuilder.withLongName("encoding")
            .withArgument(abuilder.withName("encoding").withMinimum(1).withMaximum(1).create())
            .withDescription("(Optional) The file encoding.  Default value: UTF-8").withShortName("e").create();

    Group group = gbuilder.withName("Options").withOption(minSupportOpt).withOption(inputDirOpt)
            .withOption(outputOpt).withOption(maxHeapSizeOpt).withOption(numGroupsOpt).withOption(methodOpt)
            .withOption(encodingOpt).withOption(helpOpt).withOption(treeCacheOpt).withOption(recordSplitterOpt)
            .create();
    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        Parameters params = new Parameters();

        if (cmdLine.hasOption(minSupportOpt)) {
            String minSupportString = (String) cmdLine.getValue(minSupportOpt);
            params.set("minSupport", minSupportString);
        }
        if (cmdLine.hasOption(maxHeapSizeOpt)) {
            String maxHeapSizeString = (String) cmdLine.getValue(maxHeapSizeOpt);
            params.set("maxHeapSize", maxHeapSizeString);
        }
        if (cmdLine.hasOption(numGroupsOpt)) {
            String numGroupsString = (String) cmdLine.getValue(numGroupsOpt);
            params.set("numGroups", numGroupsString);
        }

        if (cmdLine.hasOption(treeCacheOpt)) {
            String numTreeCacheString = (String) cmdLine.getValue(treeCacheOpt);
            params.set("treeCacheSize", numTreeCacheString);
        }

        if (cmdLine.hasOption(recordSplitterOpt)) {
            String patternString = (String) cmdLine.getValue(recordSplitterOpt);
            params.set("splitPattern", patternString);
        }

        String encoding = "UTF-8";
        if (cmdLine.hasOption(encodingOpt)) {
            encoding = (String) cmdLine.getValue(encodingOpt);
        }
        params.set("encoding", encoding);
        Path inputDir = new Path(cmdLine.getValue(inputDirOpt).toString());
        Path outputDir = new Path(cmdLine.getValue(outputOpt).toString());

        params.set("input", inputDir.toString());
        params.set("output", outputDir.toString());

        String classificationMethod = (String) cmdLine.getValue(methodOpt);
        if (classificationMethod.equalsIgnoreCase("sequential")) {
            runFPGrowth(params);
        } else if (classificationMethod.equalsIgnoreCase("mapreduce")) {
            HadoopUtil.overwriteOutput(outputDir);
            PFPGrowth.runPFPGrowth(params);
        }
    } catch (OptionException e) {
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.ga.watchmaker.cd.CDGA.java

public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option inputOpt = DefaultOptionCreator.inputOption().create();

    Option labelOpt = obuilder.withLongName("label").withRequired(true).withShortName("l")
            .withArgument(abuilder.withName("index").withMinimum(1).withMaximum(1).create())
            .withDescription("label's index.").create();

    Option thresholdOpt = obuilder.withLongName("threshold").withRequired(false).withShortName("t")
            .withArgument(abuilder.withName("threshold").withMinimum(1).withMaximum(1).create())
            .withDescription("Condition activation threshold, default = 0.5.").create();

    Option crosspntsOpt = obuilder.withLongName("crosspnts").withRequired(false).withShortName("cp")
            .withArgument(abuilder.withName("points").withMinimum(1).withMaximum(1).create())
            .withDescription("Number of crossover points to use, default = 1.").create();

    Option mutrateOpt = obuilder.withLongName("mutrate").withRequired(true).withShortName("m")
            .withArgument(abuilder.withName("true").withMinimum(1).withMaximum(1).create())
            .withDescription("Mutation rate (float).").create();

    Option mutrangeOpt = obuilder.withLongName("mutrange").withRequired(false).withShortName("mr")
            .withArgument(abuilder.withName("range").withMinimum(1).withMaximum(1).create())
            .withDescription("Mutation range, default = 0.1 (10%).").create();

    Option mutprecOpt = obuilder.withLongName("mutprec").withRequired(false).withShortName("mp")
            .withArgument(abuilder.withName("precision").withMinimum(1).withMaximum(1).create())
            .withDescription("Mutation precision, default = 2.").create();

    Option popsizeOpt = obuilder.withLongName("popsize").withRequired(true).withShortName("p")
            .withArgument(abuilder.withName("size").withMinimum(1).withMaximum(1).create())
            .withDescription("Population size.").create();

    Option gencntOpt = obuilder.withLongName("gencnt").withRequired(true).withShortName("g")
            .withArgument(abuilder.withName("count").withMinimum(1).withMaximum(1).create())
            .withDescription("Generations count.").create();

    Option helpOpt = DefaultOptionCreator.helpOption();

    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(helpOpt).withOption(labelOpt)
            .withOption(thresholdOpt).withOption(crosspntsOpt).withOption(mutrateOpt).withOption(mutrangeOpt)
            .withOption(mutprecOpt).withOption(popsizeOpt).withOption(gencntOpt).create();

    Parser parser = new Parser();
    parser.setGroup(group);//from   www . j a va 2  s .  c om

    try {
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        String dataset = cmdLine.getValue(inputOpt).toString();
        int target = Integer.parseInt(cmdLine.getValue(labelOpt).toString());
        double threshold = cmdLine.hasOption(thresholdOpt)
                ? Double.parseDouble(cmdLine.getValue(thresholdOpt).toString())
                : 0.5;
        int crosspnts = cmdLine.hasOption(crosspntsOpt)
                ? Integer.parseInt(cmdLine.getValue(crosspntsOpt).toString())
                : 1;
        double mutrate = Double.parseDouble(cmdLine.getValue(mutrateOpt).toString());
        double mutrange = cmdLine.hasOption(mutrangeOpt)
                ? Double.parseDouble(cmdLine.getValue(mutrangeOpt).toString())
                : 0.1;
        int mutprec = cmdLine.hasOption(mutprecOpt) ? Integer.parseInt(cmdLine.getValue(mutprecOpt).toString())
                : 2;
        int popSize = Integer.parseInt(cmdLine.getValue(popsizeOpt).toString());
        int genCount = Integer.parseInt(cmdLine.getValue(gencntOpt).toString());

        long start = System.currentTimeMillis();

        runJob(dataset, target, threshold, crosspnts, mutrate, mutrange, mutprec, popSize, genCount);

        long end = System.currentTimeMillis();

        printElapsedTime(end - start);
    } catch (OptionException e) {
        log.error("Error while parsing options", e);
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.ga.watchmaker.cd.tool.CDInfosTool.java

public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
    GroupBuilder gbuilder = new GroupBuilder();

    Option inputOpt = DefaultOptionCreator.inputOption().create();

    Option helpOpt = DefaultOptionCreator.helpOption();

    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(helpOpt).create();

    Parser parser = new Parser();
    parser.setGroup(group);//from w w w  .  j  a  v  a  2  s .  c  o  m
    try {
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        Path input = new Path(cmdLine.getValue(inputOpt).toString());
        Path output = new Path("output"); // TODO surely this should be configurable?

        FileSystem fs = FileSystem.get(input.toUri(), new Configuration());

        log.info("Loading Descriptors...");
        Descriptors descriptors = loadDescriptors(fs, input);

        log.info("Gathering informations...");
        List<String> descriptions = Lists.newArrayList();
        gatherInfos(descriptors, input, output, descriptions);

        log.info("Storing Descriptions...");
        storeDescriptions(fs, input, descriptors, descriptions);
    } catch (OptionException e) {
        log.error("Error while parsing options", e);
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.math.hadoop.decomposer.EigenVerificationJob.java

public static Map<String, String> handleArgs(String[] args) {
    Option eigenInputOpt = buildOption("eigenInput", "ei",
            "The Path for purported eigenVector input files (SequenceFile<WritableComparable,VectorWritable>.",
            null);/*from  w ww.j  a  v  a 2  s .c o  m*/
    Option corpusInputOpt = buildOption("corpusInput", "ci",
            "The Path for corpus input files (SequenceFile<WritableComparable,VectorWritable>.");
    Option outOpt = DefaultOptionCreator.outputOption().create();
    Option helpOpt = DefaultOptionCreator.helpOption();
    Option inMemOpt = buildOption("inMemory", "mem", "Buffer eigen matrix into memory (if you have enough!)",
            "false");
    Option errorOpt = buildOption("maxError", "err", "Maximum acceptable error", "0.05");
    Option minEigenValOpt = buildOption("minEigenvalue", "mev", "Minimum eigenvalue to keep the vector for",
            "0.0");

    GroupBuilder gBuilder = new GroupBuilder().withName("Options").withOption(eigenInputOpt)
            .withOption(corpusInputOpt).withOption(helpOpt).withOption(outOpt).withOption(inMemOpt)
            .withOption(errorOpt).withOption(minEigenValOpt);
    Group group = gBuilder.create();

    Map<String, String> argMap = new HashMap<String, String>();

    CommandLine cmdLine;
    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        cmdLine = parser.parse(args);
    } catch (OptionException e) {
        log.error(e.getMessage());
        CommandLineUtil.printHelp(group);
        return null;
    }
    if (cmdLine.hasOption(helpOpt)) {
        CommandLineUtil.printHelp(group);
        return argMap;
    }
    maybePut(argMap, cmdLine, eigenInputOpt, corpusInputOpt, helpOpt, outOpt, inMemOpt, errorOpt,
            minEigenValOpt);
    return argMap;
}

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(//from   www .j ava  2s. c om
                    "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 .ja  v  a  2s .  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;
}

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

private boolean processLambda(LinearCrossValidationParameter parameter, CommandLine cmdLine, Option lambda) {
    String lambdaSeq = "";
    double previous = Double.NEGATIVE_INFINITY;
    if (cmdLine.hasOption(lambda)) {
        for (Object x : cmdLine.getValues(lambda)) {
            double number = Double.parseDouble(x.toString());
            if (previous >= number || number < 0) {
                return false;
            }/*from  ww w .  j  a va 2  s .  co  m*/
            lambdaSeq += x.toString() + ",";
            previous = number;
        }
        parameter.lambda = lambdaSeq.substring(0, lambdaSeq.length() - 1);
        return true;
    } else {
        parameter.lambda = "";
        return true;
    }
}

From source file:org.apache.mahout.regression.penalizedlinear.LinearRegularizePath.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  a  v  a 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();

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