List of usage examples for org.apache.commons.cli2.commandline Parser parseAndHelp
public CommandLine parseAndHelp(final String[] arguments)
From source file:org.apache.mahout.classifier.mlp.TrainMultilayerPerceptron.java
/** * Parse the input arguments.//from w w w . jav a 2 s . com * * @param args The input arguments * @param parameters The parameters parsed. * @return Whether the input arguments are valid. * @throws Exception */ private static boolean parseArgs(String[] args, Parameters parameters) throws Exception { // build the options log.info("Validate and parse arguments..."); DefaultOptionBuilder optionBuilder = new DefaultOptionBuilder(); GroupBuilder groupBuilder = new GroupBuilder(); ArgumentBuilder argumentBuilder = new ArgumentBuilder(); // whether skip the first row of the input file Option skipHeaderOption = optionBuilder.withLongName("skipHeader").withShortName("sh").create(); Group skipHeaderGroup = groupBuilder.withOption(skipHeaderOption).create(); Option inputOption = optionBuilder.withLongName("input").withShortName("i").withRequired(true) .withChildren(skipHeaderGroup) .withArgument(argumentBuilder.withName("path").withMinimum(1).withMaximum(1).create()) .withDescription("the file path of training dataset").create(); Option labelsOption = optionBuilder.withLongName("labels").withShortName("labels").withRequired(true) .withArgument(argumentBuilder.withName("label-name").withMinimum(2).create()) .withDescription("label names").create(); Option updateOption = optionBuilder.withLongName("update").withShortName("u") .withDescription("whether to incrementally update model if the model exists").create(); Group modelUpdateGroup = groupBuilder.withOption(updateOption).create(); Option modelOption = optionBuilder.withLongName("model").withShortName("mo").withRequired(true) .withArgument(argumentBuilder.withName("model-path").withMinimum(1).withMaximum(1).create()) .withDescription("the path to store the trained model").withChildren(modelUpdateGroup).create(); Option layerSizeOption = optionBuilder.withLongName("layerSize").withShortName("ls").withRequired(true) .withArgument(argumentBuilder.withName("size of layer").withMinimum(2).withMaximum(5).create()) .withDescription("the size of each layer").create(); Option squashingFunctionOption = optionBuilder.withLongName("squashingFunction").withShortName("sf") .withArgument(argumentBuilder.withName("squashing function").withMinimum(1).withMaximum(1) .withDefault("Sigmoid").create()) .withDescription("the name of squashing function (currently only supports Sigmoid)").create(); Option learningRateOption = optionBuilder.withLongName("learningRate").withShortName("l") .withArgument(argumentBuilder.withName("learning rate").withMaximum(1).withMinimum(1) .withDefault(NeuralNetwork.DEFAULT_LEARNING_RATE).create()) .withDescription("learning rate").create(); Option momemtumOption = optionBuilder.withLongName("momemtumWeight").withShortName("m") .withArgument(argumentBuilder.withName("momemtum weight").withMaximum(1).withMinimum(1) .withDefault(NeuralNetwork.DEFAULT_MOMENTUM_WEIGHT).create()) .withDescription("momemtum weight").create(); Option regularizationOption = optionBuilder.withLongName("regularizationWeight").withShortName("r") .withArgument(argumentBuilder.withName("regularization weight").withMaximum(1).withMinimum(1) .withDefault(NeuralNetwork.DEFAULT_REGULARIZATION_WEIGHT).create()) .withDescription("regularization weight").create(); // parse the input Parser parser = new Parser(); Group normalOptions = groupBuilder.withOption(inputOption).withOption(skipHeaderOption) .withOption(updateOption).withOption(labelsOption).withOption(modelOption) .withOption(layerSizeOption).withOption(squashingFunctionOption).withOption(learningRateOption) .withOption(momemtumOption).withOption(regularizationOption).create(); parser.setGroup(normalOptions); CommandLine commandLine = parser.parseAndHelp(args); if (commandLine == null) { return false; } parameters.learningRate = getDouble(commandLine, learningRateOption); parameters.momemtumWeight = getDouble(commandLine, momemtumOption); parameters.regularizationWeight = getDouble(commandLine, regularizationOption); parameters.inputFilePath = getString(commandLine, inputOption); parameters.skipHeader = commandLine.hasOption(skipHeaderOption); List<String> labelsList = getStringList(commandLine, labelsOption); int currentIndex = 0; for (String label : labelsList) { parameters.labelsIndex.put(label, currentIndex++); } parameters.modelFilePath = getString(commandLine, modelOption); parameters.updateModel = commandLine.hasOption(updateOption); parameters.layerSizeList = getIntegerList(commandLine, layerSizeOption); parameters.squashingFunctionName = getString(commandLine, squashingFunctionOption); System.out.printf( "Input: %s, Model: %s, Update: %s, Layer size: %s, Squashing function: %s, Learning rate: %f," + " Momemtum weight: %f, Regularization Weight: %f\n", parameters.inputFilePath, parameters.modelFilePath, parameters.updateModel, Arrays.toString(parameters.layerSizeList.toArray()), parameters.squashingFunctionName, parameters.learningRate, parameters.momemtumWeight, parameters.regularizationWeight); return true; }
From source file:org.apache.mahout.classifier.sgd.RunAdaptiveLogistic.java
private static boolean parseArgs(String[] args) { DefaultOptionBuilder builder = new DefaultOptionBuilder(); Option help = builder.withLongName("help").withDescription("print this list").create(); Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create(); ArgumentBuilder argumentBuilder = new ArgumentBuilder(); Option inputFileOption = builder.withLongName("input").withRequired(true) .withArgument(argumentBuilder.withName("input").withMaximum(1).create()) .withDescription("where to get training data").create(); Option modelFileOption = builder.withLongName("model").withRequired(true) .withArgument(argumentBuilder.withName("model").withMaximum(1).create()) .withDescription("where to get the trained model").create(); Option outputFileOption = builder.withLongName("output").withRequired(true) .withDescription("the file path to output scores") .withArgument(argumentBuilder.withName("output").withMaximum(1).create()).create(); Option idColumnOption = builder.withLongName("idcolumn").withRequired(true) .withDescription("the name of the id column for each record") .withArgument(argumentBuilder.withName("idcolumn").withMaximum(1).create()).create(); Option maxScoreOnlyOption = builder.withLongName("maxscoreonly") .withDescription("only output the target label with max scores").create(); Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(inputFileOption) .withOption(modelFileOption).withOption(outputFileOption).withOption(idColumnOption) .withOption(maxScoreOnlyOption).create(); Parser parser = new Parser(); parser.setHelpOption(help);/*from www . j a v a2 s . c om*/ parser.setHelpTrigger("--help"); parser.setGroup(normalArgs); parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130)); CommandLine cmdLine = parser.parseAndHelp(args); if (cmdLine == null) { return false; } inputFile = getStringArgument(cmdLine, inputFileOption); modelFile = getStringArgument(cmdLine, modelFileOption); outputFile = getStringArgument(cmdLine, outputFileOption); idColumn = getStringArgument(cmdLine, idColumnOption); maxScoreOnly = getBooleanArgument(cmdLine, maxScoreOnlyOption); return true; }
From source file:org.apache.mahout.classifier.sgd.RunLogistic.java
private static boolean parseArgs(String[] args) { DefaultOptionBuilder builder = new DefaultOptionBuilder(); Option help = builder.withLongName("help").withDescription("print this list").create(); Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create(); Option auc = builder.withLongName("auc").withDescription("print AUC").create(); Option confusion = builder.withLongName("confusion").withDescription("print confusion matrix").create(); Option scores = builder.withLongName("scores").withDescription("print scores").create(); ArgumentBuilder argumentBuilder = new ArgumentBuilder(); Option inputFileOption = builder.withLongName("input").withRequired(true) .withArgument(argumentBuilder.withName("input").withMaximum(1).create()) .withDescription("where to get training data").create(); Option modelFileOption = builder.withLongName("model").withRequired(true) .withArgument(argumentBuilder.withName("model").withMaximum(1).create()) .withDescription("where to get a model").create(); Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(auc).withOption(scores) .withOption(confusion).withOption(inputFileOption).withOption(modelFileOption).create(); Parser parser = new Parser(); parser.setHelpOption(help);//from ww w. ja va2 s .c o m parser.setHelpTrigger("--help"); parser.setGroup(normalArgs); parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130)); CommandLine cmdLine = parser.parseAndHelp(args); if (cmdLine == null) { return false; } inputFile = getStringArgument(cmdLine, inputFileOption); modelFile = getStringArgument(cmdLine, modelFileOption); showAuc = getBooleanArgument(cmdLine, auc); showScores = getBooleanArgument(cmdLine, scores); showConfusion = getBooleanArgument(cmdLine, confusion); return true; }
From source file:org.apache.mahout.classifier.sgd.TestASFEmail.java
boolean parseArgs(String[] args) { DefaultOptionBuilder builder = new DefaultOptionBuilder(); Option help = builder.withLongName("help").withDescription("print this list").create(); ArgumentBuilder argumentBuilder = new ArgumentBuilder(); Option inputFileOption = builder.withLongName("input").withRequired(true) .withArgument(argumentBuilder.withName("input").withMaximum(1).create()) .withDescription("where to get training data").create(); Option modelFileOption = builder.withLongName("model").withRequired(true) .withArgument(argumentBuilder.withName("model").withMaximum(1).create()) .withDescription("where to get a model").create(); Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption) .withOption(modelFileOption).create(); Parser parser = new Parser(); parser.setHelpOption(help);/* w w w . j ava 2 s.com*/ parser.setHelpTrigger("--help"); parser.setGroup(normalArgs); parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130)); CommandLine cmdLine = parser.parseAndHelp(args); if (cmdLine == null) { return false; } inputFile = (String) cmdLine.getValue(inputFileOption); modelFile = (String) cmdLine.getValue(modelFileOption); return true; }
From source file:org.apache.mahout.classifier.sgd.TrainAdaptiveLogistic.java
private static boolean parseArgs(String[] args) { DefaultOptionBuilder builder = new DefaultOptionBuilder(); Option help = builder.withLongName("help").withDescription("print this list").create(); Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create(); ArgumentBuilder argumentBuilder = new ArgumentBuilder(); Option showperf = builder.withLongName("showperf") .withDescription("output performance measures during training").create(); Option inputFile = builder.withLongName("input").withRequired(true) .withArgument(argumentBuilder.withName("input").withMaximum(1).create()) .withDescription("where to get training data").create(); Option outputFile = builder.withLongName("output").withRequired(true) .withArgument(argumentBuilder.withName("output").withMaximum(1).create()) .withDescription("where to write the model content").create(); Option threads = builder.withLongName("threads") .withArgument(argumentBuilder.withName("threads").withDefault("4").create()) .withDescription("the number of threads AdaptiveLogisticRegression uses").create(); Option predictors = builder.withLongName("predictors").withRequired(true) .withArgument(argumentBuilder.withName("predictors").create()) .withDescription("a list of predictor variables").create(); Option types = builder.withLongName("types").withRequired(true) .withArgument(argumentBuilder.withName("types").create()) .withDescription("a list of predictor variable types (numeric, word, or text)").create(); Option target = builder.withLongName("target").withDescription("the name of the target variable") .withRequired(true).withArgument(argumentBuilder.withName("target").withMaximum(1).create()) .create();// ww w . java2 s . co m Option targetCategories = builder.withLongName("categories") .withDescription("the number of target categories to be considered").withRequired(true) .withArgument(argumentBuilder.withName("categories").withMaximum(1).create()).create(); Option features = builder.withLongName("features") .withDescription("the number of internal hashed features to use") .withArgument(argumentBuilder.withName("numFeatures").withDefault("1000").withMaximum(1).create()) .create(); Option passes = builder.withLongName("passes") .withDescription("the number of times to pass over the input data") .withArgument(argumentBuilder.withName("passes").withDefault("2").withMaximum(1).create()).create(); Option interval = builder.withLongName("interval") .withArgument(argumentBuilder.withName("interval").withDefault("500").create()) .withDescription("the interval property of AdaptiveLogisticRegression").create(); Option window = builder.withLongName("window") .withArgument(argumentBuilder.withName("window").withDefault("800").create()) .withDescription("the average propery of AdaptiveLogisticRegression").create(); Option skipperfnum = builder.withLongName("skipperfnum") .withArgument(argumentBuilder.withName("skipperfnum").withDefault("99").create()) .withDescription("show performance measures every (skipperfnum + 1) rows").create(); Option prior = builder.withLongName("prior") .withArgument(argumentBuilder.withName("prior").withDefault("L1").create()) .withDescription("the prior algorithm to use: L1, L2, ebp, tp, up").create(); Option priorOption = builder.withLongName("prioroption") .withArgument(argumentBuilder.withName("prioroption").create()) .withDescription("constructor parameter for ElasticBandPrior and TPrior").create(); Option auc = builder.withLongName("auc") .withArgument(argumentBuilder.withName("auc").withDefault("global").create()) .withDescription("the auc to use: global or grouped").create(); Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(inputFile) .withOption(outputFile).withOption(target).withOption(targetCategories).withOption(predictors) .withOption(types).withOption(passes).withOption(interval).withOption(window).withOption(threads) .withOption(prior).withOption(features).withOption(showperf).withOption(skipperfnum) .withOption(priorOption).withOption(auc).create(); Parser parser = new Parser(); parser.setHelpOption(help); parser.setHelpTrigger("--help"); parser.setGroup(normalArgs); parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130)); CommandLine cmdLine = parser.parseAndHelp(args); if (cmdLine == null) { return false; } TrainAdaptiveLogistic.inputFile = getStringArgument(cmdLine, inputFile); TrainAdaptiveLogistic.outputFile = getStringArgument(cmdLine, outputFile); List<String> typeList = Lists.newArrayList(); for (Object x : cmdLine.getValues(types)) { typeList.add(x.toString()); } List<String> predictorList = Lists.newArrayList(); for (Object x : cmdLine.getValues(predictors)) { predictorList.add(x.toString()); } lmp = new AdaptiveLogisticModelParameters(); lmp.setTargetVariable(getStringArgument(cmdLine, target)); lmp.setMaxTargetCategories(getIntegerArgument(cmdLine, targetCategories)); lmp.setNumFeatures(getIntegerArgument(cmdLine, features)); lmp.setInterval(getIntegerArgument(cmdLine, interval)); lmp.setAverageWindow(getIntegerArgument(cmdLine, window)); lmp.setThreads(getIntegerArgument(cmdLine, threads)); lmp.setAuc(getStringArgument(cmdLine, auc)); lmp.setPrior(getStringArgument(cmdLine, prior)); if (cmdLine.getValue(priorOption) != null) { lmp.setPriorOption(getDoubleArgument(cmdLine, priorOption)); } lmp.setTypeMap(predictorList, typeList); TrainAdaptiveLogistic.showperf = getBooleanArgument(cmdLine, showperf); TrainAdaptiveLogistic.skipperfnum = getIntegerArgument(cmdLine, skipperfnum); TrainAdaptiveLogistic.passes = getIntegerArgument(cmdLine, passes); lmp.checkParameters(); return true; }
From source file:org.apache.mahout.classifier.sgd.TrainLogistic.java
private static boolean parseArgs(String[] args) { DefaultOptionBuilder builder = new DefaultOptionBuilder(); Option help = builder.withLongName("help").withDescription("print this list").create(); Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create(); Option scores = builder.withLongName("scores").withDescription("output score diagnostics during training") .create();/*w w w. j a va 2s . c om*/ ArgumentBuilder argumentBuilder = new ArgumentBuilder(); Option inputFile = builder.withLongName("input").withRequired(true) .withArgument(argumentBuilder.withName("input").withMaximum(1).create()) .withDescription("where to get training data").create(); Option outputFile = builder.withLongName("output").withRequired(true) .withArgument(argumentBuilder.withName("output").withMaximum(1).create()) .withDescription("where to get training data").create(); Option predictors = builder.withLongName("predictors").withRequired(true) .withArgument(argumentBuilder.withName("p").create()) .withDescription("a list of predictor variables").create(); Option types = builder.withLongName("types").withRequired(true) .withArgument(argumentBuilder.withName("t").create()) .withDescription("a list of predictor variable types (numeric, word, or text)").create(); Option target = builder.withLongName("target").withRequired(true) .withArgument(argumentBuilder.withName("target").withMaximum(1).create()) .withDescription("the name of the target variable").create(); Option features = builder.withLongName("features") .withArgument(argumentBuilder.withName("numFeatures").withDefault("1000").withMaximum(1).create()) .withDescription("the number of internal hashed features to use").create(); Option passes = builder.withLongName("passes") .withArgument(argumentBuilder.withName("passes").withDefault("2").withMaximum(1).create()) .withDescription("the number of times to pass over the input data").create(); Option lambda = builder.withLongName("lambda") .withArgument(argumentBuilder.withName("lambda").withDefault("1e-4").withMaximum(1).create()) .withDescription("the amount of coefficient decay to use").create(); Option rate = builder.withLongName("rate") .withArgument(argumentBuilder.withName("learningRate").withDefault("1e-3").withMaximum(1).create()) .withDescription("the learning rate").create(); Option noBias = builder.withLongName("noBias").withDescription("don't include a bias term").create(); Option targetCategories = builder.withLongName("categories").withRequired(true) .withArgument(argumentBuilder.withName("number").withMaximum(1).create()) .withDescription("the number of target categories to be considered").create(); Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(inputFile) .withOption(outputFile).withOption(target).withOption(targetCategories).withOption(predictors) .withOption(types).withOption(passes).withOption(lambda).withOption(rate).withOption(noBias) .withOption(features).create(); Parser parser = new Parser(); parser.setHelpOption(help); parser.setHelpTrigger("--help"); parser.setGroup(normalArgs); parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130)); CommandLine cmdLine = parser.parseAndHelp(args); if (cmdLine == null) { return false; } TrainLogistic.inputFile = getStringArgument(cmdLine, inputFile); TrainLogistic.outputFile = getStringArgument(cmdLine, outputFile); List<String> typeList = Lists.newArrayList(); for (Object x : cmdLine.getValues(types)) { typeList.add(x.toString()); } List<String> predictorList = Lists.newArrayList(); for (Object x : cmdLine.getValues(predictors)) { predictorList.add(x.toString()); } lmp = new LogisticModelParameters(); lmp.setTargetVariable(getStringArgument(cmdLine, target)); lmp.setMaxTargetCategories(getIntegerArgument(cmdLine, targetCategories)); lmp.setNumFeatures(getIntegerArgument(cmdLine, features)); lmp.setUseBias(!getBooleanArgument(cmdLine, noBias)); lmp.setTypeMap(predictorList, typeList); lmp.setLambda(getDoubleArgument(cmdLine, lambda)); lmp.setLearningRate(getDoubleArgument(cmdLine, rate)); TrainLogistic.scores = getBooleanArgument(cmdLine, scores); TrainLogistic.passes = getIntegerArgument(cmdLine, passes); return true; }
From source file:org.apache.mahout.classifier.sgd.ValidateAdaptiveLogistic.java
private static boolean parseArgs(String[] args) { DefaultOptionBuilder builder = new DefaultOptionBuilder(); Option help = builder.withLongName("help").withDescription("print this list").create(); Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create(); Option auc = builder.withLongName("auc").withDescription("print AUC").create(); Option confusion = builder.withLongName("confusion").withDescription("print confusion matrix").create(); Option scores = builder.withLongName("scores").withDescription("print scores").create(); ArgumentBuilder argumentBuilder = new ArgumentBuilder(); Option inputFileOption = builder.withLongName("input").withRequired(true) .withArgument(argumentBuilder.withName("input").withMaximum(1).create()) .withDescription("where to get validate data").create(); Option modelFileOption = builder.withLongName("model").withRequired(true) .withArgument(argumentBuilder.withName("model").withMaximum(1).create()) .withDescription("where to get the trained model").create(); Option defaultCagetoryOption = builder.withLongName("defaultCategory").withRequired(false) .withArgument(/* w w w .j a va2s . co m*/ argumentBuilder.withName("defaultCategory").withMaximum(1).withDefault("unknown").create()) .withDescription("the default category value to use").create(); Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(auc).withOption(scores) .withOption(confusion).withOption(inputFileOption).withOption(modelFileOption) .withOption(defaultCagetoryOption).create(); Parser parser = new Parser(); parser.setHelpOption(help); parser.setHelpTrigger("--help"); parser.setGroup(normalArgs); parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130)); CommandLine cmdLine = parser.parseAndHelp(args); if (cmdLine == null) { return false; } inputFile = getStringArgument(cmdLine, inputFileOption); modelFile = getStringArgument(cmdLine, modelFileOption); defaultCategory = getStringArgument(cmdLine, defaultCagetoryOption); showAuc = getBooleanArgument(cmdLine, auc); showScores = getBooleanArgument(cmdLine, scores); showConfusion = getBooleanArgument(cmdLine, confusion); return true; }
From source file:org.apache.mahout.clustering.streaming.tools.ClusterQualitySummarizer.java
private boolean parseArgs(String[] args) { DefaultOptionBuilder builder = new DefaultOptionBuilder(); Option help = builder.withLongName("help").withDescription("print this list").create(); ArgumentBuilder argumentBuilder = new ArgumentBuilder(); Option inputFileOption = builder.withLongName("input").withShortName("i").withRequired(true) .withArgument(argumentBuilder.withName("input").withMaximum(1).create()) .withDescription("where to get seq files with the vectors (training set)").create(); Option testInputFileOption = builder.withLongName("testInput").withShortName("itest") .withArgument(argumentBuilder.withName("testInput").withMaximum(1).create()) .withDescription("where to get seq files with the vectors (test set)").create(); Option centroidsFileOption = builder.withLongName("centroids").withShortName("c").withRequired(true) .withArgument(argumentBuilder.withName("centroids").withMaximum(1).create()) .withDescription(/*from w ww . j a va 2 s .co m*/ "where to get seq files with the centroids (from Mahout KMeans or StreamingKMeansDriver)") .create(); Option centroidsCompareFileOption = builder.withLongName("centroidsCompare").withShortName("cc") .withRequired(false) .withArgument(argumentBuilder.withName("centroidsCompare").withMaximum(1).create()) .withDescription("where to get seq files with the second set of centroids (from Mahout KMeans or " + "StreamingKMeansDriver)") .create(); Option outputFileOption = builder.withLongName("output").withShortName("o").withRequired(true) .withArgument(argumentBuilder.withName("output").withMaximum(1).create()) .withDescription("where to dump the CSV file with the results").create(); Option mahoutKMeansFormatOption = builder.withLongName("mahoutkmeansformat").withShortName("mkm") .withDescription("if set, read files as (IntWritable, ClusterWritable) pairs") .withArgument(argumentBuilder.withName("numpoints").withMaximum(1).create()).create(); Option mahoutKMeansCompareFormatOption = builder.withLongName("mahoutkmeansformatCompare") .withShortName("mkmc").withDescription("if set, read files as (IntWritable, ClusterWritable) pairs") .withArgument(argumentBuilder.withName("numpoints").withMaximum(1).create()).create(); Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption) .withOption(testInputFileOption).withOption(outputFileOption).withOption(centroidsFileOption) .withOption(centroidsCompareFileOption).withOption(mahoutKMeansFormatOption) .withOption(mahoutKMeansCompareFormatOption).create(); Parser parser = new Parser(); parser.setHelpOption(help); parser.setHelpTrigger("--help"); parser.setGroup(normalArgs); parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 150)); CommandLine cmdLine = parser.parseAndHelp(args); if (cmdLine == null) { return false; } trainFile = (String) cmdLine.getValue(inputFileOption); if (cmdLine.hasOption(testInputFileOption)) { testFile = (String) cmdLine.getValue(testInputFileOption); } centroidFile = (String) cmdLine.getValue(centroidsFileOption); if (cmdLine.hasOption(centroidsCompareFileOption)) { centroidCompareFile = (String) cmdLine.getValue(centroidsCompareFileOption); } outputFile = (String) cmdLine.getValue(outputFileOption); if (cmdLine.hasOption(mahoutKMeansFormatOption)) { mahoutKMeansFormat = true; } if (cmdLine.hasOption(mahoutKMeansCompareFormatOption)) { mahoutKMeansFormatCompare = true; } return true; }
From source file:org.apache.mahout.clustering.streaming.tools.ResplitSequenceFiles.java
private boolean parseArgs(String[] args) { DefaultOptionBuilder builder = new DefaultOptionBuilder(); Option help = builder.withLongName("help").withDescription("print this list").create(); ArgumentBuilder argumentBuilder = new ArgumentBuilder(); Option inputFileOption = builder.withLongName("input").withShortName("i").withRequired(true) .withArgument(argumentBuilder.withName("input").withMaximum(1).create()) .withDescription(// ww w. j a v a2 s.c o m "what the base folder for sequence files is (they all must have the same key/value type") .create(); Option outputFileOption = builder.withLongName("output").withShortName("o").withRequired(true) .withArgument(argumentBuilder.withName("output").withMaximum(1).create()) .withDescription( "the base name of the file split that the files will be split it; the i'th split has the " + "suffix -i") .create(); Option numSplitsOption = builder.withLongName("numSplits").withShortName("ns").withRequired(true) .withArgument(argumentBuilder.withName("numSplits").withMaximum(1).create()) .withDescription("how many splits to use for the given files").create(); Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption) .withOption(outputFileOption).withOption(numSplitsOption).create(); Parser parser = new Parser(); parser.setHelpOption(help); parser.setHelpTrigger("--help"); parser.setGroup(normalArgs); parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130)); CommandLine cmdLine = parser.parseAndHelp(args); if (cmdLine == null) { return false; } inputFile = (String) cmdLine.getValue(inputFileOption); outputFileBase = (String) cmdLine.getValue(outputFileOption); numSplits = Integer.parseInt((String) cmdLine.getValue(numSplitsOption)); return true; }
From source file:org.apache.mahout.knn.tools.TestNewsGroupsKMeanLogisticRegression.java
boolean parseArgs(String[] args) { DefaultOptionBuilder builder = new DefaultOptionBuilder(); Option help = builder.withLongName("help").withDescription("print this list").create(); ArgumentBuilder argumentBuilder = new ArgumentBuilder(); Option inputFileOption = builder.withLongName("input").withShortName("i").withRequired(true) .withArgument(argumentBuilder.withName("input").withMaximum(1).create()) .withDescription("where to get test data (encoded with tf-idf)").create(); Option modelFileOption = builder.withLongName("model").withShortName("m").withRequired(true) .withArgument(argumentBuilder.withName("model").withMaximum(1).create()) .withDescription("where to get a model").create(); Option centroidsFileOption = builder.withLongName("centroids").withShortName("c").withRequired(true) .withArgument(argumentBuilder.withName("centroids").withMaximum(1).create()) .withDescription("where to get the centroids seqfile").create(); Option labelFileOption = builder.withLongName("labels").withShortName("l").withRequired(true) .withArgument(argumentBuilder.withName("labels").withMaximum(1).create()) .withDescription("CSV file containing the cluster labels").create(); Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption) .withOption(modelFileOption).withOption(centroidsFileOption).withOption(labelFileOption).create(); Parser parser = new Parser(); parser.setHelpOption(help);/* w w w . java 2s .c om*/ 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; }