示例#1
0
 @SuppressWarnings("static-access")
 private static void addKeyOptions(Options opts) {
   opts.addOption(
       OptionBuilder.hasArgs()
           .withArgName("attr=value")
           .withValueSeparator('=')
           .withDescription(rb.getString("match"))
           .create("m"));
   opts.addOption(
       OptionBuilder.hasArgs()
           .withArgName("attr")
           .withDescription(rb.getString("in-attr"))
           .create("i"));
 }
示例#2
0
文件: BugsTest.java 项目: srnsw/xena
 public void test15648() throws Exception {
   CommandLineParser parser = new PosixParser();
   final String[] args = new String[] {"-m", "\"Two Words\""};
   Option m = OptionBuilder.hasArgs().create("m");
   Options options = new Options();
   options.addOption(m);
   CommandLine line = parser.parse(options, args);
   assertEquals("Two Words", line.getOptionValue("m"));
 }
  /**
   * Build command-line options and descriptions
   *
   * @return command line options
   */
  public static Options buildOptions() {
    Options options = new Options();

    // Build in/output file arguments, which are required, but there is no
    // addOption method that can specify this
    OptionBuilder.isRequired();
    OptionBuilder.hasArgs();
    OptionBuilder.withLongOpt("outputFilename");
    options.addOption(OptionBuilder.create("o"));

    OptionBuilder.isRequired();
    OptionBuilder.hasArgs();
    OptionBuilder.withLongOpt("inputFilename");
    options.addOption(OptionBuilder.create("i"));

    options.addOption("p", "processor", true, "");
    options.addOption("v", "verbose", false, "");
    options.addOption("h", "help", false, "");

    return options;
  }
示例#4
0
 public static void main(String[] arguments) {
   final CommandLineParser parser = new PosixParser();
   final Options opts = new Options();
   CommandLine cmd = null;
   Pipeline.addLogHelpAndInputOptions(opts);
   Pipeline.addTikaOptions(opts);
   Pipeline.addOutputOptions(opts);
   Pipeline.addJdbcResourceOptions(
       opts, DEFAULT_JDBC_DRIVER, DEFAULT_DB_PROVIDER, DEFAULT_DATABASE);
   // entity annotator options setup
   opts.addOption("Q", "query-file", true, "file with SQL SELECT queries");
   OptionBuilder.withLongOpt("query");
   OptionBuilder.withArgName("SELECT");
   OptionBuilder.hasArgs();
   OptionBuilder.withDescription("one or more SQL SELECT queries");
   opts.addOption(OptionBuilder.create('q'));
   opts.addOption(
       "m", "entity-map", true, "name of the entity map file [" + DEFAULT_MAPPING_FILE + "]");
   opts.addOption(
       "n", "namespace", true, "namespace of the entity annotations [" + DEFAULT_NAMESPACE + "]");
   try {
     cmd = parser.parse(opts, arguments);
   } catch (final ParseException e) {
     System.err.println(e.getLocalizedMessage());
     System.exit(1); // == exit ==
   }
   final Logger l =
       Pipeline.loggingSetup(cmd, opts, "txtfnnl entities [options] <directory|files...>\n");
   // output options
   XmiWriter.Builder writer =
       Pipeline.configureWriter(cmd, XmiWriter.configure(Pipeline.ensureOutputDirectory(cmd)));
   // DB resource
   ExternalResourceDescription jdbcResource = null;
   try {
     jdbcResource =
         Pipeline.getJdbcConnectionResource(
             cmd, l, DEFAULT_JDBC_DRIVER, DEFAULT_DB_PROVIDER, DEFAULT_DATABASE);
   } catch (final ClassNotFoundException e) {
     System.err.println("JDBC resoruce setup failed:");
     System.err.println(e.toString());
     System.exit(1); // == EXIT ==
   } catch (ResourceInitializationException e) {
     System.err.println("JDBC resoruce setup failed:");
     System.err.println(e.toString());
     System.exit(1); // == EXIT ==
   }
   /* BEGIN entity annotator */
   final String queryFileName = cmd.getOptionValue('Q');
   final String entityMapPath = cmd.getOptionValue('m', DEFAULT_MAPPING_FILE);
   final String namespace = cmd.getOptionValue('n', DEFAULT_NAMESPACE);
   String[] queries = cmd.getOptionValues('q');
   File entityMap; // m
   if (queryFileName != null) {
     final File queryFile = new File(queryFileName);
     if (!queryFile.isFile() || !queryFile.canRead()) {
       System.err.print("cannot read query file ");
       System.err.println(queryFile);
       System.exit(1); // == EXIT ==
     }
     String[] fileQueries = null;
     try {
       fileQueries =
           IOUtils.read(new FileInputStream(queryFile), Pipeline.inputEncoding(cmd)).split("\n");
     } catch (final Exception e) {
       System.err.print("cannot read query file ");
       System.err.print(queryFile);
       System.err.print(":");
       System.err.println(e.getLocalizedMessage());
       System.exit(1); // == EXIT ==
     }
     if (queries == null || queries.length == 0) {
       queries = fileQueries;
     } else {
       final String[] tmp = new String[queries.length + fileQueries.length];
       System.arraycopy(queries, 0, tmp, 0, queries.length);
       System.arraycopy(fileQueries, 0, tmp, queries.length, fileQueries.length);
       queries = tmp;
     }
   }
   entityMap = new File(entityMapPath);
   if (!entityMap.isFile() || !entityMap.canRead()) {
     System.err.print("cannot read entity map file ");
     System.err.println(entityMapPath);
     System.exit(1); // == EXIT ==
   }
   if (queries == null || queries.length == 0) {
     queries = DEFAULT_SQL_QUERIES;
   }
   /* END entity annotator */
   try {
     final Pipeline pipeline = new Pipeline(2); // tika and known entity annotator
     KnownEntityAnnotator.Builder builder =
         KnownEntityAnnotator.configure(namespace, queries, entityMap, jdbcResource);
     pipeline.setReader(cmd);
     pipeline.configureTika(cmd);
     pipeline.set(1, Pipeline.multiviewEngine(builder.create()));
     pipeline.setConsumer(Pipeline.textEngine(writer.create()));
     pipeline.run();
     pipeline.destroy();
   } catch (final UIMAException e) {
     l.severe(e.toString());
     System.err.println(e.getLocalizedMessage());
     System.exit(1); // == EXIT ==
   } catch (final IOException e) {
     l.severe(e.toString());
     System.err.println(e.getLocalizedMessage());
     System.exit(1); // == EXIT ==
   }
   System.exit(0);
 }