List of usage examples for org.apache.commons.cli2.commandline Parser setGroup
public void setGroup(final Group group)
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);// www. ja va 2s . 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); 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 w w w. j a va 2s. com 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(/*w w w .java 2 s.c o m*/ 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 2 s .c o m*/ * * @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);/*from w ww . jav a2 s.c om*/ 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 .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(); 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();/*from w ww. j a v a 2 s . co 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();/* ww w . j a v a2s .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.ibm.jaql.util.shell.JaqlShellArguments.java
@SuppressWarnings("unchecked") static JaqlShellArguments parseArgs(String... args) { // option builders final DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); final ArgumentBuilder abuilder = new ArgumentBuilder(); final GroupBuilder gbuilder = new GroupBuilder(); // create standard options Option optHelp = obuilder.withShortName("h").withShortName("?").withLongName("help") .withDescription("print this message").create(); Option optJars = obuilder.withShortName("j").withLongName("jars") .withDescription(//from ww w.j av a 2s . c o m "comma-separated list of jar files to include user defined expressions or data stores") .withArgument(abuilder.withName("args").withMinimum(1).withMaximum(1).create()).create(); Option optSearchPath = obuilder.withShortName("jp").withLongName("jaql-path") .withDescription("colon seperated list of all search path entries") .withArgument(abuilder.withName("args").withMinimum(1).withMaximum(1).create()).create(); Option optBatch = obuilder.withShortName("b").withLongName("batch") .withDescription("run in batch mode (i.e., do not read from stdin)").create(); Option optOutOptions = obuilder.withShortName("o").withLongName("outoptions") .withDescription("output options: json, del and xml or an output IO descriptor. " + "This option is ignored when not running in batch mode.") .withArgument(abuilder.withName("outoptions").withMinimum(1).withMaximum(1).create()).create(); Option optEval = obuilder.withShortName("e").withLongName("eval") .withDescription("evaluate Jaql expression") .withArgument(abuilder.withName("expr").withMinimum(1).withMaximum(1).create()).create(); // create mini-cluster options Option optCluster = obuilder.withShortName("c").withLongName("cluster") .withDescription("use existing cluster (i.e., do not launch a mini-cluster)").create(); Option optNumNodes = obuilder.withShortName("n").withLongName("no-nodes") .withDescription("mini-cluster option: number of nodes to spawn") .withArgument(abuilder.withName("arg").withMinimum(1).withMaximum(1) .withValidator(NumberValidator.getIntegerInstance()).create()) .create(); Option optDir = obuilder.withShortName("d").withLongName("hdfs-dir") .withDescription("mini-cluster option: root HDFs directory") .withArgument(abuilder.withName("arg").withMinimum(1).withMaximum(1).create()).create(); Group clusterOptions = gbuilder.withName("Cluster options").withOption(optCluster).withOption(optDir) .withOption(optNumNodes).create(); // create input files option Option optInputFiles = abuilder.withName("file").withDescription("list of input files").withMinimum(0) .create(); Option optLog = obuilder.withShortName("l").withLongName("log") .withDescription("log options: json, del and xml or an output IO descriptor. ") .withArgument(abuilder.withName("arg").withMinimum(1).withMaximum(1).create()).create(); // combine all options Group options = gbuilder.withName("options").withOption(optHelp).withOption(optJars) .withOption(optSearchPath).withOption(optBatch).withOption(optLog).withOption(optOutOptions) .withOption(optEval).withOption(optInputFiles).withOption(clusterOptions).create(); // parse and print help if necessary CommandLine cl; try { Parser parser = new Parser(); parser.setGroup(options); cl = parser.parse(args); } catch (OptionException e) { printHelpAndExit(e, null, options); return null; } if (cl.hasOption(optHelp)) { printHelpAndExit(null, options); } // validate arguments JaqlShellArguments result = new JaqlShellArguments(); // mini-cluster options if (cl.hasOption(optCluster)) { result.useExistingCluster = true; } if (cl.hasOption(optDir)) { if (result.useExistingCluster) { printHelpAndExit("Options " + optCluster.getPreferredName() + " and " + optDir.getPreferredName() + " are mutually exclusive", options); } result.hdfsDir = (String) cl.getValue(optDir); } if (cl.hasOption(optNumNodes)) { if (result.useExistingCluster) { printHelpAndExit("Options " + optCluster.getPreferredName() + " and " + optNumNodes.getPreferredName() + " are mutually exclusive", options); } result.numNodes = ((Number) cl.getValue(optNumNodes)).intValue(); } // jar files if (cl.hasOption(optJars)) { result.jars = ((String) cl.getValue(optJars)).split(","); for (String jar : result.jars) { if (!new File(jar).exists()) { printHelpAndExit("Jar file " + jar + " not found", options); } } } // search path directories if (cl.hasOption(optSearchPath)) { result.searchPath = ((String) cl.getValue(optSearchPath)).split(":"); for (String dir : result.searchPath) { if (!new File(dir).exists() || !new File(dir).isDirectory()) { printHelpAndExit("Search-path entry " + dir + " not found or is no directory", options); } } } if (cl.hasOption(optBatch)) { result.batchMode = true; if (cl.hasOption(optOutOptions)) { String format = (String) cl.getValue(optOutOptions); try { result.outputAdapter = getOutputAdapter(format); } catch (Exception e) { printHelpAndExit(e, "\"" + format + "\" is neither a valid output format nor a valid IO descriptor", options); } } } // input if (cl.hasOption(optEval)) { String eval = (String) cl.getValue(optEval); if (!eval.endsWith(";")) eval += ";"; result.addInputStream(new ByteArrayInputStream(eval.getBytes())); } if (cl.hasOption(optInputFiles)) { List<String> files = (List<String>) cl.getValues(optInputFiles); for (String file : files) { try { result.addInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { printHelpAndExit(e, "Input file " + file + " not found", options); } } } // error log if (cl.hasOption(optLog)) { String path = (String) cl.getValue(optLog); try { BufferedJsonRecord logFD = new BufferedJsonRecord(); logFD.add(Adapter.TYPE_NAME, new JsonString("local")); logFD.add(Adapter.LOCATION_NAME, new JsonString(path)); OutputAdapter oa = (OutputAdapter) JaqlUtil.getAdapterStore().output.getAdapter(logFD); result.logAdapter = oa; } catch (Exception e) { printHelpAndExit(e, "\"" + path + "\" invalid", options); } } if (!result.batchMode) { result.addStdin(); } return result; }
From source file:com.martinkampjensen.thesis.Main.java
private static CommandLine parse(String[] args, Group group) { final Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = null;/* ww w.ja va 2 s. c o m*/ try { cmdLine = parser.parse(args); } catch (OptionException e) { System.out.println(e.getMessage()); exit(StatusCode.ARGUMENT); } return cmdLine; }