/** Same thing, but with compound unary transitions */ public void testCompoundUnaryTransitions() { for (String treeText : treeStrings) { Tree tree = convertTree(treeText); List<Transition> transitions = CreateTransitionSequence.createTransitionSequence(tree, true); State state = ShiftReduceParser.initialStateFromGoldTagTree(tree); for (Transition transition : transitions) { state = transition.apply(state); } assertEquals(tree, state.stack.peek()); } }
public void testInitialStateFromTagged() { String[] words = {"This", "is", "a", "short", "test", "."}; String[] tags = {"DT", "VBZ", "DT", "JJ", "NN", "."}; assertEquals(words.length, tags.length); List<TaggedWord> sentence = Sentence.toTaggedList(Arrays.asList(words), Arrays.asList(tags)); State state = ShiftReduceParser.initialStateFromTaggedSentence(sentence); for (int i = 0; i < words.length; ++i) { assertEquals(tags[i], state.sentence.get(i).value()); assertEquals(1, state.sentence.get(i).children().length); assertEquals(words[i], state.sentence.get(i).children()[0].value()); } }
public void testSeparators() { Tree tree = convertTree(commaTreeString); List<Transition> transitions = CreateTransitionSequence.createTransitionSequence(tree, true); List<String> expectedTransitions = Arrays.asList( new String[] { "Shift", "Shift", "Shift", "Shift", "RightBinary(@ADJP)", "RightBinary(ADJP)", "Shift", "RightBinary(@NP)", "RightBinary(NP)", "CompoundUnary([ROOT, FRAG])", "Finalize", "Idle" }); assertEquals( expectedTransitions, CollectionUtils.transformAsList( transitions, new Function<Transition, String>() { public String apply(Transition t) { return t.toString(); } })); String expectedSeparators = "[{2=,}]"; State state = ShiftReduceParser.initialStateFromGoldTagTree(tree); assertEquals(1, state.separators.size()); assertEquals(2, state.separators.firstKey().intValue()); assertEquals(",", state.separators.get(2)); }
public boolean parse(Tree tree) { this.originalSentence = tree.yieldHasWord(); initialState = ShiftReduceParser.initialStateFromGoldTagTree(tree); return parseInternal(); }
@Override public boolean parse(List<? extends HasWord> sentence) { this.originalSentence = sentence; initialState = ShiftReduceParser.initialStateFromTaggedSentence(sentence); return parseInternal(); }