List of usage examples for org.apache.commons.cli HelpFormatter printHelp
public void printHelp(int width, String cmdLineSyntax, String header, Options options, String footer)
options
with the specified command line syntax. From source file:fr.inria.edelweiss.kgdqp.core.CentralizedInferrencingNoSpin.java
public static void main(String args[]) throws ParseException, EngineException, InterruptedException, IOException, LoadException { List<String> endpoints = new ArrayList<String>(); String queryPath = null;//from w ww. ja va 2 s .co m boolean rulesSelection = false; File rulesDir = null; File ontDir = null; ///////////////// Graph graph = Graph.create(); QueryProcess exec = QueryProcess.create(graph); Options options = new Options(); Option helpOpt = new Option("h", "help", false, "print this message"); // Option queryOpt = new Option("q", "query", true, "specify the sparql query file"); // Option endpointOpt = new Option("e", "endpoint", true, "a federated sparql endpoint URL"); Option versionOpt = new Option("v", "version", false, "print the version information and exit"); Option rulesOpt = new Option("r", "rulesDir", true, "directory containing the inference rules"); Option ontOpt = new Option("o", "ontologiesDir", true, "directory containing the ontologies for rules selection"); // Option locOpt = new Option("c", "centralized", false, "performs centralized inferences"); Option dataOpt = new Option("l", "load", true, "data file or directory to be loaded"); // Option selOpt = new Option("s", "rulesSelection", false, "if set to true, only the applicable rules are run"); // options.addOption(queryOpt); // options.addOption(endpointOpt); options.addOption(helpOpt); options.addOption(versionOpt); options.addOption(rulesOpt); options.addOption(ontOpt); // options.addOption(selOpt); // options.addOption(locOpt); options.addOption(dataOpt); String header = "Corese/KGRAM rule engine experiment command line interface"; String footer = "\nPlease report any issue to alban.gaignard@cnrs.fr, olivier.corby@inria.fr"; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("kgdqp", header, options, footer, true); System.exit(0); } if (cmd.hasOption("o")) { rulesSelection = true; String ontDirPath = cmd.getOptionValue("o"); ontDir = new File(ontDirPath); if (!ontDir.isDirectory()) { logger.warn(ontDirPath + " is not a valid directory path."); System.exit(0); } } if (!cmd.hasOption("r")) { logger.info("You must specify a path for inference rules directory !"); System.exit(0); } if (cmd.hasOption("l")) { String[] dataPaths = cmd.getOptionValues("l"); for (String path : dataPaths) { Load ld = Load.create(graph); ld.load(path); logger.info("Loaded " + path); } } if (cmd.hasOption("v")) { logger.info("version 3.0.4-SNAPSHOT"); System.exit(0); } String rulesDirPath = cmd.getOptionValue("r"); rulesDir = new File(rulesDirPath); if (!rulesDir.isDirectory()) { logger.warn(rulesDirPath + " is not a valid directory path."); System.exit(0); } // Local rules graph initialization Graph rulesG = Graph.create(); Load ld = Load.create(rulesG); if (rulesSelection) { // Ontology loading if (ontDir.isDirectory()) { for (File o : ontDir.listFiles()) { logger.info("Loading " + o.getAbsolutePath()); ld.load(o.getAbsolutePath()); } } } // Rules loading if (rulesDir.isDirectory()) { for (File r : rulesDir.listFiles()) { if (r.getAbsolutePath().endsWith(".rq")) { logger.info("Loading " + r.getAbsolutePath()); // ld.load(r.getAbsolutePath()); // byte[] encoded = Files.readAllBytes(Paths.get(r.getAbsolutePath())); // String construct = new String(encoded, "UTF-8"); //StandardCharsets.UTF_8); FileInputStream f = new FileInputStream(r); QueryLoad ql = QueryLoad.create(); String construct = ql.read(f); f.close(); SPINProcess sp = SPINProcess.create(); String spinConstruct = sp.toSpin(construct); ld.load(new ByteArrayInputStream(spinConstruct.getBytes()), Load.TURTLE_FORMAT); logger.info("Rules graph size : " + rulesG.size()); } } } // Rule engine initialization RuleEngine ruleEngine = RuleEngine.create(graph); ruleEngine.set(exec); ruleEngine.setOptimize(true); ruleEngine.setConstructResult(true); ruleEngine.setTrace(true); StopWatch sw = new StopWatch(); logger.info("Federated graph size : " + graph.size()); logger.info("Rules graph size : " + rulesG.size()); // Rule selection logger.info("Rules selection"); QueryProcess localKgram = QueryProcess.create(rulesG); ArrayList<String> applicableRules = new ArrayList<String>(); sw.start(); String rulesSelQuery = ""; if (rulesSelection) { rulesSelQuery = pertinentRulesQuery; } else { rulesSelQuery = allRulesQuery; } Mappings maps = localKgram.query(rulesSelQuery); logger.info("Rules selected in " + sw.getTime() + " ms"); logger.info("Applicable rules : " + maps.size()); // Selected rule loading for (Mapping map : maps) { IDatatype dt = (IDatatype) map.getValue("?res"); String rule = dt.getLabel(); //loading rule in the rule engine // logger.info("Adding rule : "); // System.out.println("-------"); // System.out.println(rule); // System.out.println(""); // if (! rule.toLowerCase().contains("sameas")) { applicableRules.add(rule); ruleEngine.addRule(rule); // } } // Rules application on distributed sparql endpoints logger.info("Rules application (" + applicableRules.size() + " rules)"); ExecutorService threadPool = Executors.newCachedThreadPool(); RuleEngineThread ruleThread = new RuleEngineThread(ruleEngine); sw.reset(); sw.start(); // ruleEngine.process(); threadPool.execute(ruleThread); threadPool.shutdown(); //monitoring loop while (!threadPool.isTerminated()) { // System.out.println("******************************"); // System.out.println(Util.jsonDqpCost(QueryProcessDQP.queryCounter, QueryProcessDQP.queryVolumeCounter, QueryProcessDQP.sourceCounter, QueryProcessDQP.sourceVolumeCounter)); // System.out.println("Rule engine running for " + sw.getTime() + " ms"); // System.out.println("Federated graph size : " + graph.size()); System.out.println(sw.getTime() + " , " + graph.size()); Thread.sleep(5000); } logger.info("Federated graph size : " + graph.size()); // logger.info(Util.jsonDqpCost(QueryProcessDQP.queryCounter, QueryProcessDQP.queryVolumeCounter, QueryProcessDQP.sourceCounter, QueryProcessDQP.sourceVolumeCounter)); // TripleFormat f = TripleFormat.create(graph, true); // f.write("/tmp/gAll.ttl"); }
From source file:br.ufpb.dicomflow.integrationAPI.tools.SendService.java
public static void main(final String args[]) { try {//from ww w .jav a2s.c o m CommandLine cl = parseComandLine(args); CLIUtils.configureLog(cl); CLIUtils.configureProperties(properties, cl, CLIUtils.SEND_PROPERTIES); CLIUtils.configureEncryptProperties(signer, privateKey, cipher, cl); configureService(service, cl); sendService(cl); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new Comparator<Option>() { @Override public int compare(Option o1, Option o2) { return 0; } }); formatter.printHelp(rb.getString("send-usage"), rb.getString("send-description"), opts, rb.getString("send-example"), true); } catch (PropertyNotFoundException e) { Logger.ef(e, rb.getString("load-property-exception")); } catch (JAXBException e) { Logger.ef(e, rb.getString("load-service-exception")); } catch (ClassNotFoundException e) { Logger.ef(e, rb.getString("load-service-exception")); } catch (UnrecoverableKeyException e) { Logger.ef(e, rb.getString("load-encrypt-exception")); } catch (KeyStoreException e) { Logger.ef(e, rb.getString("load-encrypt-exception")); } catch (NoSuchAlgorithmException e) { Logger.ef(e, rb.getString("load-encrypt-exception")); } catch (CertificateException e) { Logger.ef(e, rb.getString("load-encrypt-exception")); } catch (FileNotFoundException e) { Logger.ef(e, rb.getString("load-file-exception")); } catch (IOException e) { Logger.ef(e, rb.getString("load-encrypt-exception")); } }
From source file:fr.inria.edelweiss.kgdqp.core.FedInferrencingCLI.java
public static void main(String args[]) throws ParseException, EngineException, InterruptedException { List<String> endpoints = new ArrayList<String>(); String queryPath = null;/*from w w w. j a va 2s.c o m*/ boolean rulesSelection = false; File rulesDir = null; File ontDir = null; Options options = new Options(); Option helpOpt = new Option("h", "help", false, "print this message"); Option queryOpt = new Option("q", "query", true, "specify the sparql query file"); Option endpointOpt = new Option("e", "endpoint", true, "a federated sparql endpoint URL"); Option versionOpt = new Option("v", "version", false, "print the version information and exit"); Option rulesOpt = new Option("r", "rulesDir", true, "directory containing the inference rules"); Option ontOpt = new Option("o", "ontologiesDir", true, "directory containing the ontologies for rules selection"); // Option selOpt = new Option("s", "rulesSelection", false, "if set to true, only the applicable rules are run"); options.addOption(queryOpt); options.addOption(endpointOpt); options.addOption(helpOpt); options.addOption(versionOpt); options.addOption(rulesOpt); options.addOption(ontOpt); // options.addOption(selOpt); String header = "Corese/KGRAM distributed rule engine command line interface"; String footer = "\nPlease report any issue to alban.gaignard@cnrs.fr, olivier.corby@inria.fr"; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("kgdqp", header, options, footer, true); System.exit(0); } if (!cmd.hasOption("e")) { logger.info("You must specify at least the URL of one sparql endpoint !"); System.exit(0); } else { endpoints = new ArrayList<String>(Arrays.asList(cmd.getOptionValues("e"))); } if (cmd.hasOption("o")) { rulesSelection = true; String ontDirPath = cmd.getOptionValue("o"); ontDir = new File(ontDirPath); if (!ontDir.isDirectory()) { logger.warn(ontDirPath + " is not a valid directory path."); System.exit(0); } } if (!cmd.hasOption("r")) { logger.info("You must specify a path for inference rules directory !"); System.exit(0); } else if (rulesSelection) { } if (cmd.hasOption("v")) { logger.info("version 3.0.4-SNAPSHOT"); System.exit(0); } String rulesDirPath = cmd.getOptionValue("r"); rulesDir = new File(rulesDirPath); if (!rulesDir.isDirectory()) { logger.warn(rulesDirPath + " is not a valid directory path."); System.exit(0); } ///////////////// Graph graph = Graph.create(); QueryProcessDQP execDQP = QueryProcessDQP.create(graph); for (String url : endpoints) { try { execDQP.addRemote(new URL(url), WSImplem.REST); } catch (MalformedURLException ex) { logger.error(url + " is not a well-formed URL"); System.exit(1); } } // Local rules graph initialization Graph rulesG = Graph.create(); Load ld = Load.create(rulesG); if (rulesSelection) { // Ontology loading if (ontDir.isDirectory()) { for (File o : ontDir.listFiles()) { logger.info("Loading " + o.getAbsolutePath()); ld.load(o.getAbsolutePath()); } } } // Rules loading if (rulesDir.isDirectory()) { for (File r : rulesDir.listFiles()) { logger.info("Loading " + r.getAbsolutePath()); ld.load(r.getAbsolutePath()); } } // Rule engine initialization RuleEngine ruleEngine = RuleEngine.create(graph); ruleEngine.set(execDQP); StopWatch sw = new StopWatch(); logger.info("Federated graph size : " + graph.size()); logger.info("Rules graph size : " + rulesG.size()); // Rule selection logger.info("Rules selection"); QueryProcess localKgram = QueryProcess.create(rulesG); ArrayList<String> applicableRules = new ArrayList<String>(); sw.start(); String rulesSelQuery = ""; if (rulesSelection) { rulesSelQuery = pertinentRulesQuery; } else { rulesSelQuery = allRulesQuery; } Mappings maps = localKgram.query(rulesSelQuery); logger.info("Rules selected in " + sw.getTime() + " ms"); logger.info("Applicable rules : " + maps.size()); // Selected rule loading for (Mapping map : maps) { IDatatype dt = (IDatatype) map.getValue("?res"); String rule = dt.getLabel(); //loading rule in the rule engine // logger.info("Adding rule : " + rule); applicableRules.add(rule); ruleEngine.addRule(rule); } // Rules application on distributed sparql endpoints logger.info("Rules application (" + applicableRules.size() + " rules)"); ExecutorService threadPool = Executors.newCachedThreadPool(); RuleEngineThread ruleThread = new RuleEngineThread(ruleEngine); sw.reset(); sw.start(); // ruleEngine.process(); threadPool.execute(ruleThread); threadPool.shutdown(); //monitoring loop while (!threadPool.isTerminated()) { System.out.println("******************************"); System.out.println(Util.jsonDqpCost(QueryProcessDQP.queryCounter, QueryProcessDQP.queryVolumeCounter, QueryProcessDQP.sourceCounter, QueryProcessDQP.sourceVolumeCounter)); System.out.println("Rule engine running for " + sw.getTime() + " ms"); System.out.println("Federated graph size : " + graph.size()); Thread.sleep(10000); } logger.info("Federated graph size : " + graph.size()); logger.info(Util.jsonDqpCost(QueryProcessDQP.queryCounter, QueryProcessDQP.queryVolumeCounter, QueryProcessDQP.sourceCounter, QueryProcessDQP.sourceVolumeCounter)); ///////////// Query file processing // StringBuffer fileData = new StringBuffer(1000); // BufferedReader reader = null; // try { // reader = new BufferedReader(new FileReader(queryPath)); // } catch (FileNotFoundException ex) { // logger.error("Query file "+queryPath+" not found !"); // System.exit(1); // } // char[] buf = new char[1024]; // int numRead = 0; // try { // while ((numRead = reader.read(buf)) != -1) { // String readData = String.valueOf(buf, 0, numRead); // fileData.append(readData); // buf = new char[1024]; // } // reader.close(); // } catch (IOException ex) { // logger.error("Error while reading query file "+queryPath); // System.exit(1); // } // // String sparqlQuery = fileData.toString(); // // Query q = exec.compile(sparqlQuery,null); // System.out.println(q); // // StopWatch sw = new StopWatch(); // sw.start(); // Mappings map = exec.query(sparqlQuery); // int dqpSize = map.size(); // System.out.println("--------"); // long time = sw.getTime(); // System.out.println(time + " " + dqpSize); }
From source file:br.ufpb.dicomflow.integrationAPI.tools.ReadService.java
public static void main(final String args[]) { try {//from w w w . ja v a2 s .c o m CommandLine cl = parseComandLine(args); CLIUtils.configureLog(cl); CLIUtils.configureProperties(properties, cl, CLIUtils.READ_PROPERTIES); CLIUtils.configureEncryptProperties(cipher, privateKey, signer, cl); configureFilterProperties(filter, cl); readService(cl); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new Comparator<Option>() { @Override public int compare(Option o1, Option o2) { return 0; } }); formatter.printHelp(rb.getString("read-usage"), rb.getString("read-description"), opts, rb.getString("read-example"), true); } catch (PropertyNotFoundException e) { Logger.ef(e, rb.getString("load-property-exception")); } catch (UnrecoverableKeyException e) { Logger.ef(e, rb.getString("load-encrypt-exception")); } catch (KeyStoreException e) { Logger.ef(e, rb.getString("load-encrypt-exception")); } catch (NoSuchAlgorithmException e) { Logger.ef(e, rb.getString("load-encrypt-exception")); } catch (CertificateException e) { Logger.ef(e, rb.getString("load-encrypt-exception")); } catch (FileNotFoundException e) { Logger.ef(e, rb.getString("load-file-exception")); } catch (IOException e) { Logger.ef(e, rb.getString("load-file-exception")); } catch (NumberFormatException e) { Logger.ef(e, rb.getString("load-filter-exception")); } catch (java.text.ParseException e) { Logger.ef(e, rb.getString("load-filter-exception")); } catch (JAXBException e) { Logger.ef(e, rb.getString("load-service-exception")); } }
From source file:es.upm.oeg.tools.quality.ldsniffer.cmd.LDSnifferApp.java
public static void main(String[] args) { HelpFormatter help = new HelpFormatter(); String header = "Assess a list of Linked Data resources using Linked Data Quality Model."; String footer = "Please report issues at https://github.com/nandana/ld-sniffer"; try {//from w ww. j av a2 s . c o m CommandLine line = parseArguments(args); if (line.hasOption("help")) { help.printHelp("LDSnifferApp", header, OPTIONS, footer, true); System.exit(0); } evaluationTimeout = Integer.parseInt(line.getOptionValue("t", "10")); if (line.hasOption("md")) { includeMetricDefinitions = true; } if (line.hasOption("rdf")) { rdfOutput = true; } logger.info("URL List: " + line.getOptionValue("ul")); logger.info("TDB Path: " + line.getOptionValue("tdb")); logger.info("Metrics Path: " + line.getOptionValue("ml")); logger.info("Include Metric definitions: " + line.getOptionValue("ml")); logger.info("RDF output: " + line.getOptionValue("rdf")); logger.info("Timeout (mins): " + evaluationTimeout); if (line.hasOption("ml")) { Path path = Paths.get(line.getOptionValue("ml")); if (!Files.exists(path)) { throw new IOException(path.toAbsolutePath().toString() + " : File doesn't exit."); } } //Set the TDB path String tdbDirectory; if (line.hasOption("tdb")) { tdbDirectory = line.getOptionValue("tdb"); } else { Path tempPath = Files.createTempDirectory("tdb_"); tdbDirectory = tempPath.toAbsolutePath().toString(); } // Create the URL list for the evaluation if (!line.hasOption("ul") && !line.hasOption("url")) { System.out.println("One of the following parameters are required: url or urlList "); help.printHelp("LDSnifferApp", header, OPTIONS, footer, true); System.exit(0); } else if (line.hasOption("ul") && line.hasOption("url")) { System.out.println("You have to specify either url or urlList, not both."); help.printHelp("LDSnifferApp", header, OPTIONS, footer, true); System.exit(0); } List<String> urlList = null; if (line.hasOption("ul")) { Path path = Paths.get(line.getOptionValue("ul")); logger.info("Path : " + path.toAbsolutePath().toString()); logger.info("Path exits : " + Files.exists(path)); urlList = Files.readAllLines(path, Charset.defaultCharset()); } else if (line.hasOption("url")) { urlList = new ArrayList<>(); urlList.add(line.getOptionValue("url")); } Executor executor = new Executor(tdbDirectory, urlList); executor.execute(); } catch (MissingOptionException e) { help.printHelp("LDSnifferApp", header, OPTIONS, footer, true); logger.error("Missing arguments. Reason: " + e.getMessage(), e); System.exit(1); } catch (ParseException e) { logger.error("Parsing failed. Reason: " + e.getMessage(), e); System.exit(1); } catch (IOException e) { logger.error("Execution failed. Reason: " + e.getMessage(), e); System.exit(1); } }