List of usage examples for org.apache.commons.cli2.commandline Parser setHelpFormatter
public void setHelpFormatter(final HelpFormatter helpFormatter)
From source file:it.jnrpe.plugin.jmx.CCheckJMX.java
/** * @param args/*w w w . ja v a 2 s .c o m*/ */ public static void main(String[] args) { CCheckJMX checkJMX = new CCheckJMX(); Status status; try { // query.parse(args); // configure a parser PluginDefinition pluginDef = PluginRepositoryUtil.parseXmlPluginDefinition( JMXQuery.class.getClassLoader(), CCheckJMX.class.getResourceAsStream("/check_jmx_plugin.xml")); GroupBuilder gBuilder = new GroupBuilder(); for (PluginOption po : pluginDef.getOptions()) { gBuilder = gBuilder.withOption(po.toOption()); } HelpFormatter hf = new HelpFormatter(); Parser cliParser = new Parser(); cliParser.setGroup(gBuilder.create()); cliParser.setHelpFormatter(hf); CommandLine cl = cliParser.parse(args); ReturnValue retValue = checkJMX.execute(new PluginCommandLine(cl)); status = retValue.getStatus(); System.out.println(retValue.getMessage()); } catch (Exception ex) { status = checkJMX.report(ex, System.out); } finally { try { checkJMX.disconnect(); } catch (IOException e) { status = checkJMX.report(e, System.out); } } System.exit(status.intValue()); }
From source file:haflow.component.mahout.logistic.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(); Option outputFileOption = builder.withLongName("output").withRequired(true) .withArgument(argumentBuilder.withName("output").withMaximum(1).create()) .withDescription("where to store predicting data").create(); Option accurateFileOption = builder.withLongName("accurate").withRequired(true) .withArgument(argumentBuilder.withName("accurate").withMaximum(1).create()) .withDescription("where to store accurate information").create(); Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(auc).withOption(scores) .withOption(confusion).withOption(inputFileOption).withOption(modelFileOption) .withOption(outputFileOption).withOption(accurateFileOption).create(); Parser parser = new Parser(); parser.setHelpOption(help);//w w w .j ava 2 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); accurateFile = getStringArgument(cmdLine, accurateFileOption); showAuc = getBooleanArgument(cmdLine, auc); showScores = getBooleanArgument(cmdLine, scores); showConfusion = getBooleanArgument(cmdLine, confusion); return true; }
From source file:com.ml.ira.algos.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(); Option fieldNames = builder.withLongName("fdnames").withRequired(true) .withArgument(argumentBuilder.withName("fns").create()) .withDescription("the field names of training data set").create(); Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(auc).withOption(scores) .withOption(confusion).withOption(inputFileOption).withOption(modelFileOption) .withOption(fieldNames).create(); Parser parser = new Parser(); parser.setHelpOption(help);/*from ww w .j a v a2 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 = getStringArgument(cmdLine, inputFileOption); modelFile = getStringArgument(cmdLine, modelFileOption); showAuc = getBooleanArgument(cmdLine, auc); showScores = getBooleanArgument(cmdLine, scores); showConfusion = getBooleanArgument(cmdLine, confusion); RunLogistic.fieldNames = getStringArgument(cmdLine, fieldNames); System.out.println("inputFile: " + inputFile); System.out.println("modelFile: " + modelFile); System.out.println("fieldNames: " + RunLogistic.fieldNames); return true; }
From source file:com.cloudera.knittingboar.conf.cmdline.DataConverterCmdLineDriver.java
private static boolean parseArgs(String[] args) throws IOException { 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(); ArgumentBuilder argumentBuilder = new ArgumentBuilder(); Option inputFileOption = builder.withLongName("input").withRequired(true) .withArgument(argumentBuilder.withName("input").withMaximum(1).create()) .withDescription("where to get input data").create(); Option outputFileOption = builder.withLongName("output").withRequired(true) .withArgument(argumentBuilder.withName("output").withMaximum(1).create()) .withDescription("where to write output data").create(); Option recordsPerBlockOption = builder.withLongName("recordsPerBlock") .withArgument(//from w w w .j a v a2s. c om argumentBuilder.withName("recordsPerBlock").withDefault("20000").withMaximum(1).create()) .withDescription("the number of records per output file shard to write").create(); // optionally can be { 20Newsgroups, rcv1 } Option RecordFactoryType = builder .withLongName("datasetType").withArgument(argumentBuilder.withName("recordFactoryType") .withDefault("20Newsgroups").withMaximum(1).create()) .withDescription("the type of dataset to convert").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(); */ Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption) .withOption(outputFileOption).withOption(recordsPerBlockOption).withOption(RecordFactoryType) .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) { System.out.println("null!"); return false; } // "/Users/jpatterson/Downloads/datasets/20news-bydate/20news-bydate-train/" strInputFile = getStringArgument(cmdLine, inputFileOption); // "/Users/jpatterson/Downloads/datasets/20news-kboar/train4/" strOutputFile = getStringArgument(cmdLine, outputFileOption); strrecordsPerBlock = getStringArgument(cmdLine, recordsPerBlockOption); return true; }
From source file:it.jnrpe.server.JNRPEServer.java
/** * Parses the command line./*from w w w. j a va 2s. c om*/ * * @param vsArgs * The command line * @return The parsed command line */ private static CommandLine parseCommandLine(final String[] vsArgs) { try { Group opts = configureCommandLine(); // configure a HelpFormatter HelpFormatter hf = new HelpFormatter(); // configure a parser Parser p = new Parser(); p.setGroup(opts); p.setHelpFormatter(hf); // p.setHelpTrigger("--help"); return p.parse(vsArgs); } catch (OptionException oe) { printUsage(oe); } catch (Exception e) { e.printStackTrace(); // Should never happen... } return null; }
From source file:com.cloudera.knittingboar.conf.cmdline.ModelTrainerCmdLineDriver.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(); 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 features = builder.withLongName("features") .withArgument(argumentBuilder.withName("numFeatures").withDefault("1000").withMaximum(1).create()) .withDescription("the number of internal hashed features to use").create(); // optionally can be { 20Newsgroups, rcv1 } Option RecordFactoryType = builder.withLongName("recordFactoryType") .withArgument(argumentBuilder.withName("recordFactoryType").withDefault("20Newsgroups") .withMaximum(1).create()) .withDescription("the record vectorization factory 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(); Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFile).withOption(outputFile) .withOption(RecordFactoryType).withOption(passes).withOption(lambda).withOption(rate) .withOption(noBias).withOption(features).create(); Parser parser = new Parser(); parser.setHelpOption(help);//w ww. j a va 2 s . com parser.setHelpTrigger("--help"); parser.setGroup(normalArgs); parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130)); CommandLine cmdLine = parser.parseAndHelp(args); if (cmdLine == null) { System.out.println("null!"); return false; } input_dir = getStringArgument(cmdLine, inputFile); output_dir = getStringArgument(cmdLine, outputFile); /* * 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:com.ml.ira.algos.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 v a 2s .com 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(); Option fieldNames = builder.withLongName("fdnames").withRequired(true) .withArgument(argumentBuilder.withName("fns").create()) .withDescription("the field names of training data set").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).withOption(fieldNames).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); TrainLogistic.fieldNames = getStringArgument(cmdLine, fieldNames); List<String> typeList = Lists.newArrayList(); String tmp = getStringArgument(cmdLine, types); if (tmp != null) { typeList.addAll(Arrays.asList(tmp.split(","))); } tmp = getStringArgument(cmdLine, predictors); List<String> predictorList = Lists.newArrayList(); if (tmp != null) { predictorList.addAll(Arrays.asList(tmp.split(","))); } 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.setFieldNames(TrainLogistic.fieldNames); lmp.setLambda(getDoubleArgument(cmdLine, lambda)); lmp.setLearningRate(getDoubleArgument(cmdLine, rate)); TrainLogistic.scores = getBooleanArgument(cmdLine, scores); TrainLogistic.passes = getIntegerArgument(cmdLine, passes); System.out.println("@Train inputFile: " + TrainLogistic.inputFile); System.out.println("@Train fieldNames: " + TrainLogistic.fieldNames); System.out.println("@Train typeList: " + typeList); System.out.println("@Train predictorList: " + predictorList); return true; }
From source file:haflow.component.mahout.logistic.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 . jav a 2 s . c o m 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 inforFile = builder.withLongName("infor").withRequired(true) .withArgument(argumentBuilder.withName("infor").withMaximum(1).create()) .withDescription("where to store information about the training").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(inforFile).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); TrainLogistic.inforFile = getStringArgument(cmdLine, inforFile); 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); System.out.print("infor:" + TrainLogistic.inforFile); System.out.println("target:" + getStringArgument(cmdLine, target)); System.out.println("targetCategories:" + String.valueOf(getStringArgument(cmdLine, targetCategories))); System.out.println("features:" + String.valueOf(getStringArgument(cmdLine, features))); System.out.println("lambda:" + String.valueOf(getStringArgument(cmdLine, lambda))); System.out.println("rate:" + String.valueOf(getStringArgument(cmdLine, rate))); return true; }
From source file: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();/*from w w w .j av a 2 s. c o m*/ 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) { System.out.println(args); 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:com.memonews.mahout.sentiment.SentimentModelTester.java
boolean parseArgs(final String[] args) { final DefaultOptionBuilder builder = new DefaultOptionBuilder(); final Option help = builder.withLongName("help").withDescription("print this list").create(); final ArgumentBuilder argumentBuilder = new ArgumentBuilder(); final Option inputFileOption = builder.withLongName("input").withRequired(true) .withArgument(argumentBuilder.withName("input").withMaximum(1).create()) .withDescription("where to get training data").create(); final Option modelFileOption = builder.withLongName("model").withRequired(true) .withArgument(argumentBuilder.withName("model").withMaximum(1).create()) .withDescription("where to get a model").create(); final Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption) .withOption(modelFileOption).create(); final Parser parser = new Parser(); parser.setHelpOption(help);/*w ww . j a va 2 s. co m*/ parser.setHelpTrigger("--help"); parser.setGroup(normalArgs); parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130)); final CommandLine cmdLine = parser.parseAndHelp(args); if (cmdLine == null) { return false; } inputFile = (String) cmdLine.getValue(inputFileOption); modelFile = (String) cmdLine.getValue(modelFileOption); return true; }