List of usage examples for org.apache.commons.cli ParseException getMessage
public String getMessage()
From source file:edu.uiowa.javatm.JavaTM.java
/** * @param args First one indicates which topic model to use *//*w w w. java 2s.c o m*/ public static void main(String[] args) { TMGibbsSampler tmGibbsSampler = null; Option modelType = Option.builder("model").longOpt("model-type").desc("Type of topic models to use") .hasArg().required().build(); Option dataName = Option.builder("name").longOpt("data-name").desc("Data name: used for saving outputs") .hasArg().required().build(); Option alpha = Option.builder("a").longOpt("alpha") .desc("Dirichlet prior for document (author) over topic multinomial").hasArg().required().build(); Option beta = Option.builder("b").longOpt("beta").desc("Dirichlet prior for topic over word multinomial") .hasArg().required().build(); Option pi = Option.builder("p").longOpt("pi").desc("Dirichlet prior for topic over time multinomial") .hasArg().build(); Option K = Option.builder("K").longOpt("K").desc("The number of timestamp indices").hasArg().build(); /*Option tau = Option.builder("tau").longOpt("tau") .desc("Smoothing constant for topic time") .hasArg().build();*/ Option doc = Option.builder("doc").longOpt("document-file").desc("WD matrix to use").hasArg().required() .build(); Option voc = Option.builder("voc").longOpt("vocabulary-file") .desc("Vocabulary file of the corpus of interest").hasArg().required().build(); Option auth = Option.builder("auth").longOpt("auth-file").desc("Author indices for each token").hasArg() .build(); Option authArray = Option.builder("authArray").longOpt("author-list-file").desc("Author list").hasArg() .build(); Option dkArray = Option.builder("dk").longOpt("document-time-file").desc("Document timestamp file").hasArg() .build(); Option citationMat = Option.builder("cm").longOpt("citation-matrix") .desc("Citation overtime for the corpus").hasArg().build(); Option numTopics = Option.builder("topic").longOpt("num-topics").desc("The total number of topics").hasArg() .required().build(); Option numIters = Option.builder("iter").longOpt("num-iters").desc("The total number of iterations") .hasArg().required().build(); Option outputDir = Option.builder("odir").longOpt("output-dir").desc("Output directory").hasArg().required() .build(); Options options = new Options(); options.addOption(modelType).addOption(alpha).addOption(beta).addOption(numTopics).addOption(K) .addOption(pi).addOption(citationMat).addOption(numIters).addOption(doc).addOption(voc) .addOption(dkArray).addOption(outputDir).addOption(auth).addOption(authArray).addOption(dataName); CommandLineParser parser = new DefaultParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); String model = line.getOptionValue("model"); String name = line.getOptionValue("name"); String docFile = line.getOptionValue("doc"); String vocFile = line.getOptionValue("voc"); int topics = Integer.parseInt(line.getOptionValue("topic")); int iters = Integer.parseInt(line.getOptionValue("iter")); double a = Double.parseDouble(line.getOptionValue("a")); double b = Double.parseDouble(line.getOptionValue("b")); String modelLower = model.toLowerCase(); if (modelLower.equals("lda")) { tmGibbsSampler = new LDAGibbsSampler(topics, iters, a, b, docFile, vocFile); } else if (modelLower.equals("at")) { String authFile = line.getOptionValue("auth"); String authArrayFile = line.getOptionValue("authArray"); //double tau_val = Double.parseDouble(line.getOptionValue("tau")); tmGibbsSampler = new ATGibbsSampler(topics, iters, a, b, docFile, vocFile, authFile, authArrayFile); } else if (modelLower.equals("tot")) { String dkFile = line.getOptionValue("dk"); //double tau_val = Double.parseDouble(line.getOptionValue("tau")); tmGibbsSampler = new ToTGibbsSampler(topics, iters, a, b, docFile, vocFile, dkFile); } else if (modelLower.equals("tiot")) { String timeFile = line.getOptionValue("dk"); String citationFile = line.getOptionValue("cm"); double p = Double.parseDouble(line.getOptionValue("p")); //int k = Integer.parseInt(line.getOptionValue("K")); tmGibbsSampler = new TIOTGibbsSampler(topics, iters, a, b, p, docFile, vocFile, timeFile, citationFile); } else { System.err.println("Invalid model type selection. Must be lda, at, tot or atot."); System.exit(ExitStatus.ILLEGAL_ARGUMENT); } long startTime = System.nanoTime(); tmGibbsSampler.fit(); TMOutcome outcome = tmGibbsSampler.get_outcome(); long endTime = System.nanoTime(); long duration = (endTime - startTime); System.out.println("Overall elapsed time: " + duration / 1000000000. + " seconds"); tmGibbsSampler.showTopics(10); outcome.showTopicDistribution(); String oDir = line.getOptionValue("odir"); if (!oDir.endsWith("/")) { oDir = oDir + "/"; } // append name to `oDir` oDir = oDir + name + "-"; if (modelLower.contains("tot")) { // topic over time (tot and atot) has beta distribution parameters to write Utils.write2DArray(((ToTOutcome) outcome).getPsi(), oDir + "psi-" + modelLower + ".csv"); } if (modelLower.contains("tiot")) { // topic over time (tot and atot) has beta distribution parameters to write Utils.write2DArray(((TIOTOutcome) outcome).getPsi(), oDir + "psi-" + modelLower + ".csv"); double[][][] ga = ((TIOTOutcome) outcome).getGa(); for (int t = 0; t < ga.length; t++) { Utils.write2DArray(ga[t], oDir + "gamma-" + t + "-" + modelLower + ".csv"); } } Utils.write2DArray(outcome.getPhi(), oDir + "phi-" + modelLower + ".csv"); Utils.write2DArray(outcome.getTheta(), oDir + "theta-" + modelLower + ".csv"); System.out.println("Output files saved to " + oDir); } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); } }
From source file:SearchApiExample.java
/** * @param args//w w w. j a v a 2 s. c om */ public static void main(String[] args) { Options options = buildOptions(); try { CommandLine line = new BasicParser().parse(options, args); processCommandLine(line, options); } catch (ParseException exp) { System.err.println(exp.getMessage()); printHelp(options); } }
From source file:ch.psi.zmq.receiver.FileReceiver.java
public static void main(String[] args) { int port = 8888; String source = "localhost"; Options options = new Options(); options.addOption("h", false, "Help"); @SuppressWarnings("static-access") Option optionP = OptionBuilder.withArgName("port").hasArg() .withDescription("Source port (default: " + port + ")").create("p"); options.addOption(optionP);// w ww. j a v a 2 s. c o m @SuppressWarnings("static-access") Option optionS = OptionBuilder.withArgName("source").hasArg().isRequired().withDescription( "Source address of the ZMQ stream (default port " + port + " : use -p to set the port if needed)") .create("s"); options.addOption(optionS); @SuppressWarnings("static-access") Option optionD = OptionBuilder.withArgName("path").hasArg().isRequired() .withDescription("tpath for storing files with relative destination paths").create("d"); options.addOption(optionD); GnuParser parser = new GnuParser(); CommandLine line; String path = "."; try { line = parser.parse(options, args); if (line.hasOption(optionP.getOpt())) { port = Integer.parseInt(line.getOptionValue(optionP.getOpt())); } if (line.hasOption("h")) { HelpFormatter f = new HelpFormatter(); f.printHelp("receiver", options); return; } source = line.getOptionValue(optionS.getOpt()); path = line.getOptionValue(optionD.getOpt()); } catch (ParseException e) { System.err.println(e.getMessage()); HelpFormatter f = new HelpFormatter(); f.printHelp("receiver", options); System.exit(-1); } final FileReceiver r = new FileReceiver(source, port, path); r.receive(); // Control+C Signal.handle(new Signal("INT"), new SignalHandler() { int count = 0; public void handle(Signal sig) { if (count < 1) { count++; r.terminate(); } else { System.exit(-1); } } }); }
From source file:com.act.reachables.CladeTraversal.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());/*from w w w. ja v a 2s. c o m*/ } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(CladeTraversal.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(CladeTraversal.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } String targetInchi = cl.getOptionValue(OPTION_TARGET_INCHI, PABA_INCHI); String inchiFileName = cl.getOptionValue(OPTION_OUTPUT_INCHI_FILE_NAME, DEFAULT_INCHI_FILE); String reactionsFileName = cl.getOptionValue(OPTION_OUTPUT_REACTION_FILE_NAME, DEFAULT_REACTIONS_FILE); String reactionDirectory = cl.getOptionValue(OPTION_OUTPUT_FAILED_REACTIONS_DIR_NAME, "/"); String actDataFile = cl.getOptionValue(OPTION_ACT_DATA_FILE, DEFAULT_ACTDATA_FILE); runCladeExpansion(actDataFile, targetInchi, inchiFileName, reactionsFileName, reactionDirectory); }
From source file:com.rabbitmq.perf.PerfTest.java
public static void main(String[] args) { Options options = getOptions();/*w w w.j a va 2 s. c o m*/ CommandLineParser parser = new GnuParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('?')) { usage(options); System.exit(0); } String testID = new SimpleDateFormat("HHmmss-SSS").format(Calendar.getInstance().getTime()); testID = strArg(cmd, 'd', "test-" + testID); String exchangeType = strArg(cmd, 't', "direct"); String exchangeName = strArg(cmd, 'e', exchangeType); String queueNames = strArg(cmd, 'u', ""); String routingKey = strArg(cmd, 'k', null); boolean randomRoutingKey = cmd.hasOption('K'); int samplingInterval = intArg(cmd, 'i', 1); float producerRateLimit = floatArg(cmd, 'r', 0.0f); float consumerRateLimit = floatArg(cmd, 'R', 0.0f); int producerCount = intArg(cmd, 'x', 1); int consumerCount = intArg(cmd, 'y', 1); int producerTxSize = intArg(cmd, 'm', 0); int consumerTxSize = intArg(cmd, 'n', 0); long confirm = intArg(cmd, 'c', -1); boolean autoAck = cmd.hasOption('a'); int multiAckEvery = intArg(cmd, 'A', 0); int channelPrefetch = intArg(cmd, 'Q', 0); int consumerPrefetch = intArg(cmd, 'q', 0); int minMsgSize = intArg(cmd, 's', 0); int timeLimit = intArg(cmd, 'z', 0); int producerMsgCount = intArg(cmd, 'C', 0); int consumerMsgCount = intArg(cmd, 'D', 0); List<?> flags = lstArg(cmd, 'f'); int frameMax = intArg(cmd, 'M', 0); int heartbeat = intArg(cmd, 'b', 0); boolean predeclared = cmd.hasOption('p'); String uri = strArg(cmd, 'h', "amqp://localhost"); //setup PrintlnStats stats = new PrintlnStats(testID, 1000L * samplingInterval, producerCount > 0, consumerCount > 0, (flags.contains("mandatory") || flags.contains("immediate")), confirm != -1); ConnectionFactory factory = new ConnectionFactory(); factory.setShutdownTimeout(0); // So we still shut down even with slow consumers factory.setUri(uri); factory.setRequestedFrameMax(frameMax); factory.setRequestedHeartbeat(heartbeat); MulticastParams p = new MulticastParams(); p.setAutoAck(autoAck); p.setAutoDelete(true); p.setConfirm(confirm); p.setConsumerCount(consumerCount); p.setConsumerMsgCount(consumerMsgCount); p.setConsumerRateLimit(consumerRateLimit); p.setConsumerTxSize(consumerTxSize); p.setExchangeName(exchangeName); p.setExchangeType(exchangeType); p.setFlags(flags); p.setMultiAckEvery(multiAckEvery); p.setMinMsgSize(minMsgSize); p.setPredeclared(predeclared); p.setConsumerPrefetch(consumerPrefetch); p.setChannelPrefetch(channelPrefetch); p.setProducerCount(producerCount); p.setProducerMsgCount(producerMsgCount); p.setProducerTxSize(producerTxSize); p.setQueueNames(Arrays.asList(queueNames.split(","))); p.setRoutingKey(routingKey); p.setRandomRoutingKey(randomRoutingKey); p.setProducerRateLimit(producerRateLimit); p.setTimeLimit(timeLimit); MulticastSet set = new MulticastSet(stats, factory, p, testID); set.run(true); stats.printFinal(); } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); usage(options); } catch (Exception e) { System.err.println("Main thread caught exception: " + e); e.printStackTrace(); System.exit(1); } }
From source file:name.wagners.bpp.Bpp.java
public static void main(final String[] args) { // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); options.addOption(OptionBuilder.hasArg().withArgName("int").withLongOpt("generations") .withDescription("Number of generations [default: 50]").create("g")); options.addOption(OptionBuilder.hasArg().withArgName("int").withLongOpt("mutrate") .withDescription("Mutation rate [default: 1]").create()); options.addOption(OptionBuilder.hasArg().withArgName("double").withLongOpt("mutprop") .withDescription("Mutation propability [default: 0.5]").create()); options.addOption(OptionBuilder.hasArg().withArgName("int").withLongOpt("populationsize") .withDescription("Size of population [default: 20]").create()); options.addOption(OptionBuilder.hasArg().withArgName("a|b").withLongOpt("recombalg") .withDescription("Recombination algorithm [default: a]").create()); // options.addOption(OptionBuilder // .hasArg()//from w w w .j av a 2s.c om // .withArgName("int") // .withLongOpt("recombrate") // .withDescription("Recombination rate [default: 1]") // .create()); options.addOption(OptionBuilder.hasArg().withArgName("double").withLongOpt("recombprop") .withDescription("Recombination propability [default: 0.8]").create()); options.addOption(OptionBuilder.hasArg().withArgName("a").withLongOpt("selalg") .withDescription("Selection algorithm [default: a]").create()); options.addOption(OptionBuilder.hasArg().withArgName("int").withLongOpt("selectionpressure") .withDescription("Selection pressure [default: 4]").create()); options.addOption(OptionBuilder.hasArg().withArgName("bool").withLongOpt("elitism") .withDescription("Enable Elitism [default: 1]").create("e")); options.addOption(OptionBuilder.hasArg().withArgName("filename") // .isRequired() .withLongOpt("datafile").withDescription("Problem data file [default: \"binpack.txt\"]") .create("f")); options.addOptionGroup(new OptionGroup() .addOption(OptionBuilder.withLongOpt("verbose").withDescription("be extra verbose").create("v")) .addOption(OptionBuilder.withLongOpt("quiet").withDescription("be extra quiet").create("q"))); options.addOption(OptionBuilder.withLongOpt("version") .withDescription("print the version information and exit").create("V")); options.addOption(OptionBuilder.withLongOpt("help").withDescription("print this message").create("h")); try { // parse the command line arguments CommandLine line = parser.parse(options, args); // validate that block-size has been set if (line.hasOption("help")) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Bpp", options); System.exit(0); } if (line.hasOption("version")) { log.info("Bpp 0.1 (c) 2007 by Daniel Wagner"); } if (line.hasOption("datafile")) { fname = line.getOptionValue("datafile"); } if (line.hasOption("elitism")) { elitism = Boolean.parseBoolean(line.getOptionValue("elitism")); } if (line.hasOption("generations")) { gen = Integer.parseInt(line.getOptionValue("generations")); } if (line.hasOption("mutprop")) { mp = Double.parseDouble(line.getOptionValue("mutprop")); } if (line.hasOption("mutrate")) { mr = Integer.parseInt(line.getOptionValue("mutrate")); } if (line.hasOption("populationsize")) { ps = Integer.parseInt(line.getOptionValue("populationsize")); } if (line.hasOption("recombalg")) { sel = line.getOptionValue("recombalg").charAt(0); } if (line.hasOption("recombprop")) { rp = Double.parseDouble(line.getOptionValue("recombprop")); } if (line.hasOption("selalg")) { selalg = line.getOptionValue("selalg").charAt(0); } if (line.hasOption("selectionpressure")) { sp = Integer.parseInt(line.getOptionValue("selectionpressure")); } } catch (ParseException exp) { log.info("Unexpected exception:" + exp.getMessage(), exp); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Bpp", options); System.exit(1); } // Ausgabe der eingestellten Optionen log.info("Configuration"); log.info(" Datafile: " + fname); log.info(" Generations: " + gen); log.info(" Population size: " + ps); log.info(" Elitism: " + elitism); log.info(" Mutation propapility: " + mp); log.info(" Mutation rate: " + mr); log.info(" Recombination algorithm " + (char) sel); log.info(" Recombination propapility: " + rp); log.info(" Selection pressure: " + sp); // Daten laden instance = new Instance(); instance.load(fname); Evolutionizer e = new Evolutionizer(instance); e.run(); }
From source file:es.eucm.ead.exporter.ExporterMain.java
@SuppressWarnings("all") public static void main(String args[]) { Options options = new Options(); Option help = new Option("h", "help", false, "print this message"); Option quiet = new Option("q", "quiet", false, "be extra quiet"); Option verbose = new Option("v", "verbose", false, "be extra verbose"); Option legacy = OptionBuilder.withArgName("s> <t").hasArgs(3) .withDescription(/*from www.java 2 s . c om*/ "source is a version 1.x game; must specify\n" + "<simplify> if 'true', simplifies result\n" + "<translate> if 'true', enables translation") .withLongOpt("import").create("i"); Option war = OptionBuilder.withArgName("web-base").hasArg() .withDescription("WAR packaging (web app); " + "must specify\n<web-base> the base WAR directory") .withLongOpt("war").create("w"); Option jar = OptionBuilder.withDescription("JAR packaging (desktop)").withLongOpt("jar").create("j"); Option apk = OptionBuilder.withArgName("props> <adk> <d").hasArgs(3) .withDescription("APK packaging (android); must specify \n" + "<props> (a properties file) \n" + "<adk> (location of the ADK to use) \n" + "<deploy> ('true' to install & deploy)") .withLongOpt("apk").create("a"); // EAD option Option ead = OptionBuilder.withDescription("EAD packaging (eAdventure)").withLongOpt("ead").create("e"); options.addOption(legacy); options.addOption(help); options.addOption(quiet); options.addOption(verbose); options.addOption(jar); options.addOption(war); options.addOption(apk); options.addOption(ead); CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException pe) { System.err.println("Error parsing command-line: " + pe.getMessage()); showHelp(options); return; } // general options String[] extras = cmd.getArgs(); if (cmd.hasOption(help.getOpt()) || extras.length < 2) { showHelp(options); return; } if (cmd.hasOption(verbose.getOpt())) { verbosity = Verbose; } if (cmd.hasOption(quiet.getOpt())) { verbosity = Quiet; } // import String source = extras[0]; // optional import step if (cmd.hasOption(legacy.getOpt())) { String[] values = cmd.getOptionValues(legacy.getOpt()); AdventureConverter converter = new AdventureConverter(); if (values.length > 0 && values[0].equalsIgnoreCase("true")) { converter.setEnableSimplifications(true); } if (values.length > 1 && values[1].equalsIgnoreCase("true")) { converter.setEnableTranslations(true); } // set source for next steps to import-target source = converter.convert(source, null); } if (cmd.hasOption(jar.getOpt())) { if (checkFilesExist(cmd, options, source)) { JarExporter e = new JarExporter(); e.export(source, extras[1], verbosity.equals(Quiet) ? new QuietStream() : System.err); } } else if (cmd.hasOption(apk.getOpt())) { String[] values = cmd.getOptionValues(apk.getOpt()); if (checkFilesExist(cmd, options, values[0], values[1], source)) { AndroidExporter e = new AndroidExporter(); Properties props = new Properties(); File propsFile = new File(values[0]); try { props.load(new FileReader(propsFile)); props.setProperty(AndroidExporter.SDK_HOME, props.getProperty(AndroidExporter.SDK_HOME, values[1])); } catch (IOException ioe) { System.err.println("Could not load properties from " + propsFile.getAbsolutePath()); return; } e.export(source, extras[1], props, values.length > 2 && values[2].equalsIgnoreCase("true")); } } else if (cmd.hasOption(war.getOpt())) { if (checkFilesExist(cmd, options, extras[0])) { WarExporter e = new WarExporter(); e.setWarPath(cmd.getOptionValue(war.getOpt())); e.export(source, extras[1]); } } else if (cmd.hasOption(ead.getOpt())) { String destiny = extras[1]; if (!destiny.endsWith(".ead")) { destiny += ".ead"; } FileUtils.zip(new File(destiny), new File(source)); } else { showHelp(options); } }
From source file:com.blackducksoftware.integration.hubdiff.HubDiff.java
public static void main(String[] args) throws IOException, IllegalArgumentException, EncryptionException, HubIntegrationException, JSONException { Options options = new Options(); Option optUrl1 = new Option("h1", "hub-url-1", true, "the base url to the hub. Example: http://int-hub01.dc1.lan:8080"); Option optUsername1 = new Option("u1", "username-1", true, "the username for your hub instance"); Option optPassword1 = new Option("p1", "password-1", true, "the password for your hub instance and username"); Option optUrl2 = new Option("h2", "hub-url-2", true, "the base url to the hub. Example: http://int-auto.dc1.lan:9000"); Option optUsername2 = new Option("u2", "username-2", true, "the username for your hub instance"); Option optPassword2 = new Option("p2", "password-2", true, "the password for your hub instance and username"); Option optOutputFile = new Option("o", "output", true, "the file path to your output file"); optUrl1.setRequired(true);// w ww .j a va 2 s. com optUsername1.setRequired(true); optPassword1.setRequired(true); optUsername2.setRequired(true); optUrl1.setRequired(true); optPassword2.setRequired(true); optOutputFile.setRequired(false); // Add options to collection options.addOption(optUrl1); options.addOption(optUsername1); options.addOption(optPassword1); options.addOption(optUrl2); options.addOption(optUsername2); options.addOption(optPassword2); options.addOption(optOutputFile); // Parse the arguments array for the options CommandLineParser cliParser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine optionParser; try { optionParser = cliParser.parse(options, args); } catch (ParseException e) { formatter.printHelp("hub-model-generator", options); log.error(e.getMessage()); System.exit(1); return; } // Read arguments String url1 = optionParser.getOptionValue("hub-url-1"); String username1 = optionParser.getOptionValue("username-1"); String password1 = optionParser.getOptionValue("password-1"); String url2 = optionParser.getOptionValue("hub-url-2"); String username2 = optionParser.getOptionValue("username-2"); String password2 = optionParser.getOptionValue("password-2"); String outputFilePath = optionParser.getOptionValue("output"); HubServerConfigBuilder configBuilder = new HubServerConfigBuilder(); configBuilder.setHubUrl(url1); configBuilder.setUsername(username1); configBuilder.setPassword(password1); HubServerConfig config1 = configBuilder.build(); HubServerConfigBuilder configBuilder2 = new HubServerConfigBuilder(); configBuilder2.setHubUrl(url2); configBuilder2.setUsername(username2); configBuilder2.setPassword(password2); HubServerConfig config2 = configBuilder2.build(); HubDiff hubDiff = new HubDiff(config1, config2); hubDiff.printDiff(System.out); if (outputFilePath != null) { File outputFile = new File(outputFilePath); hubDiff.writeDiffAsCSV(outputFile); } }
From source file:com.act.biointerpretation.l2expansion.L2FilteringDriver.java
public static void main(String[] args) throws Exception { // Build command line parser. Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());//from ww w . jav a2 s. c o m } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { LOGGER.error("Argument parsing failed: %s", e.getMessage()); HELP_FORMATTER.printHelp(L2FilteringDriver.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } // Print help. if (cl.hasOption(OPTION_HELP)) { HELP_FORMATTER.printHelp(L2FilteringDriver.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } checkFilterOptionIsValid(OPTION_CHEMICAL_FILTER, cl); checkFilterOptionIsValid(OPTION_REACTION_FILTER, cl); // Get corpus files. File corpusFile = new File(cl.getOptionValue(OPTION_INPUT_CORPUS)); if (!corpusFile.exists()) { LOGGER.error("Input corpus file does not exist."); return; } File outputFile = new File(cl.getOptionValue(OPTION_OUTPUT_PATH)); outputFile.createNewFile(); if (outputFile.isDirectory()) { LOGGER.error("Output file is directory."); System.exit(1); } LOGGER.info("Reading corpus from file."); L2PredictionCorpus predictionCorpus = L2PredictionCorpus.readPredictionsFromJsonFile(corpusFile); LOGGER.info("Read in corpus with %d predictions.", predictionCorpus.getCorpus().size()); LOGGER.info("Corpus has %d distinct substrates.", predictionCorpus.getUniqueSubstrateInchis().size()); if (cl.hasOption(OPTION_FILTER_SUBSTRATES)) { LOGGER.info("Filtering by substrates."); File substratesFile = new File(cl.getOptionValue(OPTION_FILTER_SUBSTRATES)); L2InchiCorpus inchis = new L2InchiCorpus(); inchis.loadCorpus(substratesFile); Set<String> inchiSet = new HashSet<String>(); inchiSet.addAll(inchis.getInchiList()); predictionCorpus = predictionCorpus .applyFilter(prediction -> inchiSet.containsAll(prediction.getSubstrateInchis())); predictionCorpus.writePredictionsToJsonFile(outputFile); LOGGER.info("Done writing filtered corpus to file."); return; } if (cl.hasOption(OPTION_SPLIT_BY_RO)) { LOGGER.info("Splitting corpus into distinct corpuses for each ro."); Map<String, L2PredictionCorpus> corpusMap = predictionCorpus .splitCorpus(prediction -> prediction.getProjectorName()); for (Map.Entry<String, L2PredictionCorpus> entry : corpusMap.entrySet()) { String fileName = cl.getOptionValue(OPTION_OUTPUT_PATH) + "." + entry.getKey(); File oneOutputFile = new File(fileName); entry.getValue().writePredictionsToJsonFile(oneOutputFile); } LOGGER.info("Done writing split corpuses to file."); return; } predictionCorpus = runDbLookups(cl, predictionCorpus, opts); LOGGER.info("Applying filters."); predictionCorpus = applyFilter(predictionCorpus, ALL_CHEMICALS_IN_DB, cl, OPTION_CHEMICAL_FILTER); predictionCorpus = applyFilter(predictionCorpus, REACTION_MATCHES_DB, cl, OPTION_REACTION_FILTER); LOGGER.info("Filtered corpus has %d predictions.", predictionCorpus.getCorpus().size()); LOGGER.info("Printing final corpus."); predictionCorpus.writePredictionsToJsonFile(outputFile); LOGGER.info("L2FilteringDriver complete!."); }
From source file:com.dattack.dbtools.ping.Ping.java
/** * The <code>main</code> method. * * @param args// w w w . j a v a2 s .c o m * the program arguments */ public static void main(final String[] args) { final Options options = createOptions(); try { final CommandLineParser parser = new DefaultParser(); final CommandLine cmd = parser.parse(options, args); final String[] filenames = cmd.getOptionValues(FILE_OPTION); final String[] taskNames = cmd.getOptionValues(TASK_NAME_OPTION); HashSet<String> hs = null; if (taskNames != null) { hs = new HashSet<>(Arrays.asList(taskNames)); } final Ping ping = new Ping(); ping.execute(filenames, hs); } catch (@SuppressWarnings("unused") final ParseException e) { showUsage(options); } catch (final ConfigurationException | DbpingParserException e) { System.err.println(e.getMessage()); } }