Exemplo n.º 1
0
  public static void main(String[] args) {

    String formatstr = "ws [--in][--out][--dd][--sw][-h]";
    Options opt = new Options();
    // opt.addOption(OptionBuilder.withArgName("in").hasArg().withDescription("search for buildfile
    // towards the root of the filesystem and use it").create("O"));
    opt.addOption(
        OptionBuilder.withLongOpt("in")
            .withDescription("file path of those files need to be processed")
            .withValueSeparator('=')
            .hasArg()
            .create());
    opt.addOption(
        OptionBuilder.withLongOpt("out")
            .withDescription("file path to store result")
            .withValueSeparator('=')
            .hasArg()
            .create());
    opt.addOption(
        OptionBuilder.withLongOpt("dd")
            .withDescription("file path of dictionary")
            .withValueSeparator('=')
            .hasArg()
            .create());
    opt.addOption(
        OptionBuilder.withLongOpt("sw")
            .withDescription("file path of stop words")
            .withValueSeparator('=')
            .hasArg()
            .create());
    opt.addOption("h", "help", false, "print help for the command.");

    if (args.length == 0) {
      HelpFormatter hf = new HelpFormatter();
      hf.printHelp(formatstr, "", opt, "");
      return;
    } else {
      parse_args(args, formatstr, opt);
    }
  }
Exemplo n.º 2
0
  public static Options createCLIOptions() {
    Options options = new Options();
    options.addOption("a", false, "use Aliases");
    Option solrServerName =
        OptionBuilder.withArgName("solrServer")
            .hasArg()
            .withDescription("Server to query.  ex: solrhost:4080")
            .create("s");
    Option searchTermName =
        OptionBuilder.withArgName("termValue")
            .hasArg()
            .withDescription("search term to use as input, use either term or f1 argument")
            .create("term");
    Option inputFileName =
        OptionBuilder.withArgName("inputFile")
            .hasArg()
            .withDescription("input filename for term1 values")
            .create("f1");
    Option inputFileName2 =
        OptionBuilder.withArgName("inputFile2")
            .hasArg()
            .withDescription("input filename for term2 values")
            .create("f2");
    Option outputFileName =
        OptionBuilder.withArgName("outputFile")
            .hasArg()
            .withDescription("output filename")
            .create("o");
    Option keepListName =
        OptionBuilder.withArgName("keepGrayList")
            .hasArg()
            .withDescription("gray list with 'keep' terms")
            .create("k");
    Option filterListName =
        OptionBuilder.withArgName("filterGrayList")
            .hasArg()
            .withDescription("gray list with 'filter' terms")
            .create("r");
    options.addOption(solrServerName);
    options.addOption(searchTermName);
    options.addOption(inputFileName);
    options.addOption(inputFileName2);
    options.addOption(outputFileName);
    options.addOption(keepListName);
    options.addOption(filterListName);

    return options;
  }
