def testNonProjective_3(self): """long nonprojective tree""" tree = datatypes.Tree([ 3, 2, 14, 2, 5, 6, 3, 9, 9, 6, 14, 14, 13, 14, -1, 14, 14, 18, 14, 20, 18, 14 ]) self.assertFalse(tree.isProjective())
def testNonProjective_2(self): """very long nonprojective tree""" tree = datatypes.Tree([ 3, 3, 3, 4, -1, 7, 7, 4, 4, 10, 4, 10, 11, 15, 15, 12, 15, 20, 20, 20, 16, 20, 25, 25, 25, 20, 4, 4, 27, 28, 31, 29, 31, 32, 35, 33, 35, 36, 37, 38, 45, 40, 43, 44, 35, 44, 45, 46, 49, 47, 46, 53, 53, 50, 53, 54, 55, 56, 59, 56, 59, 62, 60, 4 ]) self.assertFalse(tree.isProjective())
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 testMimicSystemWithOneLabel_franceExample(self): correctTree = datatypes.Tree([-1, 0, 0, 0, 0, 0], ["ROOT", "a", "b", "c", "d", "e"]) correctTrans = [ ArcStandard.SHIFT, ArcStandard.SHIFT, ArcStandard.RIGHTARC, ArcStandard.SHIFT, ArcStandard.RIGHTARC, ArcStandard.SHIFT, ArcStandard.RIGHTARC, ArcStandard.SHIFT, ArcStandard.RIGHTARC, ArcStandard.SHIFT, ArcStandard.RIGHTARC, ArcStandard.RIGHTARC ] mocksystem = MockArcStandard() labeler = MockLabeler(mocksystem, ["ROOT", "a", "b", "c", "d", "e"]) soracle = ArcStandardStaticOracle(mocksystem, labeler) labtransitions = oracle.buildStaticCorrectTransitions( correctTree, labeler, soracle) # internal transitions self.assertEqual(mocksystem.transitions, correctTrans) # applying labeled transitions predTree = tdatatypes.buildTreeFromTransitions( labeler, correctTree.nrOfTokens(), labtransitions) self.assertEqual(str(predTree), str(correctTree))
''' Created on 17.07.2018 @author: falensaa ''' from tools import datatypes oneWordExample = ("Collins", datatypes.Tree([-1])) msCollinsExample = (" Or was it because Ms. Collins had gone ?", datatypes.Tree([1, -1, 1, 1, 5, 6, 3, 6, 1])) franceExample = (" In France ? ? ! !", datatypes.Tree([-1, 0, 0, 0, 0, 0])) chamberMusicExample = ("Is this the future of chamber music ?", datatypes.Tree([-1, 0, 3, 0, 3, 6, 4, 0])) changesExample = ("Not all those who wrote oppose the changes .", datatypes.Tree([1, 5, 1, 4, 1, -1, 7, 5, 5])) # non-projective hearingExample = ("A hearing is scheduled on the issue today .", datatypes.Tree([1, 2, -1, 2, 1, 6, 4, 3, 2])) afterExample = ("That 's they 're what after", datatypes.Tree([1, -1, 5, 4, 1, 4])) letterExample = ("Who did you send the letter to ?", datatypes.Tree([6, -1, 1, 1, 5, 3, 3, 1]))
def testGetHead_rootDep(self): tree = datatypes.Tree([-1, 0, 0, 1], ["a", "b", "c", "d"]) self.assertEqual(tree.getHead(-1), None)
def testHasArc_rootDep(self): tree = datatypes.Tree([-1, 0, 0, 1]) self.assertFalse(tree.hasArc(1, -1))
def testProjective_3(self): """short projective tree v. 2""" tree = datatypes.Tree([1, 5, 1, 4, 1, -1, 7, 5, 5]) self.assertTrue(tree.isProjective())
def testProjective_2(self): """short projective tree v. 1""" tree = datatypes.Tree([1, -1, 1, 1, 5, 6, 3, 6, 1]) self.assertTrue(tree.isProjective())
def testProjective_1(self): """one word tree""" tree = datatypes.Tree([-1]) self.assertTrue(tree.isProjective())
def testNonProjective_shortestRight(self): """shortest nonprojective tree with right non projective arc""" tree = datatypes.Tree([-1, 0, 0, 1]) self.assertFalse(tree.isProjective())
def testNonProjective_shortestLeft(self): """shortest nonprojective tree with left non projective arc""" tree = datatypes.Tree([-1, 3, 0, 0]) self.assertFalse(tree.isProjective())
def testNonProjective_1(self): """short nonprojective tree with one nonprojective arc""" tree = datatypes.Tree([5, -1, 3, 1, 3, 1, 1]) self.assertFalse(tree.isProjective())
def __buildTree(self, heads): predictTree = datatypes.Tree([el - 1 for el in heads[1:]]) return predictTree
def buildTree(self): return datatypes.Tree(self.arcs, self.labels)