示例#1
0
 def test_empty(self):
     x = Xmrs()
     assert x.top is None
     assert x.index is None
     assert x.xarg is None
     assert len(x.eps()) == 0
     assert len(x.hcons()) == 0
     assert len(x.icons()) == 0
     assert len(x.variables()) == 0
示例#2
0
 def test_empty(self):
     x = Xmrs()
     assert x.top is None
     assert x.index is None
     assert x.xarg is None
     assert len(x.nodeids()) == 0
     assert len(x.eps()) == 0
     assert len(x.hcons()) == 0
     assert len(x.icons()) == 0
     assert len(x.variables()) == 0
示例#3
0
 def test_variables_and_properties(self):
     sp = Pred.surface
     # variables can be passed in with properties
     x = Xmrs(vars={'x1':{'PERS':'3','NUM':'sg'}, 'e2':{'SF':'prop'}})
     assert len(x.variables()) == 2
     assert x.properties('x1')['PERS'] == '3'
     assert x.properties('e2')['SF'] == 'prop'
     # when there's no EP, you cannot retrieve properties via a nodeid
     with pytest.raises(KeyError): x.properties(10)
     # but when an EP with an ARG0 exists, you can
     x.add_eps([(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x1'})])
     assert x.properties(10) == {'PERS': '3', 'NUM': 'sg'}
     # variables can also be inferred from structural things
     x = Xmrs(top='h0', index='e2', xarg='e5')
     assert set(x.variables()) == {'h0', 'e2', 'e5'}
     x = Xmrs(eps=[(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})])
     assert set(x.variables()) == {'x4', 'h3'}
     x = Xmrs(hcons=[('h0', 'qeq', 'h1')])
     assert set(x.variables()) == {'h0', 'h1'}
     x = Xmrs(icons=[('x4', 'focus', 'x6')])
     assert set(x.variables()) == {'x4', 'x6'}
     # variables can be passed in and inferred
     x = Xmrs(icons=[('x4', 'focus', 'x6')], vars={'x4': {'PERS': '3'}})
     assert set(x.variables()) == {'x4', 'x6'}
     assert x.properties('x4') == {'PERS': '3'}
     assert x.properties('x6') == {}
     # adding things later doesn't reset properties
     x = Xmrs(vars={'x4': {'PERS': '3'}})
     x.add_eps([(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})])
     assert set(x.variables()) == {'x4', 'h3'}
     assert x.properties('x4') == {'PERS': '3'}
     # and properties can't be added via properties()
     x.properties('x4')['NUM'] = 'sg'
     assert x.properties('x4') == {'PERS': '3'}
     # TODO: how do we add properties?
     # constants are not variables
     x = Xmrs(eps=[(10, sp('_v_v_rel'), 'h3',
                    {'ARG0': 'e2', 'CARG': '"dog"'})])
     assert set(x.variables()) == {'e2', 'h3'}
     # Constants don't need to be the CARG role, and don't need
     # quotes (but if there are quotes, even var-looking things are
     # constants). pyDelphin differs from the LKB in the first
     # respect, but also maybe in the second.
     x = Xmrs(eps=[(10, sp('_v_v_rel'), 'h3',
                    {'ARG0': 'e2', 'ARG1': '1', 'ARG2': '"x5"'})])
     assert set(x.variables()) == {'h3', 'e2'}
示例#4
0
 def test_variables_and_properties(self):
     sp = Pred.stringpred
     # variables can be passed in with properties
     x = Xmrs(vars={'x1':{'PERS':'3','NUM':'sg'}, 'e2':{'SF':'prop'}})
     assert len(x.variables()) == 2
     assert x.properties('x1')['PERS'] == '3'
     assert x.properties('e2')['SF'] == 'prop'
     # when there's no EP, you cannot retrieve properties via a nodeid
     with pytest.raises(KeyError): x.properties(10)
     # but when an EP with an ARG0 exists, you can
     x.add_eps([(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x1'})])
     assert x.properties(10) == {'PERS': '3', 'NUM': 'sg'}
     # variables can also be inferred from structural things
     x = Xmrs(top='h0', index='e2', xarg='e5')
     assert set(x.variables()) == {'h0', 'e2', 'e5'}
     x = Xmrs(eps=[(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})])
     assert set(x.variables()) == {'x4', 'h3'}
     x = Xmrs(hcons=[('h0', 'qeq', 'h1')])
     assert set(x.variables()) == {'h0', 'h1'}
     x = Xmrs(icons=[('x4', 'focus', 'x6')])
     assert set(x.variables()) == {'x4', 'x6'}
     # variables can be passed in and inferred
     x = Xmrs(icons=[('x4', 'focus', 'x6')], vars={'x4': {'PERS': '3'}})
     assert set(x.variables()) == {'x4', 'x6'}
     assert x.properties('x4') == {'PERS': '3'}
     assert x.properties('x6') == {}
     # adding things later doesn't reset properties
     x = Xmrs(vars={'x4': {'PERS': '3'}})
     x.add_eps([(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})])
     assert set(x.variables()) == {'x4', 'h3'}
     assert x.properties('x4') == {'PERS': '3'}
     # and properties can't be added via properties()
     x.properties('x4')['NUM'] = 'sg'
     assert x.properties('x4') == {'PERS': '3'}
     # TODO: how do we add properties?
     # constants are not variables
     x = Xmrs(eps=[(10, sp('_v_v_rel'), 'h3',
                    {'ARG0': 'e2', 'CARG': '"dog"'})])
     assert set(x.variables()) == {'e2', 'h3'}
     # Constants don't need to be the CARG role, and don't need
     # quotes (but if there are quotes, even var-looking things are
     # constants). pyDelphin differs from the LKB in the first
     # respect, but also maybe in the second.
     x = Xmrs(eps=[(10, sp('_v_v_rel'), 'h3',
                    {'ARG0': 'e2', 'ARG1': '1', 'ARG2': '"x5"'})])
     assert set(x.variables()) == {'h3', 'e2'}