Exemplo n.º 3
0
  @SuppressWarnings({"AccessStaticViaInstance"})
  public static Options createCompilationOptions() {
    //
    // Parse the command line

    Options options = new Options();

    options.addOption(
        OptionBuilder.hasArg()
            .withArgName("path")
            .withDescription("Specify where to find the class files - must be first argument")
            .create("classpath"));
    options.addOption(
        OptionBuilder.withLongOpt("classpath")
            .hasArg()
            .withArgName("path")
            .withDescription("Aliases for '-classpath'")
            .create("cp"));
    options.addOption(
        OptionBuilder.withLongOpt("sourcepath")
            .hasArg()
            .withArgName("path")
            .withDescription("Specify where to find the source files")
            .create());
    options.addOption(
        OptionBuilder.withLongOpt("temp")
            .hasArg()
            .withArgName("temp")
            .withDescription("Specify temporary directory")
            .create());
    options.addOption(
        OptionBuilder.withLongOpt("encoding")
            .hasArg()
            .withArgName("encoding")
            .withDescription("Specify the encoding of the user class files")
            .create());
    options.addOption(
        OptionBuilder.hasArg()
            .withDescription("Specify where to place generated class files")
            .create('d'));
    //            options.addOption(OptionBuilder.withLongOpt("strict").withDescription("Turn on
    // strict type safety.").create('s'));
    options.addOption(
        OptionBuilder.withLongOpt("help")
            .withDescription("Print a synopsis of standard options")
            .create('h'));
    options.addOption(
        OptionBuilder.withLongOpt("version").withDescription("Print the version").create('v'));
    options.addOption(
        OptionBuilder.withLongOpt("exception")
            .withDescription("Print stack trace on error")
            .create('e'));
    options.addOption(
        OptionBuilder.withLongOpt("jointCompilation")
            .withDescription("Attach javac compiler to compile .java files")
            .create('j'));
    options.addOption(
        OptionBuilder.withLongOpt("basescript")
            .hasArg()
            .withArgName("class")
            .withDescription("Base class name for scripts (must derive from Script)")
            .create('b'));

    options.addOption(
        OptionBuilder.withArgName("property=value")
            .withValueSeparator()
            .hasArgs(2)
            .withDescription("name-value pairs to pass to javac")
            .create("J"));
    options.addOption(
        OptionBuilder.withArgName("flag")
            .hasArg()
            .withDescription("passed to javac for joint compilation")
            .create("F"));

    options.addOption(
        OptionBuilder.withLongOpt("indy")
            .withDescription("enables compilation using invokedynamic")
            .create());
    options.addOption(
        OptionBuilder.withLongOpt("configscript")
            .hasArg()
            .withDescription("A script for tweaking the configuration options")
            .create());
    return options;
  }
  public static void main(String[] args) {
    String logConfig = System.getProperty("log-config");
    if (logConfig == null) {
      logConfig = "log-config.txt";
    }

    Options options = new Options();
    options.addOption("h", "help", false, "print this message");
    options.addOption("v", "version", false, "output version information and exit");
    options.addOption(OptionBuilder.withDescription("trace mode").withLongOpt("trace").create());
    options.addOption(OptionBuilder.withDescription("debug mode").withLongOpt("debug").create());
    options.addOption(OptionBuilder.withDescription("info mode").withLongOpt("info").create());
    options.addOption(
        OptionBuilder.withArgName("file")
            .hasArg()
            .withDescription(
                "file from which to read the labelled training set in tabular format (reference annotation)")
            .isRequired()
            .withLongOpt("labelled")
            .create("l"));
    options.addOption(
        OptionBuilder.withArgName("file")
            .hasArg()
            .withDescription(
                "file from which to read the translated unlabelled training set in tabular format (one sentence per line, including id)")
            .isRequired()
            .withLongOpt("unlabelled")
            .create("u"));
    options.addOption(
        OptionBuilder.withArgName("file")
            .hasArg()
            .withDescription(
                "file from which to read the translated roles (phrase table: source language \\t target language)")
            .isRequired()
            .withLongOpt("roles")
            .create("r"));
    options.addOption(
        OptionBuilder.withArgName("file")
            .hasArg()
            .withDescription(
                "file in which to write the translated labelled training set in tabular format (aligned with the reference annotation)")
            .isRequired()
            .withLongOpt("output")
            .create("o"));
    options.addOption(
        OptionBuilder.withArgName("int")
            .hasArg()
            .withDescription("example from which to start from")
            .withLongOpt("start")
            .create());

    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;

    try {
      commandLine = parser.parse(options, args);

      Properties defaultProps = new Properties();
      try {
        defaultProps.load(new InputStreamReader(new FileInputStream(logConfig), "UTF-8"));
      } catch (Exception e) {
        defaultProps.setProperty("log4j.appender.stdout", "org.apache.log4j.ConsoleAppender");
        defaultProps.setProperty(
            "log4j.appender.stdout.layout.ConversionPattern", "[%t] %-5p (%F:%L) - %m %n");
        defaultProps.setProperty("log4j.appender.stdout.layout", "org.apache.log4j.PatternLayout");
        defaultProps.setProperty("log4j.appender.stdout.Encoding", "UTF-8");
      }

      if (commandLine.hasOption("trace")) {
        defaultProps.setProperty("log4j.rootLogger", "trace,stdout");
      } else if (commandLine.hasOption("debug")) {
        defaultProps.setProperty("log4j.rootLogger", "debug,stdout");
      } else if (commandLine.hasOption("info")) {
        defaultProps.setProperty("log4j.rootLogger", "info,stdout");
      } else {
        if (defaultProps.getProperty("log4j.rootLogger") == null) {
          defaultProps.setProperty("log4j.rootLogger", "info,stdout");
        }
      }
      PropertyConfigurator.configure(defaultProps);

      if (commandLine.hasOption("help") || commandLine.hasOption("version")) {
        throw new ParseException("");
      }

      File labelled = new File(commandLine.getOptionValue("labelled"));
      File unlabelled = new File(commandLine.getOptionValue("unlabelled"));
      File roles = new File(commandLine.getOptionValue("roles"));
      File output = new File(commandLine.getOptionValue("output"));
      try {
        if (commandLine.hasOption("start")) {
          int start = Integer.parseInt(commandLine.getOptionValue("start"));
          new AnnotationMigration(labelled, unlabelled, roles, output, start);
        } else {
          new AnnotationMigration(labelled, unlabelled, roles, output);
        }

      } catch (IOException e) {
        logger.error(e);
      }

    } catch (ParseException exp) {
      if (exp.getMessage().length() > 0) {
        System.err.println("Parsing failed: " + exp.getMessage() + "\n");
      }
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp(
          200,
          "java -Dfile.encoding=UTF-8 -cp dist/dirha.jar org.fbk.cit.hlt.dirha.AnnotationMigration",
          "\n",
          options,
          "\n",
          true);
      System.exit(1);
    }
  }