Example #1
0
    def test_flatten(self):
        ids = UniqueIDs()
        assert flatten('(ROOT (S_2 0= 2=) (ROOT|<$,>_2 ($, 1=,) ($. 3=.)))',
                       ids, {}, True) == ([
                           (('ROOT', 'ROOT}<0>', '$.@.'), ((0, 1), )),
                           (('ROOT}<0>', 'S_2', '$,@,'), ((0, 1, 0), )),
                           (('$,@,', 'Epsilon'), (',', )),
                           (('$.@.', 'Epsilon'), ('.', ))
                       ], '(ROOT {0} (ROOT|<$,>_2 {1} {2}))')

        assert flatten("(NN 0=foo)", ids, {},
                       True) == ([(('NN', 'Epsilon'), ('foo', ))], '(NN 0)')

        prods, frag = flatten(
            r"(S (S|<VP> (S|<NP> (NP (ART 0=Das) (CNP "
            "(CNP|<TRUNC> (TRUNC 1=Garten-) (CNP|<KON> (KON 2=und) "
            "(CNP|<NN> (NN 3=Friedhofsamt)))))) (S|<VAFIN> "
            "(VAFIN 4=hatte))) (VP (VP|<ADV> (ADV 5=kuerzlich) "
            "(VP|<NP> (NP (ART 6=dem) (NN 7=Ortsbeirat)) (VP|<NP> "
            "(NP_2 8= 10=) (VP|<VVPP> (VVPP 9=))))))))", ids, {}, True)
        assert prods == [(('S', 'S}<8>_2', 'VVPP'), ((0, 1, 0), )),
                         (('S}<8>_2', 'S}<7>', 'NP_2'), ((0, 1), (1, ))),
                         (('S}<7>', 'S}<6>', 'NN@Ortsbeirat'), ((0, 1), )),
                         (('S}<6>', 'S}<5>', 'ART@dem'), ((0, 1), )),
                         (('S}<5>', 'S}<4>', 'ADV@kuerzlich'), ((0, 1), )),
                         (('S}<4>', 'S}<3>', 'VAFIN@hatte'), ((0, 1), )),
                         (('S}<3>', 'S}<2>', 'NN@Friedhofsamt'), ((0, 1), )),
                         (('S}<2>', 'S}<1>', 'KON@und'), ((0, 1), )),
                         (('S}<1>', 'ART@Das', 'TRUNC@Garten-'), ((0, 1), )),
                         (('ART@Das', 'Epsilon'), ('Das', )),
                         (('TRUNC@Garten-', 'Epsilon'), ('Garten-', )),
                         (('KON@und', 'Epsilon'), ('und', )),
                         (('NN@Friedhofsamt', 'Epsilon'), ('Friedhofsamt', )),
                         (('VAFIN@hatte', 'Epsilon'), ('hatte', )),
                         (('ADV@kuerzlich', 'Epsilon'), ('kuerzlich', )),
                         (('ART@dem', 'Epsilon'), ('dem', )),
                         (('NN@Ortsbeirat', 'Epsilon'), ('Ortsbeirat', ))]
        assert frag == (
            '(S (S|<VP> (S|<NP> (NP {0} (CNP (CNP|<TRUNC> {1} (CNP|<KON> '
            '{2} (CNP|<NN> {3}))))) (S|<VAFIN> {4})) (VP (VP|<ADV> {5} '
            '(VP|<NP> (NP {6} {7}) (VP|<NP> {8} (VP|<VVPP> {9})))))))')

        assert flatten(
            "(S|<VP>_2 (VP_3 (VP|<NP>_3 (NP 0=) (VP|<ADV>_2 "
            "(ADV 2=) (VP|<VVPP> (VVPP 4=))))) (S|<VAFIN> (VAFIN 1=)))", ids,
            {}, True) == ([
                (('S|<VP>_2', 'S|<VP>_2}<10>', 'VVPP'), ((0, ), (1, ))),
                (('S|<VP>_2}<10>', 'S|<VP>_2}<9>', 'ADV'), ((0, 1), )),
                (('S|<VP>_2}<9>', 'NP', 'VAFIN'), ((0, 1), ))
            ], '(S|<VP>_2 (VP_3 (VP|<NP>_3 {0} (VP|<ADV>_2 {2} (VP|<VVPP> '
                          '{3})))) (S|<VAFIN> {1}))')
