Example usage for org.apache.commons.cli2.builder DefaultOptionBuilder DefaultOptionBuilder

List of usage examples for org.apache.commons.cli2.builder DefaultOptionBuilder DefaultOptionBuilder

Introduction

In this page you can find the example usage for org.apache.commons.cli2.builder DefaultOptionBuilder DefaultOptionBuilder.

Prototype

public DefaultOptionBuilder() 

Source Link

Document

Creates a new DefaultOptionBuilder using defaults

Usage

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   w w w.ja va 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  .j  a  va 2 s.  co 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.dirichlet.Job.java

@Override
public int run(String[] args) throws Exception {
    addInputOption();//  w ww  .  j  a v  a 2  s  .  c  o m
    addOutputOption();
    addOption(DefaultOptionCreator.maxIterationsOption().create());
    addOption(DefaultOptionCreator.numClustersOption().withRequired(true).create());
    addOption(DefaultOptionCreator.overwriteOption().create());
    addOption(new DefaultOptionBuilder().withLongName(DirichletDriver.ALPHA_OPTION).withRequired(false)
            .withShortName("m")
            .withArgument(new ArgumentBuilder().withName(DirichletDriver.ALPHA_OPTION).withDefault("1.0")
                    .withMinimum(1).withMaximum(1).create())
            .withDescription("The alpha0 value for the DirichletDistribution. Defaults to 1.0").create());
    addOption(new DefaultOptionBuilder().withLongName(DirichletDriver.MODEL_DISTRIBUTION_CLASS_OPTION)
            .withRequired(false).withShortName("md")
            .withArgument(new ArgumentBuilder().withName(DirichletDriver.MODEL_DISTRIBUTION_CLASS_OPTION)
                    .withDefault(GaussianClusterDistribution.class.getName()).withMinimum(1).withMaximum(1)
                    .create())
            .withDescription("The ModelDistribution class name. Defaults to GaussianClusterDistribution")
            .create());
    addOption(new DefaultOptionBuilder().withLongName(DirichletDriver.MODEL_PROTOTYPE_CLASS_OPTION)
            .withRequired(false).withShortName("mp")
            .withArgument(new ArgumentBuilder().withName("prototypeClass")
                    .withDefault(RandomAccessSparseVector.class.getName()).withMinimum(1).withMaximum(1)
                    .create())
            .withDescription(
                    "The ModelDistribution prototype Vector class name. Defaults to RandomAccessSparseVector")
            .create());
    addOption(DefaultOptionCreator.distanceMeasureOption().withRequired(false).create());
    addOption(DefaultOptionCreator.emitMostLikelyOption().create());
    addOption(DefaultOptionCreator.thresholdOption().create());

    Map<String, List<String>> argMap = parseArguments(args);
    if (argMap == null) {
        return -1;
    }

    Path input = getInputPath();
    Path output = getOutputPath();
    if (hasOption(DefaultOptionCreator.OVERWRITE_OPTION)) {
        HadoopUtil.delete(getConf(), output);
    }
    String modelFactory = getOption(DirichletDriver.MODEL_DISTRIBUTION_CLASS_OPTION);
    String modelPrototype = getOption(DirichletDriver.MODEL_PROTOTYPE_CLASS_OPTION);
    String distanceMeasure = getOption(DefaultOptionCreator.DISTANCE_MEASURE_OPTION);
    int numModels = Integer.parseInt(getOption(DefaultOptionCreator.NUM_CLUSTERS_OPTION));
    int maxIterations = Integer.parseInt(getOption(DefaultOptionCreator.MAX_ITERATIONS_OPTION));
    boolean emitMostLikely = Boolean.parseBoolean(getOption(DefaultOptionCreator.EMIT_MOST_LIKELY_OPTION));
    double threshold = Double.parseDouble(getOption(DefaultOptionCreator.THRESHOLD_OPTION));
    double alpha0 = Double.parseDouble(getOption(DirichletDriver.ALPHA_OPTION));
    DistributionDescription description = new DistributionDescription(modelFactory, modelPrototype,
            distanceMeasure, 60);

    run(input, output, description, numModels, maxIterations, alpha0, emitMostLikely, threshold);
    return 0;
}

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

