Пример #1
0
  private static double testParser(Parser parser, List<Tree<String>> testTrees) {
    EnglishPennTreebankParseEvaluator.LabeledConstituentEval<String> eval =
        new EnglishPennTreebankParseEvaluator.LabeledConstituentEval<String>(
            Collections.singleton("ROOT"),
            new HashSet<String>(Arrays.asList(new String[] {"''", "``", ".", ":", ","})));
    for (Tree<String> testTree : testTrees) {
      List<String> testSentence = testTree.getYield();

      if (testSentence.size() > MAX_LENGTH) continue;
      Tree<String> guessedTree = parser.getBestParse(testSentence);
      System.out.println("Guess:\n" + Trees.PennTreeRenderer.render(guessedTree));
      System.out.println("Gold:\n" + Trees.PennTreeRenderer.render(testTree));
      eval.evaluate(guessedTree, testTree);
    }
    System.out.println();
    return eval.display(true);
  }
Пример #2
0
 private Tree<String> buildTagTree(List<String> words, List<String> tags, int currentPosition) {
   Tree<String> leafTree = new Tree<String>(words.get(currentPosition));
   Tree<String> tagTree =
       new Tree<String>(tags.get(currentPosition), Collections.singletonList(leafTree));
   return tagTree;
 }
Пример #3
0
 private Tree<String> addRoot(Tree<String> tree) {
   return new Tree<String>("ROOT", Collections.singletonList(tree));
 }