List of usage examples for org.apache.commons.cli2.builder DefaultOptionBuilder DefaultOptionBuilder
public DefaultOptionBuilder()
From source file:org.apache.mahout.feature.mrmr.common.commandline.DefaultOptionCreator.java
public static DefaultOptionBuilder targetColumnOption() { return new DefaultOptionBuilder().withLongName(TARGET_COLUMN).withRequired(true).withShortName("t") .withArgument(new ArgumentBuilder().withName(TARGET_COLUMN).withDefault("1").withMinimum(1) .withMaximum(1).create()) .withDescription("The column number of the target class"); }
From source file:org.apache.mahout.feature.mrmr.common.commandline.DefaultOptionCreator.java
public static DefaultOptionBuilder rowNumberOption() { return new DefaultOptionBuilder().withLongName(ROW_NUMBER).withRequired(true).withShortName("nr") .withArgument(new ArgumentBuilder().withName(ROW_NUMBER).withMinimum(1).withMaximum(1).create()) .withDescription("Number of rows in the dataset"); }
From source file:org.apache.mahout.feature.mrmr.common.commandline.DefaultOptionCreator.java
public static DefaultOptionBuilder columnNumberOption() { return new DefaultOptionBuilder().withLongName(COLUMN_NUMBER).withRequired(true).withShortName("nc") .withArgument(new ArgumentBuilder().withName(COLUMN_NUMBER).withMinimum(1).withMaximum(1).create()) .withDescription("Number of columns in the dataset"); }
From source file:org.apache.mahout.feature.mrmr.common.commandline.DefaultOptionCreator.java
public static DefaultOptionBuilder featureNumberOption() { return new DefaultOptionBuilder().withLongName(FEATURE_NUMBER).withRequired(true).withShortName("nf") .withArgument(new ArgumentBuilder().withName(FEATURE_NUMBER).withMinimum(1).withMaximum(1).create()) .withDescription("Number of feature to select"); }
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 www. ja v a2 s . c om*/ 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 ww w .jav a2 s .co m 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);//www. j ava 2 s . c o m 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.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);//from w w w .j a va2 s. co 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 w w . java 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(//ww w .j a va2 s . c o 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; }