List of usage examples for org.apache.commons.cli2 OptionException toString
public String toString()
From source file:imageClassify.Describe.java
public static void main(String[] args) throws IOException, DescriptorException { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option pathOpt = obuilder.withLongName("path").withShortName("p").withRequired(true) .withArgument(abuilder.withName("path").withMinimum(1).withMaximum(1).create()) .withDescription("Data path").create(); Option descriptorOpt = obuilder.withLongName("descriptor").withShortName("d").withRequired(true) .withArgument(abuilder.withName("descriptor").withMinimum(1).create()) .withDescription("data descriptor").create(); Option descPathOpt = obuilder.withLongName("file").withShortName("f").withRequired(true) .withArgument(abuilder.withName("file").withMinimum(1).withMaximum(1).create()) .withDescription("Path to generated descriptor file").create(); Option regOpt = obuilder.withLongName("regression").withDescription("Regression Problem").withShortName("r") .create();//from w ww . j a va2s. c o m Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h") .create(); Group group = gbuilder.withName("Options").withOption(pathOpt).withOption(descPathOpt) .withOption(descriptorOpt).withOption(regOpt).withOption(helpOpt).create(); try { Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelp(group); return; } String dataPath = cmdLine.getValue(pathOpt).toString(); String descPath = cmdLine.getValue(descPathOpt).toString(); List<String> descriptor = convert(cmdLine.getValues(descriptorOpt)); boolean regression = cmdLine.hasOption(regOpt); log.debug("Data path : {}", dataPath); log.debug("Descriptor path : {}", descPath); log.debug("Descriptor : {}", descriptor); log.debug("Regression : {}", regression); runTool(dataPath, descriptor, descPath, regression); } catch (OptionException e) { log.warn(e.toString()); CommandLineUtil.printHelp(group); } }
From source file:com.wsc.myexample.decisionForest.MyTestForest.java
public int init(String[] args) throws IOException, ClassNotFoundException, InterruptedException { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option inputOpt = DefaultOptionCreator.inputOption().create(); Option datasetOpt = obuilder.withLongName("dataset").withShortName("ds").withRequired(true) .withArgument(abuilder.withName("dataset").withMinimum(1).withMaximum(1).create()) .withDescription("Dataset path").create(); Option modelOpt = obuilder.withLongName("model").withShortName("m").withRequired(true) .withArgument(abuilder.withName("path").withMinimum(1).withMaximum(1).create()) .withDescription("Path to the Decision Forest").create(); Option outputOpt = DefaultOptionCreator.outputOption().create(); Option analyzeOpt = obuilder.withLongName("analyze").withShortName("a").withRequired(false).create(); Option mrOpt = obuilder.withLongName("mapreduce").withShortName("mr").withRequired(false).create(); Option helpOpt = DefaultOptionCreator.helpOption(); Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(datasetOpt).withOption(modelOpt) .withOption(outputOpt).withOption(analyzeOpt).withOption(mrOpt).withOption(helpOpt).create(); try {/*from ww w . ja v a 2s. c o m*/ Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption("help")) { CommandLineUtil.printHelp(group); return -1; } String dataName = cmdLine.getValue(inputOpt).toString(); String datasetName = cmdLine.getValue(datasetOpt).toString(); String modelName = cmdLine.getValue(modelOpt).toString(); String outputName = cmdLine.hasOption(outputOpt) ? cmdLine.getValue(outputOpt).toString() : null; analyze = cmdLine.hasOption(analyzeOpt); useMapreduce = cmdLine.hasOption(mrOpt); if (log.isDebugEnabled()) { log.debug("inout : {}", dataName); log.debug("dataset : {}", datasetName); log.debug("model : {}", modelName); log.debug("output : {}", outputName); log.debug("analyze : {}", analyze); log.debug("mapreduce : {}", useMapreduce); } dataPath = dataName; datasetPath = datasetName; modelPath = modelName; if (outputName != null) { outputPath = outputName; } } catch (OptionException e) { log.warn(e.toString(), e); CommandLineUtil.printHelp(group); return -1; } testForest(); return 0; }
From source file:imageClassify.TestForest.java
@Override public int run(String[] args) throws IOException, ClassNotFoundException, InterruptedException { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option inputOpt = DefaultOptionCreator.inputOption().create(); Option datasetOpt = obuilder.withLongName("dataset").withShortName("ds").withRequired(true) .withArgument(abuilder.withName("dataset").withMinimum(1).withMaximum(1).create()) .withDescription("Dataset path").create(); Option modelOpt = obuilder.withLongName("model").withShortName("m").withRequired(true) .withArgument(abuilder.withName("path").withMinimum(1).withMaximum(1).create()) .withDescription("Path to the Decision Forest").create(); Option outputOpt = DefaultOptionCreator.outputOption().create(); Option analyzeOpt = obuilder.withLongName("analyze").withShortName("a").withRequired(false).create(); Option mrOpt = obuilder.withLongName("mapreduce").withShortName("mr").withRequired(false).create(); Option helpOpt = DefaultOptionCreator.helpOption(); Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(datasetOpt).withOption(modelOpt) .withOption(outputOpt).withOption(analyzeOpt).withOption(mrOpt).withOption(helpOpt).create(); try {//w w w .j av a 2 s . c o m Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption("help")) { CommandLineUtil.printHelp(group); return -1; } String dataName = cmdLine.getValue(inputOpt).toString(); String datasetName = cmdLine.getValue(datasetOpt).toString(); String modelName = cmdLine.getValue(modelOpt).toString(); String outputName = cmdLine.hasOption(outputOpt) ? cmdLine.getValue(outputOpt).toString() : null; analyze = cmdLine.hasOption(analyzeOpt); useMapreduce = cmdLine.hasOption(mrOpt); if (log.isDebugEnabled()) { log.debug("inout : {}", dataName); log.debug("dataset : {}", datasetName); log.debug("model : {}", modelName); log.debug("output : {}", outputName); log.debug("analyze : {}", analyze); log.debug("mapreduce : {}", useMapreduce); } dataPath = new Path(dataName); datasetPath = new Path(datasetName); modelPath = new Path(modelName); if (outputName != null) { outputPath = new Path(outputName); } } catch (OptionException e) { log.warn(e.toString(), e); CommandLineUtil.printHelp(group); return -1; } testForest(); return 0; }
From source file:org.apache.mahout.classifier.chi_rwcs.mapreduce.TestModel.java
@Override public int run(String[] args) throws IOException, ClassNotFoundException, InterruptedException { // TODO Auto-generated method stub DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option inputOpt = DefaultOptionCreator.inputOption().create(); Option datasetOpt = obuilder.withLongName("dataset").withShortName("ds").withRequired(true) .withArgument(abuilder.withName("dataset").withMinimum(1).withMaximum(1).create()) .withDescription("Dataset path").create(); Option modelOpt = obuilder.withLongName("model").withShortName("m").withRequired(true) .withArgument(abuilder.withName("path").withMinimum(1).withMaximum(1).create()) .withDescription("Path to the Model").create(); Option outputOpt = DefaultOptionCreator.outputOption().create(); Option helpOpt = DefaultOptionCreator.helpOption(); Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(datasetOpt).withOption(modelOpt) .withOption(outputOpt).withOption(helpOpt).create(); try {/*from www.j a va2s . c om*/ Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption("help")) { CommandLineUtil.printHelp(group); return -1; } dataName = cmdLine.getValue(inputOpt).toString(); String datasetName = cmdLine.getValue(datasetOpt).toString(); String modelName = cmdLine.getValue(modelOpt).toString(); String outputName = cmdLine.hasOption(outputOpt) ? cmdLine.getValue(outputOpt).toString() : null; if (log.isDebugEnabled()) { log.debug("inout : {}", dataName); log.debug("dataset : {}", datasetName); log.debug("model : {}", modelName); log.debug("output : {}", outputName); } dataPath = new Path(dataName); datasetPath = new Path(datasetName); modelPath = new Path(modelName); if (outputName != null) { outputPath = new Path(outputName); } } catch (OptionException e) { log.warn(e.toString(), e); CommandLineUtil.printHelp(group); return -1; } time = System.currentTimeMillis(); testModel(); time = System.currentTimeMillis() - time; writeToFileClassifyTime(Chi_RWCSUtils.elapsedTime(time)); return 0; }
From source file:org.apache.mahout.classifier.df.tools.Frequencies.java
@Override public int run(String[] args) throws IOException, ClassNotFoundException, InterruptedException { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option dataOpt = obuilder.withLongName("data").withShortName("d").withRequired(true) .withArgument(abuilder.withName("path").withMinimum(1).withMaximum(1).create()) .withDescription("Data path").create(); Option datasetOpt = obuilder.withLongName("dataset").withShortName("ds").withRequired(true) .withArgument(abuilder.withName("path").withMinimum(1).create()).withDescription("dataset path") .create();/* w w w .j a v a2s . c o m*/ Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h") .create(); Group group = gbuilder.withName("Options").withOption(dataOpt).withOption(datasetOpt).withOption(helpOpt) .create(); try { Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelp(group); return 0; } String dataPath = cmdLine.getValue(dataOpt).toString(); String datasetPath = cmdLine.getValue(datasetOpt).toString(); log.debug("Data path : {}", dataPath); log.debug("Dataset path : {}", datasetPath); runTool(dataPath, datasetPath); } catch (OptionException e) { log.warn(e.toString(), e); CommandLineUtil.printHelp(group); } return 0; }
From source file:org.apache.mahout.classifier.df.tools.UDistrib.java
/** * Launch the uniform distribution tool. Requires the following command line arguments:<br> * /* w w w. j a va 2 s.c o m*/ * data : data path dataset : dataset path numpartitions : num partitions output : output path * * @throws java.io.IOException */ public static void main(String[] args) throws IOException { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option dataOpt = obuilder.withLongName("data").withShortName("d").withRequired(true) .withArgument(abuilder.withName("data").withMinimum(1).withMaximum(1).create()) .withDescription("Data path").create(); Option datasetOpt = obuilder.withLongName("dataset").withShortName("ds").withRequired(true) .withArgument(abuilder.withName("dataset").withMinimum(1).create()).withDescription("Dataset path") .create(); Option outputOpt = obuilder.withLongName("output").withShortName("o").withRequired(true) .withArgument(abuilder.withName("output").withMinimum(1).withMaximum(1).create()) .withDescription("Path to generated files").create(); Option partitionsOpt = obuilder.withLongName("numpartitions").withShortName("p").withRequired(true) .withArgument(abuilder.withName("numparts").withMinimum(1).withMinimum(1).create()) .withDescription("Number of partitions to create").create(); Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h") .create(); Group group = gbuilder.withName("Options").withOption(dataOpt).withOption(outputOpt).withOption(datasetOpt) .withOption(partitionsOpt).withOption(helpOpt).create(); try { Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelp(group); return; } String data = cmdLine.getValue(dataOpt).toString(); String dataset = cmdLine.getValue(datasetOpt).toString(); int numPartitions = Integer.parseInt(cmdLine.getValue(partitionsOpt).toString()); String output = cmdLine.getValue(outputOpt).toString(); runTool(data, dataset, output, numPartitions); } catch (OptionException e) { log.warn(e.toString(), e); CommandLineUtil.printHelp(group); } }
From source file:org.apache.mahout.df.tools.Describe.java
public static void main(String[] args) throws IOException, DescriptorException { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option pathOpt = obuilder.withLongName("path").withShortName("p").withRequired(true) .withArgument(abuilder.withName("path").withMinimum(1).withMaximum(1).create()) .withDescription("Data path").create(); Option descriptorOpt = obuilder.withLongName("descriptor").withShortName("d").withRequired(true) .withArgument(abuilder.withName("descriptor").withMinimum(1).create()) .withDescription("data descriptor").create(); Option descPathOpt = obuilder.withLongName("file").withShortName("f").withRequired(true) .withArgument(abuilder.withName("file").withMinimum(1).withMaximum(1).create()) .withDescription("Path to generated descriptor file").create(); Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h") .create();/* www . ja v a2 s. com*/ Group group = gbuilder.withName("Options").withOption(pathOpt).withOption(descPathOpt) .withOption(descriptorOpt).withOption(helpOpt).create(); try { Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelp(group); return; } String dataPath = cmdLine.getValue(pathOpt).toString(); String descPath = cmdLine.getValue(descPathOpt).toString(); List<String> descriptor = convert(cmdLine.getValues(descriptorOpt)); log.debug("Data path : {}", dataPath); log.debug("Descriptor path : {}", descPath); log.debug("Descriptor : {}", descriptor); runTool(dataPath, descriptor, descPath); } catch (OptionException e) { log.warn(e.toString()); CommandLineUtil.printHelp(group); } }