use of org.apache.commons.cli.DefaultParser in project streamsx.health by IBMStreams.
the class HealthDataBeaconService method main.
public static void main(String[] args) throws Exception {
Option numPatientsOption = Option.builder("n").longOpt("num-patients").hasArg().argName("number of patients").required(false).build();
Option patientPrefixOption = Option.builder("p").longOpt("patient prefix").hasArg().argName("patient prefix").required(false).build();
Options options = new Options();
options.addOption(numPatientsOption);
options.addOption(patientPrefixOption);
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("help", options);
throw (e);
}
Map<String, Object> params = new HashMap<>();
if (cmd.hasOption("n")) {
params.put("num.patients", Integer.valueOf(cmd.getOptionValue("n")));
}
if (cmd.hasOption("p")) {
params.put("patient.prefix", cmd.getOptionValue("p"));
}
HealthDataBeaconService svc = new HealthDataBeaconService(System.getProperty("user.dir"));
svc.run(Type.DISTRIBUTED, params);
}
use of org.apache.commons.cli.DefaultParser in project streamsx.health by IBMStreams.
the class PatientsMonitoringDemo method main.
public static void main(String[] args) throws Exception {
String topics = "";
int numPatients = 20;
Options options = new Options();
Option contextTypeOption = Option.builder("t").required(false).hasArg(true).desc("Specify the Streams context type (BUNDLE, DISTRIBUTED, etc)").longOpt("type").build();
Option topicOption = Option.builder("i").required(true).hasArg(true).desc("Specify a list of topics the sample should also subscribe to. Topics are specified as comma-separated list.").longOpt("topic").build();
Option numPatientsOption = Option.builder("n").required(false).hasArg(true).desc("Specify number of patients to generate.").longOpt("num").build();
Option helpOption = Option.builder("h").longOpt("help").desc("Display help").build();
options.addOption(contextTypeOption);
options.addOption(topicOption);
options.addOption(numPatientsOption);
options.addOption(helpOption);
CommandLineParser parser = new DefaultParser();
CommandLine cmdLine = parser.parse(options, args);
if (cmdLine.hasOption("h")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("PatientsMonitoringDemo", options);
return;
}
if (cmdLine.hasOption("t")) {
String type = cmdLine.getOptionValue("t");
contextType = Type.valueOf(type.toUpperCase());
if (contextType == null) {
System.out.println("ERROR: Invalid contextType " + type);
}
}
if (cmdLine.hasOption("i")) {
topics = cmdLine.getOptionValue("i");
if (topics == null) {
System.out.println("ERROR: Invalid topics specified. Topics cannot be null.");
return;
} else if (topics.length() == 0) {
System.out.println("ERROR: Invalid topics specified. Topics cannot be empty.");
return;
}
}
if (cmdLine.hasOption("n")) {
String numPatientsStr = cmdLine.getOptionValue("n");
if (numPatientsStr != null) {
try {
numPatients = Integer.valueOf(numPatientsStr);
if (numPatients < 0) {
System.out.println("ERROR: Number of patients cannot be < 0.");
return;
}
} catch (Exception e) {
System.out.println("ERROR: Unable to convert number of patients to a number: " + numPatientsStr);
return;
}
}
}
// UI service
UIWrapperService uiService = new UIWrapperService();
// DataIngest service
if (numPatients > 0) {
Map<String, Object> beaconServiceParams = new HashMap<String, Object>();
beaconServiceParams.put("num.patients", numPatients);
beaconServiceParams.put("patient.prefix", "patient-");
HealthDataBeaconService beaconService = new HealthDataBeaconService("../../simulate/com.ibm.streamsx.health.simulate.beacon");
beaconService.run(contextType, beaconServiceParams);
}
// Manipulator service
PatientManipulatorService manService = new PatientManipulatorService(topics.split(","));
// Vitals Rules
VitalsRulesWrapperService vitalsService = new VitalsRulesWrapperService();
Map<String, Object> vitalsParams = new HashMap<String, Object>();
vitalsParams.put("ingestTopic", manService.getPublishedTopic());
uiService.run(contextType, new HashMap<>());
manService.run(contextType, new HashMap<>());
vitalsService.run(contextType, vitalsParams);
}
use of org.apache.commons.cli.DefaultParser in project jena by apache.
the class RuleMap method main.
/**
* General command line utility to process one RDF file into another
* by application of a set of forward chaining rules.
* <pre>
* Usage: RuleMap [-il inlang] [-ol outlang] -d infile rulefile
* </pre>
*/
public static void main(String[] args) {
try {
// Parse the command line
String usage = "Usage: RuleMap [-il inlang] [-ol outlang] [-d] rulefile infile (- for stdin)";
final CommandLineParser parser = new DefaultParser();
Options options = new Options().addOption("il", "inputLang", true, "input language").addOption("ol", "outputLang", true, "output language").addOption("d", "Deductions only?");
CommandLine cl = parser.parse(options, args);
final List<String> filenameArgs = cl.getArgList();
if (filenameArgs.size() != 2) {
System.err.println(usage);
System.exit(1);
}
String inLang = cl.getOptionValue("inputLang");
String fname = filenameArgs.get(1);
Model inModel = null;
if (fname.equals("-")) {
inModel = ModelFactory.createDefaultModel();
inModel.read(System.in, null, inLang);
} else {
inModel = FileManager.get().loadModel(fname, inLang);
}
String outLang = cl.hasOption("outputLang") ? cl.getOptionValue("outputLang") : "N3";
boolean deductionsOnly = cl.hasOption('d');
// Fetch the rule set and create the reasoner
BuiltinRegistry.theRegistry.register(new Deduce());
Map<String, String> prefixes = new HashMap<>();
List<Rule> rules = loadRules(filenameArgs.get(0), prefixes);
Reasoner reasoner = new GenericRuleReasoner(rules);
// Process
InfModel infModel = ModelFactory.createInfModel(reasoner, inModel);
infModel.prepare();
infModel.setNsPrefixes(prefixes);
// Output
try (PrintWriter writer = new PrintWriter(System.out)) {
if (deductionsOnly) {
Model deductions = infModel.getDeductionsModel();
deductions.setNsPrefixes(prefixes);
deductions.setNsPrefixes(inModel);
deductions.write(writer, outLang);
} else {
infModel.write(writer, outLang);
}
}
} catch (Throwable t) {
System.err.println("An error occured: \n" + t);
t.printStackTrace();
}
}
use of org.apache.commons.cli.DefaultParser in project groovy by apache.
the class Java2GroovyMain method main.
public static void main(String[] args) {
try {
Options options = new Options();
CommandLineParser cliParser = new DefaultParser();
CommandLine cli = cliParser.parse(options, args);
String[] filenames = cli.getArgs();
if (filenames.length == 0) {
System.err.println("Needs at least one filename");
}
Java2GroovyProcessor.processFiles(Arrays.asList(filenames));
} catch (Throwable t) {
t.printStackTrace();
}
}
use of org.apache.commons.cli.DefaultParser in project groovy by apache.
the class FileSystemCompiler method commandLineCompile.
/**
* Same as main(args) except that exceptions are thrown out instead of causing
* the VM to exit and the lookup for .groovy files can be controlled
*/
public static void commandLineCompile(String[] args, boolean lookupUnnamedFiles) throws Exception {
Options options = createCompilationOptions();
CommandLineParser cliParser = new DefaultParser();
CommandLine cli;
cli = cliParser.parse(options, args);
if (cli.hasOption('h')) {
displayHelp(options);
return;
}
if (cli.hasOption('v')) {
displayVersion();
return;
}
displayStackTraceOnError = cli.hasOption('e');
CompilerConfiguration configuration = generateCompilerConfigurationFromOptions(cli);
// Load the file name list
String[] filenames = generateFileNamesFromOptions(cli);
boolean fileNameErrors = filenames == null;
if (!fileNameErrors && (filenames.length == 0)) {
displayHelp(options);
return;
}
fileNameErrors = fileNameErrors && !validateFiles(filenames);
if (!fileNameErrors) {
doCompilation(configuration, null, filenames, lookupUnnamedFiles);
}
}
Aggregations