Пример #1
0
    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])
Пример #2
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
Пример #3
0
    def testChangesExample(self):
        """Example: changesExample"""

        system = ArcHybrid()
        tree = tdatatypes.buildTreeFromTransitions(
            system, changesExample[1].nrOfTokens(), changesCorrect)
        self.assertEqual(tree, changesExample[1])
Пример #4
0
    def testFranceExample(self):
        """Example: franceExample"""

        system = ArcHybrid()
        tree = tdatatypes.buildTreeFromTransitions(
            system, franceExample[1].nrOfTokens(), franceCorrect)
        self.assertEqual(tree, franceExample[1])
Пример #5
0
    def testMsCollinsExample(self):
        """Example: msCollinsExample"""

        system = ArcHybrid()
        tree = tdatatypes.buildTreeFromTransitions(
            system, msCollinsExample[1].nrOfTokens(), msCollinsCorrect)
        self.assertEqual(tree, msCollinsExample[1])
Пример #6
0
    def testOneWordExample(self):
        """Example: oneWordExample"""

        system = ArcHybrid()
        tree = tdatatypes.buildTreeFromTransitions(
            system, oneWordExample[1].nrOfTokens(), oneWordCorrect)
        self.assertEqual(tree, oneWordExample[1])
Пример #7
0
    def testChangesExample(self):
        """Example: changesExample"""

        system = ArcHybrid()
        soracle = ArcHybridStaticOracle(system)
        transitions = oracle.buildStaticCorrectTransitions(
            changesExample[1], system, soracle)
        self.assertEqual(changesCorrect, transitions)
Пример #8
0
    def testFranceExample(self):
        """Example: franceExample"""

        system = ArcHybrid()
        soracle = ArcHybridStaticOracle(system)
        transitions = oracle.buildStaticCorrectTransitions(
            franceExample[1], system, soracle)
        self.assertEqual(franceCorrect, transitions)
Пример #9
0
    def testOneWordExample(self):
        """Example: oneWordExample"""

        system = ArcHybrid()
        soracle = ArcHybridStaticOracle(system)
        transitions = oracle.buildStaticCorrectTransitions(
            oneWordExample[1], system, soracle)
        self.assertEqual(oneWordCorrect, transitions)
Пример #10
0
    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)
Пример #11
0
    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)
Пример #12
0
    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)
Пример #13
0
    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])
Пример #14
0
    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])