use of org.apache.commons.cli.Options in project opennms by OpenNMS.
the class SpectrumTrapImporter method configureArgs.
private void configureArgs(String[] argv) {
Options opts = new Options();
opts.addOption("d", "dir", true, "Directory where Spectrum custom events are located");
opts.addOption("t", "model-type-asset-field", true, "Name of asset field containing equivalent of Spectrum model type. Defaults to 'manufacturer'.");
opts.addOption("u", "base-uei", true, "Base value for UEI of generated OpenNMS events. Defaults to 'uei.opennms.org/import/Spectrum'.");
opts.addOption("f", "output-file", true, "File to which OpenNMS events will be written. Defaults to standard output.");
opts.addOption("k", "key", true, "Middle part of reduction- and clear-key, after UEI and before discriminators. Defaults to '%dpname%:%nodeid%:%interface%'.");
CommandLineParser parser = new GnuParser();
try {
CommandLine cmd = parser.parse(opts, argv);
if (cmd.hasOption('d')) {
m_customEventsDir = new FileSystemResource(cmd.getOptionValue('d'));
}
if (cmd.hasOption('t')) {
m_modelTypeAssetField = cmd.getOptionValue('t');
} else {
m_modelTypeAssetField = "manufacturer";
}
if (cmd.hasOption('u')) {
m_baseUei = cmd.getOptionValue('u');
} else {
m_baseUei = "uei.opennms.org/import/Spectrum";
}
if (cmd.hasOption('f')) {
m_outputWriter = new PrintWriter(new FileSystemResource(cmd.getOptionValue('f')).getFile());
} else {
m_outputWriter = new PrintWriter(System.out);
}
if (cmd.hasOption('k')) {
m_reductionKeyBody = cmd.getOptionValue('k');
} else {
m_reductionKeyBody = "%dpname%:%nodeid%:%interface%";
}
} catch (ParseException pe) {
printHelp("Failed to parse command line options");
System.exit(1);
} catch (FileNotFoundException fnfe) {
printHelp("Custom events input directory does not seem to exist");
}
}
use of org.apache.commons.cli.Options in project ProPPR by TeamCohen.
the class GradientFinder method main.
public static void main(String[] args) {
try {
int inputFiles = Configuration.USE_GROUNDED | Configuration.USE_INIT_PARAMS;
int outputFiles = Configuration.USE_GRADIENT | Configuration.USE_PARAMS;
int modules = Configuration.USE_TRAINER | Configuration.USE_SRW | Configuration.USE_SQUASHFUNCTION;
int constants = Configuration.USE_THREADS | Configuration.USE_EPOCHS | Configuration.USE_FORCE | Configuration.USE_FIXEDWEIGHTS;
CustomConfiguration c = new CustomConfiguration(args, inputFiles, outputFiles, constants, modules) {
boolean relax;
@Override
protected Option checkOption(Option o) {
if (PARAMS_FILE_OPTION.equals(o.getLongOpt()) || INIT_PARAMS_FILE_OPTION.equals(o.getLongOpt()))
o.setRequired(false);
return o;
}
@Override
protected void addCustomOptions(Options options, int[] flags) {
options.addOption(Option.builder().longOpt("relaxFW").desc("Relax fixedWeight rules for gradient computation (used in ProngHorn)").optionalArg(true).build());
}
@Override
protected void retrieveCustomSettings(CommandLine line, int[] flags, Options options) {
if (groundedFile == null || !groundedFile.exists())
usageOptions(options, flags, "Must specify grounded file using --" + Configuration.GROUNDED_FILE_OPTION);
if (gradientFile == null)
usageOptions(options, flags, "Must specify gradient using --" + Configuration.GRADIENT_FILE_OPTION);
// default to 0 epochs
if (!options.hasOption("epochs"))
this.epochs = 0;
this.relax = false;
if (options.hasOption("relaxFW"))
this.relax = true;
}
@Override
public Object getCustomSetting(String name) {
if ("relaxFW".equals(name))
return this.relax;
return null;
}
};
System.out.println(c.toString());
ParamVector<String, ?> params = null;
SymbolTable<String> masterFeatures = new SimpleSymbolTable<String>();
File featureIndex = new File(c.groundedFile.getParent(), c.groundedFile.getName() + Grounder.FEATURE_INDEX_EXTENSION);
if (featureIndex.exists()) {
log.info("Reading feature index from " + featureIndex.getName() + "...");
for (String line : new ParsedFile(featureIndex)) {
masterFeatures.insert(line.trim());
}
}
if (c.epochs > 0) {
// train first
log.info("Training for " + c.epochs + " epochs...");
params = c.trainer.train(masterFeatures, new ParsedFile(c.groundedFile), new ArrayLearningGraphBuilder(), // create a parameter vector
c.initParamsFile, c.epochs);
if (c.paramsFile != null)
ParamsFile.save(params, c.paramsFile, c);
} else if (c.initParamsFile != null) {
params = new SimpleParamVector<String>(Dictionary.load(new ParsedFile(c.initParamsFile)));
} else if (c.paramsFile != null) {
params = new SimpleParamVector<String>(Dictionary.load(new ParsedFile(c.paramsFile)));
} else {
params = new SimpleParamVector<String>();
}
// this lets prongHorn hold external features fixed for training, but still compute their gradient
if (((Boolean) c.getCustomSetting("relaxFW"))) {
log.info("Turning off fixedWeight rules");
c.trainer.setFixedWeightRules(new FixedWeightRules());
}
ParamVector<String, ?> batchGradient = c.trainer.findGradient(masterFeatures, new ParsedFile(c.groundedFile), new ArrayLearningGraphBuilder(), params);
ParamsFile.save(batchGradient, c.gradientFile, c);
} catch (Throwable t) {
t.printStackTrace();
System.exit(-1);
}
}
use of org.apache.commons.cli.Options in project ProPPR by TeamCohen.
the class PropertiesConfigurationTest method testProperties.
@Test
public void testProperties() throws ParseException {
Options options = new Options();
options.addOption(OptionBuilder.withLongOpt("force").withDescription("Ignore errors and run anyway").create());
DefaultParser parser = new DefaultParser();
Properties props = new Properties();
// props.put("--force", true);
props.setProperty("--force", "true");
CommandLine line = parser.parse(options, new String[0], props);
assertTrue(line.hasOption("force"));
}
use of org.apache.commons.cli.Options in project ProPPR by TeamCohen.
the class Configuration method missing.
public static void missing(int options, int[] flags) {
StringBuilder sb = new StringBuilder("Missing required option:\n");
switch(options) {
case USE_WAM:
sb.append("\tprogramFiles");
break;
default:
throw new UnsupportedOperationException("Bad programmer! Add handling to Configuration.missing for flag " + options);
}
Configuration c = new Configuration();
Options o = new Options();
c.addOptions(o, flags);
c.usageOptions(o, flags, sb.toString());
}
use of org.apache.commons.cli.Options in project zm-mailbox by Zimbra.
the class LdapUpgrade method getAllOptions.
private static Options getAllOptions() {
Options options = new Options();
options.addOption(O_HELP, "help", false, "print usage");
options.addOption(O_VERBOSE, "verbose", false, "be verbose");
options.addOption(O_BUG, "bug", true, "bug number this upgrade is for");
options.addOption(O_DESCRIBE, "desc", true, "describe this upgrade task");
options.addOption(O_DESCRIBE_ALL, "descAll", false, "describe all upgrade tasks");
return options;
}
Aggregations