def test_mergedicsnodes(self): tree = Tree.parse( '(S (VP (VP (PP (APPR 0) (ART 1) (NN 2)) (CARD 4)' '(VVPP 5)) (VAINF 6)) (VMFIN 3))', parse_leaf=int) assert str(mergediscnodes(splitdiscnodes(tree))) == ( '(S (VP (VP (PP (APPR 0) (ART 1) (NN 2)) (CARD 4) (VVPP 5)) ' '(VAINF 6)) (VMFIN 3))') assert str(mergediscnodes(splitdiscnodes(tree, markorigin=True))) == ( '(S (VP (VP (PP (APPR 0) (ART 1) (NN 2)) (CARD 4) (VVPP 5)) ' '(VAINF 6)) (VMFIN 3))') tree = Tree.parse('(S (X (A 0) (A 2)) (X (A 1) (A 3)))', parse_leaf=int) assert str(mergediscnodes(splitdiscnodes( tree, markorigin=True))) == ('(S (X (A 0) (A 2)) (X (A 1) (A 3)))') tree = Tree.parse('(S (X (A 0) (A 2)) (X (A 1) (A 3)))', parse_leaf=int) assert str(splitdiscnodes(tree, markorigin=True)) == ( '(S (X*0 (A 0)) (X*0 (A 1)) (X*1 (A 2)) (X*1 (A 3)))') tree = Tree.parse('(S (X (A 0) (A 2)) (X (A 1) (A 3)))', parse_leaf=int) assert str(mergediscnodes( splitdiscnodes(tree))) == ('(S (X (A 0) (A 1) (A 2) (A 3)))')
def postprocess(self, treestr, stage=-1): """Take parse tree and apply postprocessing.""" parsetree = Tree.parse(treestr, parse_leaf=int) if self.stages[stage].split: mergediscnodes(unbinarize(parsetree, childchar=':', expandunary=False)) saveheads(parsetree, self.binarization.tailmarker) unbinarize(parsetree, expandunary=False) removefanoutmarkers(parsetree) if self.relationalrealizational: parsetree = rrbacktransform(parsetree, self.relationalrealizational['adjunctionlabel']) if self.transformations: reversetransform(parsetree, self.transformations) return parsetree, False
def postprocess(self, treestr, stage=-1, derivs=None): """ Take parse tree and apply postprocessing. """ parsetree = Tree.parse(treestr, parse_leaf=int) if self.stages[stage].split: mergediscnodes(unbinarize(parsetree, childchar=':')) saveheads(parsetree, self.tailmarker) unbinarize(parsetree) removefanoutmarkers(parsetree) if self.relationalrealizational: parsetree = rrbacktransform(parsetree, self.relationalrealizational['adjunctionlabel']) if self.transformations: reversetransform(parsetree, self.transformations) fragments = derivs.get(treestr) if derivs else None return parsetree, fragments, False
def test_mergedicsnodes(self): tree = Tree.parse('(S (VP (VP (PP (APPR 0) (ART 1) (NN 2)) (CARD 4)' '(VVPP 5)) (VAINF 6)) (VMFIN 3))', parse_leaf=int) assert str(mergediscnodes(splitdiscnodes(tree))) == ( '(S (VP (VP (PP (APPR 0) (ART 1) (NN 2)) (CARD 4) (VVPP 5)) ' '(VAINF 6)) (VMFIN 3))') assert str(mergediscnodes(splitdiscnodes(tree, markorigin=True))) == ( '(S (VP (VP (PP (APPR 0) (ART 1) (NN 2)) (CARD 4) (VVPP 5)) ' '(VAINF 6)) (VMFIN 3))') tree = Tree.parse('(S (X (A 0) (A 2)) (X (A 1) (A 3)))', parse_leaf=int) assert str(mergediscnodes(splitdiscnodes(tree, markorigin=True))) == ( '(S (X (A 0) (A 2)) (X (A 1) (A 3)))') tree = Tree.parse('(S (X (A 0) (A 2)) (X (A 1) (A 3)))', parse_leaf=int) assert str(splitdiscnodes(tree, markorigin=True)) == ( '(S (X*0 (A 0)) (X*0 (A 1)) (X*1 (A 2)) (X*1 (A 3)))') tree = Tree.parse('(S (X (A 0) (A 2)) (X (A 1) (A 3)))', parse_leaf=int) assert str(mergediscnodes(splitdiscnodes(tree))) == ( '(S (X (A 0) (A 1) (A 2) (A 3)))')
def test_splitdisc(): """Verify that splitting and merging discontinuities gives the same trees.""" from discodop.treebank import NegraCorpusReader correct = wrong = 0 corpus = NegraCorpusReader('alpinosample.export') for tree in corpus.trees().values(): if mergediscnodes(splitdiscnodes(tree)) == tree: correct += 1 else: wrong += 1 total = len(corpus.sents()) print('disc. split-merge: correct', correct, '=', 100. * correct / total, '%') print('disc. split-merge: wrong', wrong, '=', 100. * wrong / total, '%') assert wrong == 0