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

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

Introduction

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

Prototype

Object getValue(final Option option, final Object defaultValue) throws IllegalStateException;

Source Link

Document

Retrieves the single Argument value associated with the specified Option

Usage

From source file:chapter7.src.InputDriver.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().withRequired(false).create();
    Option outputOpt = DefaultOptionCreator.outputOption().withRequired(false).create();
    Option vectorOpt = obuilder.withLongName("vector").withRequired(false)
            .withArgument(abuilder.withName("v").withMinimum(1).withMaximum(1).create())
            .withDescription("The vector implementation to use.").withShortName("v").create();

    Option helpOpt = DefaultOptionCreator.helpOption();

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

    try {//from  w w w  . ja  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;
        }

        Path input = new Path(cmdLine.getValue(inputOpt, "testdata").toString());
        Path output = new Path(cmdLine.getValue(outputOpt, "output").toString());
        String vectorClassName = cmdLine.getValue(vectorOpt, "org.apache.mahout.math.RandomAccessSparseVector")
                .toString();
        //runJob(input, output, vectorClassName);
    } catch (OptionException e) {
        InputDriver.log.error("Exception parsing command line: ", e);
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.clustering.conversion.InputDriver.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().withRequired(false).create();
    Option outputOpt = DefaultOptionCreator.outputOption().withRequired(false).create();
    Option vectorOpt = obuilder.withLongName("vector").withRequired(false)
            .withArgument(abuilder.withName("v").withMinimum(1).withMaximum(1).create())
            .withDescription("The vector implementation to use.").withShortName("v").create();

    Option helpOpt = DefaultOptionCreator.helpOption();

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

    try {/*from   www  .  jav a2s  .  co  m*/
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);
        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        Path input = new Path(cmdLine.getValue(inputOpt, "testdata").toString());
        Path output = new Path(cmdLine.getValue(outputOpt, "output").toString());
        String vectorClassName = cmdLine.getValue(vectorOpt, "org.apache.mahout.math.RandomAccessSparseVector")
                .toString();
        runJob(input, output, vectorClassName);
    } catch (OptionException e) {
        log.error("Exception parsing command line: ", e);
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.clustering.conversion.meanshift.InputDriver.java

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

    Option inputOpt = DefaultOptionCreator.inputOption().withRequired(false).create();
    Option outputOpt = DefaultOptionCreator.outputOption().withRequired(false).create();
    Option helpOpt = DefaultOptionCreator.helpOption();
    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt).withOption(helpOpt)
            .create();//  w  ww .j av a2  s  .  c o  m

    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);
        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        Path input = new Path(cmdLine.getValue(inputOpt, "testdata").toString());
        Path output = new Path(cmdLine.getValue(outputOpt, "output").toString());
        runJob(input, output);
    } catch (OptionException e) {
        log.error("Exception parsing command line: ", e);
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.clustering.syntheticcontrol.canopy.InputDriver.java

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

    Option inputOpt = DefaultOptionCreator.inputOption().withRequired(false).create();
    Option outputOpt = DefaultOptionCreator.outputOption().withRequired(false).create();
    Option vectorOpt = obuilder.withLongName("vector").withRequired(false)
            .withArgument(abuilder.withName("v").withMinimum(1).withMaximum(1).create())
            .withDescription("The vector implementation to use.").withShortName("v").create();

    Option helpOpt = DefaultOptionCreator.helpOption();

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

    try {/*from ww  w  .ja 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;
        }

        Path input = new Path(cmdLine.getValue(inputOpt, "testdata").toString());
        Path output = new Path(cmdLine.getValue(outputOpt, "output").toString());
        String vectorClassName = cmdLine.getValue(vectorOpt, "org.apache.mahout.math.RandomAccessSparseVector")
                .toString();
        runJob(input, output, vectorClassName);
    } catch (OptionException e) {
        InputDriver.LOG.error("Exception parsing command line: ", e);
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.clustering.syntheticcontrol.canopy.Job.java

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

    Option inputOpt = obuilder.withLongName("input").withRequired(false)
            .withArgument(abuilder.withName("input").withMinimum(1).withMaximum(1).create())
            .withDescription("The Path for input Vectors. Must be a SequenceFile of Writable, Vector")
            .withShortName("i").create();
    Option outputOpt = obuilder.withLongName("output").withRequired(false)
            .withArgument(abuilder.withName("output").withMinimum(1).withMaximum(1).create())
            .withDescription("The Path to put the output in").withShortName("o").create();

    Option measureClassOpt = obuilder.withLongName("distance").withRequired(false)
            .withArgument(abuilder.withName("distance").withMinimum(1).withMaximum(1).create())
            .withDescription("The Distance Measure to use.  Default is SquaredEuclidean").withShortName("m")
            .create();//from   www .  ja v  a2  s.c o  m
    // Option vectorClassOpt = obuilder.withLongName("vectorClass").withRequired(false).withArgument(
    // abuilder.withName("vectorClass").withMinimum(1).withMaximum(1).create()).
    // withDescription("The Vector implementation class name.  Default is RandomAccessSparseVector.class")
    // .withShortName("v").create();

    Option t1Opt = obuilder.withLongName("t1").withRequired(false)
            .withArgument(abuilder.withName("t1").withMinimum(1).withMaximum(1).create()).withDescription("t1")
            .withShortName("t1").create();
    Option t2Opt = obuilder.withLongName("t2").withRequired(false)
            .withArgument(abuilder.withName("t2").withMinimum(1).withMaximum(1).create()).withDescription("t2")
            .withShortName("t2").create();

    Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h")
            .create();

    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt)
            .withOption(measureClassOpt)// .withOption(vectorClassOpt)
            .withOption(t1Opt).withOption(t2Opt).withOption(helpOpt).create();

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

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

        Path input = new Path(cmdLine.getValue(inputOpt, "testdata").toString());
        Path output = new Path(cmdLine.getValue(outputOpt, "output").toString());
        String measureClass = cmdLine
                .getValue(measureClassOpt, "org.apache.mahout.common.distance.EuclideanDistanceMeasure")
                .toString();

        // String className = cmdLine.getValue(vectorClassOpt,
        // "org.apache.mahout.math.RandomAccessSparseVector").toString();
        // Class<? extends Vector> vectorClass = Class.forName(className).asSubclass(Vector.class);
        double t1 = Double.parseDouble(cmdLine.getValue(t1Opt, "80").toString());
        double t2 = Double.parseDouble(cmdLine.getValue(t2Opt, "55").toString());

        runJob(input, output, measureClass, t1, t2);
    } catch (OptionException e) {
        Job.log.error("Exception", e);
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.clustering.syntheticcontrol.kmeans.Job.java

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

    Option inputOpt = DefaultOptionCreator.inputOption().withRequired(false).create();
    Option outputOpt = DefaultOptionCreator.outputOption().withRequired(false).create();
    Option convergenceDeltaOpt = DefaultOptionCreator.convergenceOption().withRequired(false).create();
    Option maxIterationsOpt = DefaultOptionCreator.maxIterationsOption().withRequired(false).create();

    Option measureClassOpt = obuilder.withLongName("distance").withRequired(false)
            .withArgument(abuilder.withName("distance").withMinimum(1).withMaximum(1).create())
            .withDescription("The Distance Measure to use.  Default is SquaredEuclidean").withShortName("m")
            .create();/*from w w w. ja v  a 2 s .  c  o m*/

    Option t1Opt = obuilder.withLongName("t1").withRequired(false)
            .withArgument(abuilder.withName("t1").withMinimum(1).withMaximum(1).create())
            .withDescription("The t1 value to use.").withShortName("m").create();
    Option t2Opt = obuilder.withLongName("t2").withRequired(false)
            .withArgument(abuilder.withName("t2").withMinimum(1).withMaximum(1).create())
            .withDescription("The t2 value to use.").withShortName("m").create();
    Option vectorClassOpt = obuilder.withLongName("vectorClass").withRequired(false)
            .withArgument(abuilder.withName("vectorClass").withMinimum(1).withMaximum(1).create())
            .withDescription("The Vector implementation class name.  Default is RandomAccessSparseVector.class")
            .withShortName("v").create();

    Option helpOpt = DefaultOptionCreator.helpOption();

    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt)
            .withOption(measureClassOpt).withOption(convergenceDeltaOpt).withOption(maxIterationsOpt)
            .withOption(vectorClassOpt).withOption(t1Opt).withOption(t2Opt).withOption(helpOpt).create();
    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }
        Path input = new Path(cmdLine.getValue(inputOpt, "testdata").toString());
        Path output = new Path(cmdLine.getValue(outputOpt, "output").toString());
        String measureClass = cmdLine
                .getValue(measureClassOpt, "org.apache.mahout.common.distance.EuclideanDistanceMeasure")
                .toString();
        double t1 = Double.parseDouble(cmdLine.getValue(t1Opt, "80").toString());
        double t2 = Double.parseDouble(cmdLine.getValue(t2Opt, "55").toString());
        double convergenceDelta = Double.parseDouble(cmdLine.getValue(convergenceDeltaOpt, "0.5").toString());
        int maxIterations = Integer.parseInt(cmdLine.getValue(maxIterationsOpt, 10).toString());

        runJob(input, output, measureClass, t1, t2, convergenceDelta, maxIterations);
    } catch (OptionException e) {
        log.error("Exception", e);
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.clustering.syntheticcontrol.meanshift.InputDriver.java

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

    Option inputOpt = DefaultOptionCreator.inputOption().withRequired(false).create();
    Option outputOpt = DefaultOptionCreator.outputOption().withRequired(false).create();
    Option helpOpt = DefaultOptionCreator.helpOption();
    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt).withOption(helpOpt)
            .create();//from  w  w w .j a v a2 s . c  om

    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);
        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        Path input = new Path(cmdLine.getValue(inputOpt, "testdata").toString());
        Path output = new Path(cmdLine.getValue(outputOpt, "output").toString());
        runJob(input, output);
    } catch (OptionException e) {
        InputDriver.LOG.error("Exception parsing command line: ", e);
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.clustering.syntheticcontrol.meanshift.Job.java

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

    Option inputOpt = DefaultOptionCreator.inputOption().withRequired(false).create();
    Option outputOpt = DefaultOptionCreator.outputOption().withRequired(false).create();
    Option convergenceDeltaOpt = DefaultOptionCreator.convergenceOption().withRequired(false).create();
    Option maxIterOpt = DefaultOptionCreator.maxIterationsOption().withRequired(false).create();
    Option helpOpt = DefaultOptionCreator.helpOption();

    Option modelOpt = obuilder.withLongName("distanceClass").withRequired(false).withShortName("d")
            .withArgument(abuilder.withName("distanceClass").withMinimum(1).withMaximum(1).create())
            .withDescription("The distance measure class name.").create();

    Option threshold1Opt = obuilder.withLongName("threshold_1").withRequired(false).withShortName("t1")
            .withArgument(abuilder.withName("threshold_1").withMinimum(1).withMaximum(1).create())
            .withDescription("The T1 distance threshold.").create();

    Option threshold2Opt = obuilder.withLongName("threshold_2").withRequired(false).withShortName("t2")
            .withArgument(abuilder.withName("threshold_2").withMinimum(1).withMaximum(1).create())
            .withDescription("The T1 distance threshold.").create();

    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt).withOption(modelOpt)
            .withOption(helpOpt).withOption(convergenceDeltaOpt).withOption(threshold1Opt)
            .withOption(maxIterOpt).withOption(threshold2Opt).create();

    try {//ww  w.  j a  v a 2 s.  co m
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);
        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        Path input = new Path(cmdLine.getValue(inputOpt, "testdata").toString());
        Path output = new Path(cmdLine.getValue(outputOpt, "output").toString());
        String measureClassName = cmdLine
                .getValue(modelOpt, "org.apache.mahout.common.distance.EuclideanDistanceMeasure").toString();
        double t1 = Double.parseDouble(cmdLine.getValue(threshold1Opt, "47.6").toString());
        double t2 = Double.parseDouble(cmdLine.getValue(threshold2Opt, "1").toString());
        double convergenceDelta = Double.parseDouble(cmdLine.getValue(convergenceDeltaOpt, "0.5").toString());
        int maxIterations = Integer.parseInt(cmdLine.getValue(maxIterOpt, "10").toString());
        runJob(input, output, measureClassName, t1, t2, convergenceDelta, maxIterations);
    } catch (OptionException e) {
        log.error("Exception parsing command line: ", e);
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.apache.mahout.clustering.syntheticcontrol.meanshift.OutputDriver.java

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

    Option inputOpt = DefaultOptionCreator.inputOption().withRequired(false).create();
    Option outputOpt = DefaultOptionCreator.outputOption().withRequired(false).create();
    Option helpOpt = DefaultOptionCreator.helpOption();
    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt).withOption(helpOpt)
            .create();/*  w w  w . j  av a 2 s  .  c  o  m*/

    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);
        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        String input = cmdLine.getValue(inputOpt, "testdata").toString();
        String output = cmdLine.getValue(outputOpt, "output").toString();
        runJob(input, output);
    } catch (OptionException e) {
        OutputDriver.LOG.error("Exception parsing command line: ", e);
        CommandLineUtil.printHelp(group);
    }
}