@Override
public int run(String[] args) throws Exception {
    addInputOption();//from  w  w w.  j a va2  s.  c  o m
    addOutputOption();
    addOption(DefaultOptionCreator.distanceMeasureOption().create());
    addOption(DefaultOptionCreator.convergenceOption().create());
    addOption(DefaultOptionCreator.maxIterationsOption().create());
    addOption(DefaultOptionCreator.overwriteOption().create());
    addOption(DefaultOptionCreator.t1Option().create());
    addOption(DefaultOptionCreator.t2Option().create());
    addOption(M_OPTION, M_OPTION, "coefficient normalization factor, must be greater than 1", true);

    Map<String, List<String>> argMap = parseArguments(args);
    if (argMap == null) {
        return -1;
    }

    Path input = getInputPath();
    Path output = getOutputPath();
    String measureClass = getOption(DefaultOptionCreator.DISTANCE_MEASURE_OPTION);
    if (measureClass == null) {
        measureClass = SquaredEuclideanDistanceMeasure.class.getName();
    }
    double convergenceDelta = Double.parseDouble(getOption(DefaultOptionCreator.CONVERGENCE_DELTA_OPTION));
    int maxIterations = Integer.parseInt(getOption(DefaultOptionCreator.MAX_ITERATIONS_OPTION));
    float fuzziness = Float.parseFloat(getOption(M_OPTION));

    addOption(new DefaultOptionBuilder().withLongName(M_OPTION).withRequired(true)
            .withArgument(new ArgumentBuilder().withName(M_OPTION).withMinimum(1).withMaximum(1).create())
            .withDescription("coefficient normalization factor, must be greater than 1").withShortName(M_OPTION)
            .create());
    if (hasOption(DefaultOptionCreator.OVERWRITE_OPTION)) {
        HadoopUtil.delete(getConf(), output);
    }
    DistanceMeasure measure = ClassUtils.instantiateAs(measureClass, DistanceMeasure.class);
    double t1 = Double.parseDouble(getOption(DefaultOptionCreator.T1_OPTION));
    double t2 = Double.parseDouble(getOption(DefaultOptionCreator.T2_OPTION));
    run(getConf(), input, output, measure, t1, t2, maxIterations, fuzziness, convergenceDelta);
    return 0;
}

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

        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.common.commandline.DefaultOptionCreator.java

/**
 * Returns a default command line option for clusters input directory
 * specification. Used by FuzzyKmeans, Kmeans
 *//*from  w  w  w . j  a  v a  2 s  . c  o m*/
public static DefaultOptionBuilder clustersInOption() {
    return new DefaultOptionBuilder().withLongName(CLUSTERS_IN_OPTION).withRequired(true)
            .withArgument(
                    new ArgumentBuilder().withName(CLUSTERS_IN_OPTION).withMinimum(1).withMaximum(1).create())
            .withDescription(
                    "The path to the initial clusters directory. Must be a SequenceFile of some type of Cluster")
            .withShortName("c");
}

From source file:org.apache.mahout.common.commandline.DefaultOptionCreator.java

/**
 * Returns a default command line option for specification of distance measure
 * class to use. Used by Canopy, FuzzyKmeans, Kmeans, MeanShift
 */// w ww  .  j  a va2  s  . com
public static DefaultOptionBuilder distanceMeasureOption() {
    return new DefaultOptionBuilder().withLongName(DISTANCE_MEASURE_OPTION).withRequired(false)
            .withShortName("dm")
            .withArgument(new ArgumentBuilder().withName(DISTANCE_MEASURE_OPTION)
                    .withDefault(SquaredEuclideanDistanceMeasure.class.getName()).withMinimum(1).withMaximum(1)
                    .create())
            .withDescription("The classname of the DistanceMeasure. Default is SquaredEuclidean");
}

From source file:org.apache.mahout.common.commandline.DefaultOptionCreator.java

/**
 * Returns a default command line option for specification of sequential or
 * parallel operation. Used by Canopy, FuzzyKmeans, Kmeans, MeanShift,
 * Dirichlet/* w w  w. j  a v a 2 s. c  o m*/
 */
public static DefaultOptionBuilder methodOption() {
    return new DefaultOptionBuilder().withLongName(METHOD_OPTION).withRequired(false).withShortName("xm")
            .withArgument(new ArgumentBuilder().withName(METHOD_OPTION).withDefault(MAPREDUCE_METHOD)
                    .withMinimum(1).withMaximum(1).create())
            .withDescription("The execution method to use: sequential or mapreduce. Default is mapreduce");
}

From source file:org.apache.mahout.common.commandline.DefaultOptionCreator.java

/**
 * Returns a default command line option for specification of T1. Used by
 * Canopy, MeanShift//from w  w  w .j  av a 2s  .  co  m
 */
public static DefaultOptionBuilder t1Option() {
    return new DefaultOptionBuilder().withLongName(T1_OPTION).withRequired(true)
            .withArgument(new ArgumentBuilder().withName(T1_OPTION).withMinimum(1).withMaximum(1).create())
            .withDescription("T1 threshold value").withShortName(T1_OPTION);
}