示例#1
0
  /////////////////////////////////////////////////////
  // RUNNING THE PARSER
  ////////////////////////////////////////////////////
  public static void main(String[] args) throws FileNotFoundException, Exception {
    System.setProperty("java.io.tmpdir", "./tmp/");
    ParserOptions options = new ParserOptions(args);
    System.out.println("Default temp directory:" + System.getProperty("java.io.tmpdir"));

    System.out.println("Separate labeling: " + options.separateLab);

    if (options.train) {
      DependencyPipe pipe =
          options.secondOrder ? new DependencyPipe2O(options) : new DependencyPipe(options);
      int[] instanceLengths = pipe.createInstances(options.trainfile, options.trainforest);
      pipe.closeAlphabets();
      DependencyParser dp = new DependencyParser(pipe, options);
      // pipe.printModelStats(null);
      int numFeats = pipe.dataAlphabet.size();
      int numTypes = pipe.typeAlphabet.size();
      System.out.print("Num Feats: " + numFeats);
      System.out.println(".\tNum Edge Labels: " + numTypes);
      if (options
          .stackedLevel0) // Augment training data with output predictions, for stacked learning
      // (afm 03-03-08)
      {
        // Output data augmented with output predictions
        System.out.println("Augmenting training data with output predictions...");
        options.testfile = options.trainfile;
        dp.augment(
            instanceLengths, options.trainfile, options.trainforest, options.augmentNumParts);
        // Now train the base classifier in the whole corpus, nothing being ignored
        System.out.println("Training the base classifier in the whole corpus...");
      }
      // afm 03-06-08 --- To allow some instances to be ignored
      int ignore[] = new int[instanceLengths.length];
      for (int i = 0; i < instanceLengths.length; i++) ignore[i] = 0;
      dp.params = new Parameters(pipe.dataAlphabet.size());
      dp.train(instanceLengths, ignore, options.trainfile, options.trainforest);
      System.out.print("Saving model...");
      dp.saveModel(options.modelName);
      System.out.print("done.");
    }
    if (options.test) {
      DependencyPipe pipe =
          options.secondOrder ? new DependencyPipe2O(options) : new DependencyPipe(options);
      DependencyParser dp = new DependencyParser(pipe, options);
      System.out.print("\tLoading model...");
      dp.loadModel(options.modelName);
      System.out.println("done.");
      pipe.printModelStats(dp.params);
      pipe.closeAlphabets();
      dp.outputParses(null);
    }

    System.out.println();

    if (options.eval) {
      System.out.println("\nEVALUATION PERFORMANCE:");
      DependencyEvaluator.evaluate(options.goldfile, options.outfile, options.format);
    }
  }
  // ///////////////////////////////////////////////////
  // RUNNING THE PARSER
  // //////////////////////////////////////////////////
  public static void main(String[] args) throws FileNotFoundException, Exception {

    ParserOptions options = new ParserOptions(args);

    if (options.train) {

      DependencyPipe pipe =
          options.secondOrder ? new DependencyPipe2O(options) : new DependencyPipe(options);

      int[] instanceLengths = pipe.createInstances(options.trainfile, options.trainforest);

      pipe.closeAlphabets();

      DependencyParser dp = new DependencyParser(pipe, options);

      int numFeats = pipe.dataAlphabet.size();
      int numTypes = pipe.typeAlphabet.size();
      System.out.print("Num Feats: " + numFeats);
      System.out.println(".\tNum Edge Labels: " + numTypes);

      dp.train(instanceLengths, options.trainfile, options.trainforest);

      System.out.print("Saving model...");
      dp.saveModel(options.modelName);
      System.out.print("done.");
    }

    if (options.test) {
      DependencyPipe pipe =
          options.secondOrder ? new DependencyPipe2O(options) : new DependencyPipe(options);
      scoreWriter = new BufferedWriter(new FileWriter(options.outfile + ".mstscores"));

      DependencyParser dp = new DependencyParser(pipe, options);

      System.out.print("\tLoading model...");
      dp.loadModel(options.modelName);
      System.out.println("done.");

      pipe.closeAlphabets();

      dp.outputParses();
      scoreWriter.close();
    }

    System.out.println();

    if (options.eval) {
      System.out.println("\nEVALUATION PERFORMANCE:");
      DependencyEvaluator.evaluate(
          options.goldfile, options.outfile, options.format, (options.confidenceEstimator != null));
    }

    if (options.rankEdgesByConfidence) {
      System.out.println("\nRank edges by confidence:");
      EdgeRankerByConfidence edgeRanker = new EdgeRankerByConfidence();
      edgeRanker.rankEdgesByConfidence(options.goldfile, options.outfile, options.format);
    }
  }