use of org.apache.commons.cli.GnuParser in project Cloud9 by lintool.
the class HadoopAlign method main.
@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException {
options = new Options();
options.addOption(OptionBuilder.withDescription("path to XML-formatted parallel corpus").withArgName("path").hasArg().isRequired().create(INPUT_OPTION));
options.addOption(OptionBuilder.withDescription("path to work/output directory on HDFS").withArgName("path").hasArg().isRequired().create(WORK_OPTION));
options.addOption(OptionBuilder.withDescription("two-letter collection language code").withArgName("en|de|fr|zh|es|ar|tr").hasArg().isRequired().create(FLANG_OPTION));
options.addOption(OptionBuilder.withDescription("two-letter collection language code").withArgName("en|de|fr|zh|es|ar|tr").hasArg().isRequired().create(ELANG_OPTION));
options.addOption(OptionBuilder.withDescription("number of IBM Model 1 iterations").withArgName("positive integer").hasArg().create(MODEL1_OPTION));
options.addOption(OptionBuilder.withDescription("number of HMM iterations").withArgName("positive integer").hasArg().create(HMM_OPTION));
options.addOption(OptionBuilder.withDescription("truncate/stem text or not").create(TRUNCATE_OPTION));
options.addOption(OptionBuilder.withDescription("number of reducers").withArgName("positive integer").hasArg().create(REDUCE_OPTION));
options.addOption(OptionBuilder.withDescription("Hadoop option to load external jars").withArgName("jar packages").hasArg().create(LIBJARS_OPTION));
CommandLine cmdline;
CommandLineParser parser = new GnuParser();
try {
cmdline = parser.parse(options, args);
} catch (ParseException exp) {
printUsage();
System.err.println("Error parsing command line: " + exp.getMessage());
return;
}
String bitextPath = cmdline.getOptionValue(INPUT_OPTION);
String workDir = cmdline.getOptionValue(WORK_OPTION);
String srcLang = cmdline.getOptionValue(FLANG_OPTION);
String trgLang = cmdline.getOptionValue(ELANG_OPTION);
int model1Iters = cmdline.hasOption(MODEL1_OPTION) ? Integer.parseInt(cmdline.getOptionValue(MODEL1_OPTION)) : 0;
int hmmIters = cmdline.hasOption(HMM_OPTION) ? Integer.parseInt(cmdline.getOptionValue(HMM_OPTION)) : 0;
if (model1Iters + hmmIters == 0) {
System.err.println("Please enter a positive number of iterations for either Model 1 or HMM");
printUsage();
return;
}
boolean isTruncate = cmdline.hasOption(TRUNCATE_OPTION) ? true : false;
int numReducers = cmdline.hasOption(REDUCE_OPTION) ? Integer.parseInt(cmdline.getOptionValue(REDUCE_OPTION)) : 50;
HadoopAlignConfig hac = new HadoopAlignConfig(workDir, trgLang, srcLang, bitextPath, model1Iters, hmmIters, // use null word
true, // use variational bayes
false, // use word truncation
isTruncate, // alpha
0.00f);
hac.setHMMHomogeneous(false);
hac.set("mapreduce.map.memory.mb", "2048");
hac.set("mapreduce.map.java.opts", "-Xmx2048m");
hac.set("mapreduce.reduce.memory.mb", "2048");
hac.set("mapreduce.reduce.java.opts", "-Xmx2048m");
hac.setHMMp0(0.2);
hac.setMaxSentLen(15);
doAlignment(50, numReducers, hac);
}
use of org.apache.commons.cli.GnuParser in project Cloud9 by lintool.
the class FileMerger method run.
@Override
public /**
* TODO: add in hadoop configuration
*/
int run(String[] args) throws IOException {
Options options = new Options();
options.addOption(HELP_OPTION, false, "print the help message");
options.addOption(OptionBuilder.withArgName(PATH_INDICATOR).hasArg().withDescription("input file or directory").create(INPUT_OPTION));
options.addOption(OptionBuilder.withArgName(PATH_INDICATOR).hasArg().withDescription("output file").create(OUTPUT_OPTION));
options.addOption(OptionBuilder.withArgName(INTEGER_INDICATOR).hasArg().withDescription("number of mappers (default to 0 and hence local merge mode, set to positive value to enable cluster merge mode)").create(MAPPER_OPTION));
options.addOption(OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator().withDescription("assign value for given property").create("D"));
options.addOption(TEXT_FILE_INPUT_FORMAT, false, "input file in sequence format");
options.addOption(DELETE_SOURCE_OPTION, false, "delete sources after merging");
int mapperTasks = 0;
boolean deleteSource = DELETE_SOURCE;
boolean textFileFormat = TEXT_FILE_INPUT;
String inputPath = "";
String outputPath = "";
GenericOptionsParser genericOptionsParser = new GenericOptionsParser(args);
Configuration configuration = genericOptionsParser.getConfiguration();
CommandLineParser parser = new GnuParser();
HelpFormatter formatter = new HelpFormatter();
try {
CommandLine line = parser.parse(options, args);
if (line.hasOption(HELP_OPTION)) {
formatter.printHelp(FileMerger.class.getName(), options);
System.exit(0);
}
if (line.hasOption(INPUT_OPTION)) {
inputPath = line.getOptionValue(INPUT_OPTION);
} else {
throw new ParseException("Parsing failed due to " + INPUT_OPTION + " not initialized...");
}
if (line.hasOption(OUTPUT_OPTION)) {
outputPath = line.getOptionValue(OUTPUT_OPTION);
} else {
throw new ParseException("Parsing failed due to " + OUTPUT_OPTION + " not initialized...");
}
if (line.hasOption(MAPPER_OPTION)) {
mapperTasks = Integer.parseInt(line.getOptionValue(MAPPER_OPTION));
if (mapperTasks <= 0) {
sLogger.info("Warning: " + MAPPER_OPTION + " is not positive, merge in local model...");
mapperTasks = 0;
}
}
if (line.hasOption(DELETE_SOURCE_OPTION)) {
deleteSource = true;
}
if (line.hasOption(TEXT_FILE_INPUT_FORMAT)) {
textFileFormat = true;
}
} catch (ParseException pe) {
System.err.println(pe.getMessage());
formatter.printHelp(FileMerger.class.getName(), options);
System.exit(0);
} catch (NumberFormatException nfe) {
System.err.println(nfe.getMessage());
System.exit(0);
}
try {
merge(configuration, inputPath, outputPath, mapperTasks, textFileFormat, deleteSource);
} catch (InstantiationException ie) {
ie.printStackTrace();
} catch (IllegalAccessException iae) {
iae.printStackTrace();
}
return 0;
}
use of org.apache.commons.cli.GnuParser in project saga by timurstrekalov.
the class Main method main.
public static void main(final String[] args) throws IOException, ParseException {
logger.debug("Starting...");
final Option baseDirOpt = new Option("b", "base-dir", true, "Base directory for test search");
final Option includeOpt = new Option("i", "include", true, "Comma-separated list of Ant-style paths to the tests to run");
final Option excludeOpt = new Option("e", "exclude", true, "Comma-separated list of Ant-style paths to the tests to exclude from run");
final Option outputDirOpt = new Option("o", "output-dir", true, "The output directory for coverage reports");
final Option outputInstrumentedFilesOpt = new Option("f", "output-instrumented-files", false, "Whether to output instrumented files (default is false)");
final Option noInstrumentPatternOpt = new Option("n", "no-instrument-pattern", true, "Regular expression patterns to match classes to exclude from instrumentation");
noInstrumentPatternOpt.setArgs(Option.UNLIMITED_VALUES);
final Option sourcesToPreloadOpt = new Option("p", "preload-sources", true, "Comma-separated list of Ant-style paths to files to preload");
final Option sourcesToPreloadEncodingOpt = new Option(null, "preload-sources-encoding", true, "Encoding to use when preloading sources");
final Option threadCountOpt = new Option("t", "thread-count", true, "The maximum number of threads to use (defaults to the number of cores)");
final Option outputStrategyOpt = new Option("s", "output-strategy", true, "Coverage report output strategy. One of " + Arrays.toString(OutputStrategy.values()));
final Option includeInlineScriptsOpt = new Option("d", "include-inline-scripts", false, "Whether to include inline scripts into instrumentation by default (default is false)");
final Option backgroundJavaScriptTimeoutOpt = new Option("j", "background-javascript-timeout", true, "How long to wait for background JavaScript to finish running (in milliseconds, default is 5 minutes)");
final Option browserVersionOpt = new Option("v", "browser-version", true, "Determines the browser and version profile that HtmlUnit will simulate");
final Option reportFormatsOpt = new Option(null, "report-formats", true, "A comma-separated list of formats of the reports to be generated. Valid values are: HTML, RAW, CSV, PDF");
final Option sortByOpt = new Option(null, "sort-by", true, "The column to sort by, one of 'file', 'statements', 'executed' or 'coverage' (default is 'coverage')");
final Option orderOpt = new Option(null, "order", true, "The order of sorting, one of 'asc' or 'ascending', 'desc' or 'descending' (default is 'ascending')");
final Option helpOpt = new Option("h", "help", false, "Print this message");
final Options options = new Options();
options.addOption(baseDirOpt);
options.addOption(includeOpt);
options.addOption(excludeOpt);
options.addOption(outputDirOpt);
options.addOption(outputInstrumentedFilesOpt);
options.addOption(noInstrumentPatternOpt);
options.addOption(threadCountOpt);
options.addOption(outputStrategyOpt);
options.addOption(includeInlineScriptsOpt);
options.addOption(helpOpt);
options.addOption(sourcesToPreloadOpt);
options.addOption(sourcesToPreloadEncodingOpt);
options.addOption(backgroundJavaScriptTimeoutOpt);
options.addOption(browserVersionOpt);
options.addOption(reportFormatsOpt);
options.addOption(sortByOpt);
options.addOption(orderOpt);
logger.debug("Finished configuring options");
try {
CommandLineParser parser = new GnuParser();
CommandLine line = parser.parse(options, args, false);
logger.debug("Parsed the arguments, take 1");
baseDirOpt.setRequired(true);
outputDirOpt.setRequired(true);
options.addOption(baseDirOpt);
options.addOption(outputDirOpt);
if (line.hasOption(helpOpt.getLongOpt())) {
printHelpAndExit(options);
}
parser = new GnuParser();
line = parser.parse(options, args);
logger.debug("Parsed the arguments, take 2");
final String baseDir = line.getOptionValue(baseDirOpt.getLongOpt());
final String includes = line.getOptionValue(includeOpt.getLongOpt());
final String excludes = line.getOptionValue(excludeOpt.getLongOpt());
final File outputDir = new File(line.getOptionValue(outputDirOpt.getLongOpt()));
final CoverageGenerator gen = CoverageGeneratorFactory.newInstance(baseDir, outputDir);
final Config config = gen.getConfig();
config.setIncludes(includes);
config.setExcludes(excludes);
if (line.hasOption(outputInstrumentedFilesOpt.getLongOpt())) {
config.setOutputInstrumentedFiles(true);
}
config.setNoInstrumentPatterns(line.getOptionValues(noInstrumentPatternOpt.getLongOpt()));
config.setSourcesToPreload(line.getOptionValue(sourcesToPreloadOpt.getLongOpt()));
config.setOutputStrategy(line.getOptionValue(outputStrategyOpt.getLongOpt()));
final String threadCount = line.getOptionValue(threadCountOpt.getLongOpt());
if (threadCount != null) {
try {
config.setThreadCount(Integer.parseInt(threadCount));
} catch (final Exception e) {
System.err.println("Invalid thread count");
printHelpAndExit(options);
}
}
if (line.hasOption(includeInlineScriptsOpt.getLongOpt())) {
config.setIncludeInlineScripts(true);
}
final String backgroundJavaScriptTimeout = line.getOptionValue(backgroundJavaScriptTimeoutOpt.getLongOpt());
if (backgroundJavaScriptTimeout != null) {
try {
config.setBackgroundJavaScriptTimeout(Long.valueOf(backgroundJavaScriptTimeout));
} catch (final Exception e) {
System.err.println("Invalid timeout");
printHelpAndExit(options);
}
}
config.setBrowserVersion(line.getOptionValue(browserVersionOpt.getLongOpt()));
config.setReportFormats(line.getOptionValue(reportFormatsOpt.getLongOpt()));
config.setSortBy(line.getOptionValue(sortByOpt.getLongOpt()));
config.setOrder(line.getOptionValue(orderOpt.getLongOpt()));
logger.debug("Configured the coverage generator, running");
gen.instrumentAndGenerateReports();
} catch (final MissingOptionException e) {
System.err.println(e.getMessage());
printHelpAndExit(options);
} catch (final UnrecognizedOptionException e) {
System.err.println(e.getMessage());
printHelpAndExit(options);
} catch (final ParseException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of org.apache.commons.cli.GnuParser in project mysql_perf_analyzer by yahoo.
the class App method main.
/* -p --port 9090
* -r --webcontextroot webapps
* -l --logpath logpath
* -w --war webapp war file name
*/
public static void main(String[] args) throws Exception {
App myServer = new App();
CommandLineParser parser = new GnuParser();
Options options = getAvaliableCommandLineOptions();
System.out.println(new Date() + " Usage: java -classpath ... com.yahoo.dba.tools.myperfserver.App -j jettyhome " + "-p port -c webcontextroot -k workingDir -l logpath -w war_file");
readOptionsFromCommandLine(args, parser, options, myServer);
System.setProperty("logPath", myServer.getLogDirectoryPath());
PID_FILE = myServer.getWarFile().substring(0, myServer.getWarFile().indexOf('.')) + ".pid";
checksRunningOfAnotherServerInstance();
runServer(myServer);
}
use of org.apache.commons.cli.GnuParser in project midpoint by Evolveum.
the class AbstractWebServiceClient method parseCommandLine.
private void parseCommandLine(String[] args) throws ParseException {
CommandLineParser cliParser = new GnuParser();
commandLine = cliParser.parse(options, args, true);
if (commandLine.hasOption('h')) {
printHelp();
System.exit(0);
}
if (commandLine.hasOption('v')) {
verbose = true;
}
}
Aggregations