private Tree<String> merge(Tree<String> leftTree, Tree<String> rightTree) { int span = leftTree.getYield().size() + rightTree.getYield().size(); String mostFrequentLabel = spanToCategories.getCounter(span).argMax(); List<Tree<String>> children = new ArrayList<Tree<String>>(); children.add(leftTree); children.add(rightTree); return new Tree<String>(mostFrequentLabel, children); }
/* Builds a lexicon from the observed tags in a list of training trees. */ public Lexicon(List<Tree<String>> trainTrees) { for (Tree<String> trainTree : trainTrees) { List<String> words = trainTree.getYield(); List<String> tags = trainTree.getPreTerminalYield(); for (int position = 0; position < words.size(); position++) { String word = words.get(position); String tag = tags.get(position); tallyTagging(word, tag); } } }
private static void 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); } eval.display(true); }