Esempio n. 1
0
    def testLeftArcIsNotValidWithRoot(self):
        """invalid left when second item on the stack is root"""

        state = tdatatypes.State(5)
        system = ArcStandard()
        system.applyTransition(state, ArcStandard.SHIFT)
        self.assertFalse(system.isValidTransition(state, ArcStandard.LEFTARC))
Esempio n. 2
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 = ArcStandard()

        system.applyTransition(state, ArcStandard.SHIFT)

        self.assertEqual(state.buffer.toList(), [1, 2, 3, 4])
        self.assertEqual(state.stack.toList(), [-1, 0])
Esempio n. 3
0
    def testChangesExample(self):
        """Example: changesExample"""

        system = ArcStandard()
        tree = tdatatypes.buildTreeFromTransitions(
            system, changesExample[1].nrOfTokens(), changesCorrect)
        self.assertEqual(tree, changesExample[1])
Esempio n. 4
0
    def testFranceExample(self):
        """Example: franceExample"""

        system = ArcStandard()
        tree = tdatatypes.buildTreeFromTransitions(
            system, franceExample[1].nrOfTokens(), franceCorrect)
        self.assertEqual(tree, franceExample[1])
Esempio n. 5
0
    def testMsCollinsExample(self):
        """Example: msCollinsExample"""

        system = ArcStandard()
        tree = tdatatypes.buildTreeFromTransitions(
            system, msCollinsExample[1].nrOfTokens(), msCollinsCorrect)
        self.assertEqual(tree, msCollinsExample[1])
Esempio n. 6
0
    def testOneWordExample(self):
        """Example: oneWordExample"""

        system = ArcStandard()
        tree = tdatatypes.buildTreeFromTransitions(
            system, oneWordExample[1].nrOfTokens(), oneWordCorrect)
        self.assertEqual(tree, oneWordExample[1])
Esempio n. 7
0
    def testChangesExample(self):
        """Example: changesExample"""

        system = ArcStandard()
        soracle = ArcStandardStaticOracle(system)
        transitions = oracle.buildStaticCorrectTransitions(
            changesExample[1], system, soracle)
        self.assertEqual(changesCorrect, transitions)
Esempio n. 8
0
    def testFranceExample(self):
        """Example: franceExample"""

        system = ArcStandard()
        soracle = ArcStandardStaticOracle(system)
        transitions = oracle.buildStaticCorrectTransitions(
            franceExample[1], system, soracle)
        self.assertEqual(franceCorrect, transitions)
Esempio n. 9
0
    def testOneWordExample(self):
        """Example: oneWordExample"""

        system = ArcStandard()
        soracle = ArcStandardStaticOracle(system)
        transitions = oracle.buildStaticCorrectTransitions(
            oneWordExample[1], system, soracle)
        self.assertEqual(oneWordCorrect, transitions)
Esempio n. 10
0
    def testRightArcHead(self):
        """RightArcStandard introduces an arc from the top-most token on the stack to the second one"""

        state = tdatatypes.State(5)
        system = ArcStandard()
        system.applyTransition(state, ArcStandard.SHIFT)
        system.applyTransition(state, ArcStandard.RIGHTARC)
        self.assertEqual(state.arcs.getHead(0), -1)
Esempio n. 11
0
    def testLeftArcHead(self):
        """LeftArc introduces an arc from the second to the first item on the stack"""

        state = tdatatypes.State(5)
        system = ArcStandard()
        system.applyTransition(state, ArcStandard.SHIFT)
        system.applyTransition(state, ArcStandard.SHIFT)
        system.applyTransition(state, ArcStandard.LEFTARC)
        self.assertEqual(state.arcs.getHead(0), 1)
Esempio n. 12
0
    def testLeftArcRemove(self):
        """LeftArc removes the second token on the stack"""

        state = tdatatypes.State(5)
        system = ArcStandard()
        system.applyTransition(state, ArcStandard.SHIFT)

        self.assertEqual(state.stack.toList(), [-1, 0])
        system.applyTransition(state, ArcStandard.LEFTARC)
        self.assertEqual(state.stack.toList(), [0])
Esempio n. 13
0
    def testArcStandardWithLabels(self):
        system = ArcStandard()
        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 = ArcStandardStaticOracle(system, labeler)
        transitions = oracle.buildStaticCorrectTransitions(
            correct, labeler, soracle)

        predict = tdatatypes.buildTreeFromTransitions(labeler,
                                                      correct.nrOfTokens(),
                                                      transitions)
        self.assertEqual(predict, correct)
Esempio n. 14
0
    def testRightArcRemove(self):
        """RightArcStandard removes the top-most token from the stack"""

        state = tdatatypes.State(5)
        system = ArcStandard()
        system.applyTransition(state, ArcStandard.SHIFT)

        self.assertEqual(state.stack.toList(), [-1, 0])
        self.assertEqual(state.buffer.toList(), [1, 2, 3, 4])

        system.applyTransition(state, ArcStandard.RIGHTARC)

        self.assertEqual(state.stack.toList(), [-1])
        self.assertEqual(state.buffer.toList(), [1, 2, 3, 4])
Esempio n. 15
0
 def applyTransition(self, state, tId):
     self.transitions.append(tId)
     return ArcStandard.applyTransition(self, state, tId)
Esempio n. 16
0
    def testFinalConfigurationBufferEmpty(self):
        """final configuration - with empty buffer"""

        state = tdatatypes.State(0)
        system = ArcStandard()
        self.assertTrue(system.isFinal(state))
Esempio n. 17
0
    def testFinalConfigurationBufferNonEmpty(self):
        """configuration with full buffer is not final"""

        state = tdatatypes.State(5)
        system = ArcStandard()
        self.assertFalse(system.isFinal(state))