def test_find_argument_target(): assert query.find_argument_target(m, 10000, 'RSTR') == 10002 assert query.find_argument_target(m, 10001, 'ARG1') == 10002 assert query.find_argument_target(m, 10003, 'ARG2') == 10005 # test CARGs and unbound vars: "Abrams tried." m2 = Xmrs( top='h0', eps=[ EP(10000, sp('proper_q_rel'), 'h4', { 'ARG0': 'x3', 'RSTR': 'h5' }), EP(10001, sp('named_rel'), 'h7', { 'ARG0': 'x3', 'CARG': 'Abrams' }), EP(10002, sp('"_try_v_1_rel"'), 'h1', { 'ARG0': 'e2', 'ARG1': 'x3', 'ARG2': 'i9' }), ], hcons=[qeq('h0', 'h1'), qeq('h5', 'h7')], ) assert query.find_argument_target(m2, 10001, 'CARG') == 'Abrams' assert query.find_argument_target(m2, 10002, 'ARG2') == 'i9'
def test_construct(self): with pytest.raises(TypeError): EP() with pytest.raises(TypeError): EP(10) with pytest.raises(TypeError): EP(10, spred('_dog_n_rel')) e = EP(10, spred('_dog_n_rel'), 'h1') assert e.nodeid == 10 assert e.pred == '_dog_n_rel' assert e.label == 'h1'
def test_is_quantifier(self): e = EP(10, spred('_the_q_rel'), 'h1', args={RSTR_ROLE: 'h2'}) assert e.is_quantifier() == True # not a q pred, but has RSTR e = EP(10, spred('_dog_n_rel'), 'h1', args={RSTR_ROLE: 'h2'}) assert e.is_quantifier() == True # a q pred, but no RSTR e = EP(10, spred('_the_q_rel'), 'h1', args={}) assert e.is_quantifier() == False
def test_args(self): p = spred('_chase_v_rel') lbl = 'h1' e = EP(11, p, lbl) assert len(e.args) == 0 v1 = 'e2' e = EP(11, p, lbl, args={IVARG_ROLE: v1}) assert len(e.args) == 1 assert e.args[IVARG_ROLE] == v1 v2 = 'x3' e = EP(11, p, lbl, args={IVARG_ROLE: v1, 'ARG1': v2}) assert len(e.args) == 2 assert e.args[IVARG_ROLE] == v1 assert e.args['ARG1'] == v2
def test_from_dict(self): assert Mrs.from_dict({}) == Mrs() m1 = Mrs.from_dict({ 'relations': [{ 'label': 'h1', 'predicate': '_rain_v_1', 'arguments': { 'ARG0': 'e2' } }], 'constraints': [], 'variables': { 'h1': { 'type': 'h' }, 'e2': { 'type': 'e' } } }) m2 = Mrs(rels=[ EP(FIRST_NODEID, sp('"_rain_v_1_rel"'), 'h1', {'ARG0': 'e2'}) ]) assert m1 == m2
def test_to_dict(self): assert Mrs().to_dict() == { 'relations': [], 'constraints': [], 'variables': {} } x = Mrs(rels=[EP(10, sp('"_rain_v_1_rel"'), 'h1', {'ARG0': 'e2'})]) assert x.to_dict() == { 'relations': [ {'label': 'h1', 'predicate': '_rain_v_1', 'arguments': {'ARG0': 'e2'}} ], 'constraints': [], 'variables': {'h1': {'type': 'h'}, 'e2': {'type': 'e'}} } x = Mrs( top='h0', rels=[EP(10, sp('"_rain_v_1_rel"'), 'h1', {'ARG0': 'e2'})], hcons=[('h0', 'qeq', 'h1')], vars={'e2': {'SF': 'prop', 'TENSE': 'pres'}} ) assert x.to_dict() == { 'top': 'h0', 'relations': [ {'label': 'h1', 'predicate': '_rain_v_1', 'arguments': {'ARG0': 'e2'}} ], 'constraints': [{'relation': 'qeq', 'high': 'h0', 'low': 'h1'}], 'variables': { 'h0': {'type': 'h'}, 'h1': {'type': 'h'}, 'e2': {'type': 'e', 'properties': {'SF': 'prop', 'TENSE': 'pres'}} } } assert x.to_dict(properties=False) == { 'top': 'h0', 'relations': [ {'label': 'h1', 'predicate': '_rain_v_1', 'arguments': {'ARG0': 'e2'}} ], 'constraints': [{'relation': 'qeq', 'high': 'h0', 'low': 'h1'}], 'variables': { 'h0': {'type': 'h'}, 'h1': {'type': 'h'}, 'e2': {'type': 'e'} } }
def test_single_ep(self): # basic, one EP, no TOP x = Mrs(rels=[EP(10, sp('"_rain_v_1_rel"'), 'h1')]) check_xmrs(x, None, None, None, 1, 0, 0, 1) # variables don't need to be created predictably, but it's nice # to get the expected values for simple cases assert x.label(10) == 'h1' assert x.ep(10).iv == None # now with ARG0 x = Mrs(rels=[EP(10, sp('"_rain_v_1_rel"'), 'h1', {'ARG0': 'e2'})]) check_xmrs(x, None, None, None, 1, 0, 0, 2) assert x.label(10) == 'h1' assert x.ep(10).iv == 'e2' # now with TOP x = Mrs(top='h0', rels=[EP(10, sp('"_rain_v_1_rel"'), 'h1', {'ARG0': 'e2'})], hcons=[('h0', 'qeq', 'h1')]) check_xmrs(x, 'h0', None, None, 1, 1, 0, 3) assert x.label(10) == 'h1' assert x.ep(10).iv == 'e2'
from delphin.mrs.xmrs import Xmrs from delphin.mrs.components import ElementaryPredication as EP, Pred from delphin.mrs import query sp = Pred.surface qeq = lambda hi, lo: (hi, 'qeq', lo) # "Cats are chased by big dogs." (reordered, but equivalent) m = Xmrs(top='h0', eps=[ EP(10000, sp('udef_q_rel'), 'h4', { 'ARG0': 'x3', 'RSTR': 'h5' }), EP(10001, sp('"_big_a_1_rel"'), 'h7', { 'ARG0': 'e8', 'ARG1': 'x3' }), EP(10002, sp('"_dog_n_1_rel"'), 'h7', {'ARG0': 'x3'}), EP(10003, sp('"_chase_v_1_rel"'), 'h1', { 'ARG0': 'e2', 'ARG1': 'x3', 'ARG2': 'x9' }), EP(10004, sp('udef_q_rel'), 'h10', { 'ARG0': 'x9', 'RSTR': 'h11' }), EP(10005, sp('"_cat_n_1_rel"'), 'h13', {'ARG0': 'x9'}) ], hcons=[qeq('h0', 'h1'),
from delphin.mrs import xmrs, path as mp from delphin.mrs.components import Pred, ElementaryPredication as EP sp = Pred.surface def qeq(hi, lo): return (hi, 'qeq', lo) m0 = xmrs.Xmrs() # "It rains." m1 = xmrs.Xmrs(top='h0', eps=[EP(10000, sp('"_rain_v_1_rel"'), 'h1', {'ARG0': 'e2'})], hcons=[qeq('h0', 'h1')]) # "Big dogs bark." m2 = xmrs.Xmrs(top='h0', eps=[ EP(10000, sp('udef_q_rel'), 'h4', { 'ARG0': 'x3', 'RSTR': 'h5' }), EP(10001, sp('"_big_a_1_rel"'), 'h7', { 'ARG0': 'e8', 'ARG1': 'x3' }), EP(10002, sp('"_dog_n_1_rel"'), 'h7', {'ARG0': 'x3'}), EP(10003, sp('"_bark_v_1_rel"'), 'h1', { 'ARG0': 'e2',
Node, ElementaryPredication as EP ) spred = Pred.stringpred from delphin.mrs.xmrs import Xmrs from delphin.mrs.config import ( CVARSORT, IVARG_ROLE, CONSTARG_ROLE, EQ_POST, HEQ_POST, NEQ_POST, H_POST, NIL_POST, LTOP_NODEID, FIRST_NODEID ) # store some example MRSs for later tests (note, some are made by hand) # just a verb; e.g. "it rains" x1 = Xmrs( top='h0', eps=[EP(10000, spred('_rain_v_1_rel'), 'h1', {'ARG0': 'e2'})], hcons=[('h0', 'qeq', 'h1')] ) # modified verb, e.g. "it rains heavily" x2 = Xmrs( top='h0', eps=[ EP(10000, spred('_rain_v_1_rel'), 'h1', {'ARG0': 'e2'}), EP(10001, spred('_heavy_a_1_rel'), 'h1', {'ARG0': 'e4', 'ARG1': 'e2'}) ], hcons=[('h0', 'qeq', 'h1')] ) # Verb and noun with quantifier; e.g. "the dog barks" x3 = Xmrs( top='h0',