Example #2
0
	def test_flatten(self):
		ids = UniqueIDs()
		sent = [None, ',', None, '.']
		tree = "(ROOT (S_2 0 2) (ROOT|<$,>_2 ($, 1) ($. 3)))"
		assert flatten(tree, sent, ids, {}, True) == (
				[(('ROOT', 'ROOT}<0>', '$.@.'), ((0, 1),)),
				(('ROOT}<0>', 'S_2', '$,@,'), ((0, 1, 0),)),
				(('$,@,', 'Epsilon'), (',',)), (('$.@.', 'Epsilon'), ('.',))],
				'(ROOT {0} (ROOT|<$,>_2 {1} {2}))')

		assert flatten("(NN 0)", ["foo"], ids, {}, True) == (
				[(('NN', 'Epsilon'), ('foo',))], '(NN 0)')

		prods, frag = flatten(r"(S (S|<VP> (S|<NP> (NP (ART 0) (CNP "
				"(CNP|<TRUNC> (TRUNC 1) (CNP|<KON> (KON 2) (CNP|<NN> "
				"(NN 3)))))) (S|<VAFIN> (VAFIN 4))) (VP (VP|<ADV> (ADV 5) "
				"(VP|<NP> (NP (ART 6) (NN 7)) (VP|<NP> (NP_2 8 10) (VP|<VVPP> "
				"(VVPP 9))))))))",
				['Das', 'Garten-', 'und', 'Friedhofsamt', 'hatte', 'kuerzlich',
				'dem', 'Ortsbeirat', None, None, None], ids, {}, True)
		assert prods == [(('S', 'S}<8>_2', 'VVPP'), ((0, 1, 0),)),
				(('S}<8>_2', 'S}<7>', 'NP_2'), ((0, 1), (1,))),
				(('S}<7>', 'S}<6>', 'NN@Ortsbeirat'), ((0, 1),)),
				(('S}<6>', 'S}<5>', 'ART@dem'), ((0, 1),)),
				(('S}<5>', 'S}<4>', 'ADV@kuerzlich'), ((0, 1),)),
				(('S}<4>', 'S}<3>', 'VAFIN@hatte'), ((0, 1),)),
				(('S}<3>', 'S}<2>', 'NN@Friedhofsamt'), ((0, 1),)),
				(('S}<2>', 'S}<1>', 'KON@und'), ((0, 1),)),
				(('S}<1>', 'ART@Das', 'TRUNC@Garten-'), ((0, 1),)),
				(('ART@Das', 'Epsilon'), ('Das',)),
				(('TRUNC@Garten-', 'Epsilon'), ('Garten-',)),
				(('KON@und', 'Epsilon'), ('und',)),
				(('NN@Friedhofsamt', 'Epsilon'), ('Friedhofsamt',)),
				(('VAFIN@hatte', 'Epsilon'), ('hatte',)),
				(('ADV@kuerzlich', 'Epsilon'), ('kuerzlich',)),
				(('ART@dem', 'Epsilon'), ('dem',)),
				(('NN@Ortsbeirat', 'Epsilon'), ('Ortsbeirat',))]
		assert frag == (
				'(S (S|<VP> (S|<NP> (NP {0} (CNP (CNP|<TRUNC> {1} (CNP|<KON> '
				'{2} (CNP|<NN> {3}))))) (S|<VAFIN> {4})) (VP (VP|<ADV> {5} '
				'(VP|<NP> (NP {6} {7}) (VP|<NP> {8} (VP|<VVPP> {9})))))))')

		assert flatten("(S|<VP>_2 (VP_3 (VP|<NP>_3 (NP 0) (VP|<ADV>_2 "
				"(ADV 2) (VP|<VVPP> (VVPP 4))))) (S|<VAFIN> (VAFIN 1)))",
				(None, None, None, None, None), ids, {}, True) == (
				[(('S|<VP>_2', 'S|<VP>_2}<10>', 'VVPP'), ((0,), (1,))),
				(('S|<VP>_2}<10>', 'S|<VP>_2}<9>', 'ADV'), ((0, 1),)),
				(('S|<VP>_2}<9>', 'NP', 'VAFIN'), ((0, 1),))],
				'(S|<VP>_2 (VP_3 (VP|<NP>_3 {0} (VP|<ADV>_2 {2} (VP|<VVPP> '
				'{3})))) (S|<VAFIN> {1}))')
