예제 #1
0
  public static CompilerConfiguration generateCompilerConfigurationFromOptions(CommandLine cli)
      throws IOException {
    //
    // Setup the configuration data

    CompilerConfiguration configuration = new CompilerConfiguration();

    if (cli.hasOption("classpath")) {
      configuration.setClasspath(cli.getOptionValue("classpath"));
    }

    if (cli.hasOption('d')) {
      configuration.setTargetDirectory(cli.getOptionValue('d'));
    }

    if (cli.hasOption("encoding")) {
      configuration.setSourceEncoding(cli.getOptionValue("encoding"));
    }

    if (cli.hasOption("basescript")) {
      configuration.setScriptBaseClass(cli.getOptionValue("basescript"));
    }

    // joint compilation parameters
    if (cli.hasOption('j')) {
      Map<String, Object> compilerOptions = new HashMap<String, Object>();

      String[] opts = cli.getOptionValues("J");
      compilerOptions.put("namedValues", opts);

      opts = cli.getOptionValues("F");
      compilerOptions.put("flags", opts);

      configuration.setJointCompilationOptions(compilerOptions);
    }

    if (cli.hasOption("indy")) {
      configuration.getOptimizationOptions().put("int", false);
      configuration.getOptimizationOptions().put("indy", true);
    }

    if (cli.hasOption("configscript")) {
      String path = cli.getOptionValue("configscript");
      File groovyConfigurator = new File(path);
      Binding binding = new Binding();
      binding.setVariable("configuration", configuration);

      CompilerConfiguration configuratorConfig = new CompilerConfiguration();
      ImportCustomizer customizer = new ImportCustomizer();
      customizer.addStaticStars(
          "org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder");
      configuratorConfig.addCompilationCustomizers(customizer);

      GroovyShell shell = new GroovyShell(binding, configuratorConfig);
      shell.evaluate(groovyConfigurator);
    }

    return configuration;
  }
예제 #2
0
  /**
   * Parses the command line arguments and sets the respective fields accordingly. This function
   * sets the input source and target files, the source and target language, the running mode (gb or
   * bb), the additional files required by the GB feature extractor, the rebuild and log options
   *
   * @param args The command line arguments
   */
  public void parseArguments(String[] args) {

    Option help =
        OptionBuilder.withArgName("help")
            .hasArg()
            .withDescription("print project help information")
            .isRequired(false)
            .create("help");

    Option input = OptionBuilder.withArgName("input").hasArgs(3).isRequired(true).create("input");

    Option lang = OptionBuilder.withArgName("lang").hasArgs(2).isRequired(false).create("lang");

    Option feat = OptionBuilder.withArgName("feat").hasArgs(1).isRequired(false).create("feat");

    Option gb =
        OptionBuilder.withArgName("gb")
            .withDescription("GlassBox input files")
            .hasOptionalArgs(2)
            .hasArgs(3)
            .create("gb");

    Option mode =
        OptionBuilder.withArgName("mode")
            .withDescription("blackbox features, glassbox features or both")
            .hasArgs(1)
            .isRequired(true)
            .create("mode");

    Option config =
        OptionBuilder.withArgName("config")
            .withDescription("cofiguration file")
            .hasArgs(1)
            .isRequired(false)
            .create("config");

    Option rebuild = new Option("rebuild", "run all preprocessing tools");
    rebuild.setRequired(false);

    // separate 17 BB from 79 BB
    Option baseline = new Option("baseline", "only 17 baseline feature will be calculated");
    baseline.setRequired(false);

    CommandLineParser parser = new PosixParser();
    Options options = new Options();

    options.addOption(help);
    options.addOption(input);
    options.addOption(mode);
    options.addOption(lang);
    options.addOption(feat);
    options.addOption(gb);
    options.addOption(rebuild);
    options.addOption(config);
    options.addOption(baseline);

    try {
      // parse the command line arguments
      CommandLine line = parser.parse(options, args);

      if (line.hasOption("config")) {
        resourceManager = new PropertiesManager(line.getOptionValue("config"));
      } else {
        resourceManager = new PropertiesManager();
      }

      if (line.hasOption("input")) {
        // print the value of block-size
        String[] files = line.getOptionValues("input");
        sourceFile = files[0];
        targetFile = files[1];
      }

      if (line.hasOption("lang")) {
        String[] langs = line.getOptionValues("lang");
        sourceLang = langs[0];
        targetLang = langs[1];
      } else {
        sourceLang = resourceManager.getString("sourceLang.default");
        targetLang = resourceManager.getString("targetLang.default");
      }

      if (line.hasOption("gb")) {
        String[] gbOpt = line.getOptionValues("gb");
        for (String s : gbOpt) System.out.println(s);
        if (gbOpt.length > 1) {
          mtSys = MOSES;
          nbestInput = gbOpt[0];
          onebestPhrases = gbOpt[1];
          onebestLog = gbOpt[2];
          gbMode = 1;
        } else {
          File f = new File(gbOpt[0]);
          if (f.isDirectory()) {
            mtSys = IBM;
            wordLattices = gbOpt[0];
            gbMode = 1;
          } else {
            gbMode = 0;
            gbXML = gbOpt[0];
          }
        }
      }

      if (line.hasOption("mode")) {
        String[] modeOpt = line.getOptionValues("mode");
        setMod(modeOpt[0].trim());
        System.out.println(getMod());
        configPath = resourceManager.getString("featureConfig." + getMod());
        System.out.println("feature config:" + configPath);
        featureManager = new FeatureManager(configPath);
      }

      if (line.hasOption("feat")) {
        // print the value of block-size
        features = line.getOptionValue("feat");
        featureManager.setFeatureList(features);
      } else {
        featureManager.setFeatureList("all");
      }

      if (line.hasOption("rebuild")) {
        forceRun = true;
      }

      if (line.hasOption("baseline")) {
        isBaseline = true;
      }

    } catch (ParseException exp) {
      System.out.println("Unexpected exception:" + exp.getMessage());
    }
  }