def testShift(self): """Shift takes the first token from the front of the buffer and pushes it onto the stack""" state = tdatatypes.State(5) system = ArcHybrid() system.applyTransition(state, ArcHybrid.SHIFT) self.assertEqual(state.buffer.toList(), [1, 2, 3, 4]) self.assertEqual(state.stack.toList(), [-1, 0])
def __buildCorrectTransitions(self, tree): system = ArcHybrid() soracle = ArcHybridDynamicOracle(system, None, MockExplorePolicy()) result = [] state = tdatatypes.State(tree.nrOfTokens()) while not system.isFinal(state): transition = soracle.nextCorrectTransitions(state, tree)[0] result.append(transition) system.applyTransition(state, transition) return result
def testChangesExample(self): """Example: changesExample""" system = ArcHybrid() tree = tdatatypes.buildTreeFromTransitions( system, changesExample[1].nrOfTokens(), changesCorrect) self.assertEqual(tree, changesExample[1])
def testFranceExample(self): """Example: franceExample""" system = ArcHybrid() tree = tdatatypes.buildTreeFromTransitions( system, franceExample[1].nrOfTokens(), franceCorrect) self.assertEqual(tree, franceExample[1])
def testMsCollinsExample(self): """Example: msCollinsExample""" system = ArcHybrid() tree = tdatatypes.buildTreeFromTransitions( system, msCollinsExample[1].nrOfTokens(), msCollinsCorrect) self.assertEqual(tree, msCollinsExample[1])
def testOneWordExample(self): """Example: oneWordExample""" system = ArcHybrid() tree = tdatatypes.buildTreeFromTransitions( system, oneWordExample[1].nrOfTokens(), oneWordCorrect) self.assertEqual(tree, oneWordExample[1])
def testChangesExample(self): """Example: changesExample""" system = ArcHybrid() soracle = ArcHybridStaticOracle(system) transitions = oracle.buildStaticCorrectTransitions( changesExample[1], system, soracle) self.assertEqual(changesCorrect, transitions)
def testFranceExample(self): """Example: franceExample""" system = ArcHybrid() soracle = ArcHybridStaticOracle(system) transitions = oracle.buildStaticCorrectTransitions( franceExample[1], system, soracle) self.assertEqual(franceCorrect, transitions)
def testOneWordExample(self): """Example: oneWordExample""" system = ArcHybrid() soracle = ArcHybridStaticOracle(system) transitions = oracle.buildStaticCorrectTransitions( oneWordExample[1], system, soracle) self.assertEqual(oneWordCorrect, transitions)
def testLeftArcHead(self): """LeftArc introduces an arc from the front of the buffer to the top-most token on the stack""" state = tdatatypes.State(5) system = ArcHybrid() system.applyTransition(state, ArcHybrid.SHIFT) system.applyTransition(state, ArcHybrid.LEFTARC) self.assertEqual(state.arcs.getHead(0), 1)
def testRightArcHead(self): """RightArcStandard introduces an arc from the second item to the top-most token on the stack""" state = tdatatypes.State(5) system = ArcHybrid() system.applyTransition(state, ArcHybrid.SHIFT) system.applyTransition(state, ArcHybrid.RIGHTARC) self.assertEqual(state.arcs.getHead(0), -1)
def testArcHybridWithLabels(self): system = ArcHybrid() labeler = MockLabeler(system, ["ROOT", "a", "b"]) correct = datatypes.Tree( [1, -1, 1, 1, 5, 6, 3, 6, 1], ["a", "ROOT", "a", "b", "b", "a", "a", "b", "a"]) soracle = ArcHybridStaticOracle(system, labeler) transitions = oracle.buildStaticCorrectTransitions( correct, labeler, soracle) predict = tdatatypes.buildTreeFromTransitions(labeler, correct.nrOfTokens(), transitions) self.assertEqual(predict, correct)
def testLeftArcRemove(self): """LeftArc removes the top-most token on the stack""" state = tdatatypes.State(5) system = ArcHybrid() system.applyTransition(state, ArcHybrid.SHIFT) self.assertEqual(state.stack.toList(), [-1, 0]) system.applyTransition(state, ArcHybrid.LEFTARC) self.assertEqual(state.stack.toList(), [-1])
def testRightArcRemove(self): """RightArcStandard removes the top-most token from the stack""" state = tdatatypes.State(5) system = ArcHybrid() system.applyTransition(state, ArcHybrid.SHIFT) self.assertEqual(state.stack.toList(), [-1, 0]) self.assertEqual(state.buffer.toList(), [1, 2, 3, 4]) system.applyTransition(state, ArcHybrid.RIGHTARC) self.assertEqual(state.stack.toList(), [-1]) self.assertEqual(state.buffer.toList(), [1, 2, 3, 4])