Example #3
0
	def test_flatten(self):
		ids = UniqueIDs()
		assert flatten(
				'(ROOT (S_2 0= 2=) (ROOT|<$,>_2 ($, 1=,) ($. 3=.)))',
				ids, {}, True) == (
				[(('ROOT', 'ROOT}<0>', '$.@.'), ((0, 1),)),
				(('ROOT}<0>', 'S_2', '$,@,'), ((0, 1, 0),)),
				(('$,@,', 'Epsilon'), (',',)), (('$.@.', 'Epsilon'), ('.',))],
				'(ROOT {0} (ROOT|<$,>_2 {1} {2}))')

		assert flatten("(NN 0=foo)", ids, {}, True) == (
				[(('NN', 'Epsilon'), ('foo',))], '(NN 0)')

		prods, frag = flatten(r"(S (S|<VP> (S|<NP> (NP (ART 0=Das) (CNP "
				"(CNP|<TRUNC> (TRUNC 1=Garten-) (CNP|<KON> (KON 2=und) "
				"(CNP|<NN> (NN 3=Friedhofsamt)))))) (S|<VAFIN> "
				"(VAFIN 4=hatte))) (VP (VP|<ADV> (ADV 5=kuerzlich) "
				"(VP|<NP> (NP (ART 6=dem) (NN 7=Ortsbeirat)) (VP|<NP> "
				"(NP_2 8= 10=) (VP|<VVPP> (VVPP 9=))))))))",
				ids, {}, True)
		assert prods == [(('S', 'S}<8>_2', 'VVPP'), ((0, 1, 0),)),
				(('S}<8>_2', 'S}<7>', 'NP_2'), ((0, 1), (1,))),
				(('S}<7>', 'S}<6>', 'NN@Ortsbeirat'), ((0, 1),)),
				(('S}<6>', 'S}<5>', 'ART@dem'), ((0, 1),)),
				(('S}<5>', 'S}<4>', 'ADV@kuerzlich'), ((0, 1),)),
				(('S}<4>', 'S}<3>', 'VAFIN@hatte'), ((0, 1),)),
				(('S}<3>', 'S}<2>', 'NN@Friedhofsamt'), ((0, 1),)),
				(('S}<2>', 'S}<1>', 'KON@und'), ((0, 1),)),
				(('S}<1>', 'ART@Das', 'TRUNC@Garten-'), ((0, 1),)),
				(('ART@Das', 'Epsilon'), ('Das',)),
				(('TRUNC@Garten-', 'Epsilon'), ('Garten-',)),
				(('KON@und', 'Epsilon'), ('und',)),
				(('NN@Friedhofsamt', 'Epsilon'), ('Friedhofsamt',)),
				(('VAFIN@hatte', 'Epsilon'), ('hatte',)),
				(('ADV@kuerzlich', 'Epsilon'), ('kuerzlich',)),
				(('ART@dem', 'Epsilon'), ('dem',)),
				(('NN@Ortsbeirat', 'Epsilon'), ('Ortsbeirat',))]
		assert frag == (
				'(S (S|<VP> (S|<NP> (NP {0} (CNP (CNP|<TRUNC> {1} (CNP|<KON> '
				'{2} (CNP|<NN> {3}))))) (S|<VAFIN> {4})) (VP (VP|<ADV> {5} '
				'(VP|<NP> (NP {6} {7}) (VP|<NP> {8} (VP|<VVPP> {9})))))))')

		assert flatten("(S|<VP>_2 (VP_3 (VP|<NP>_3 (NP 0=) (VP|<ADV>_2 "
				"(ADV 2=) (VP|<VVPP> (VVPP 4=))))) (S|<VAFIN> (VAFIN 1=)))",
				ids, {}, True) == (
				[(('S|<VP>_2', 'S|<VP>_2}<10>', 'VVPP'), ((0,), (1,))),
				(('S|<VP>_2}<10>', 'S|<VP>_2}<9>', 'ADV'), ((0, 1),)),
				(('S|<VP>_2}<9>', 'NP', 'VAFIN'), ((0, 1),))],
				'(S|<VP>_2 (VP_3 (VP|<NP>_3 {0} (VP|<ADV>_2 {2} (VP|<VVPP> '
				'{3})))) (S|<VAFIN> {1}))')