def test_hcon(self): x = Xmrs() with pytest.raises(TypeError): x.hcon() with pytest.raises(KeyError): x.hcon('h0') x.add_hcons([('h0', 'qeq', 'h1')]) assert x.hcon('h0') == ('h0', 'qeq', 'h1') with pytest.raises(KeyError): x.hcon('h1')
def test_hcons(self): x = Xmrs() assert len(x.hcons()) == 0 x.add_hcons([('h0', 'qeq', 'h1')]) hcs = x.hcons() assert len(hcs) == 1 assert hcs[0] == ('h0', 'qeq', 'h1') x.add_hcons([('h3', 'qeq', 'h5')]) hcs = sorted(x.hcons()) # hcons are not stored in sorted order assert len(hcs) == 2 assert hcs[1] == ('h3', 'qeq', 'h5')
def test_nodeids(self): sp = Pred.surface x = Xmrs(eps=[(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})]) assert x.nodeids() == [10] assert x.nodeids(ivs=['x4']) == [10] assert x.nodeids(quantifier=False) == [10] assert x.nodeids(quantifier=None) == [10] assert x.nodeids(quantifier=True) == [] x.add_eps([(11, sp('_the_q_rel'), 'h5', {'ARG0': 'x4', 'RSTR': 'h6'})]) x.add_hcons([('h6', 'qeq', 'h3')]) assert sorted(x.nodeids()) == [10, 11] assert sorted(x.nodeids(ivs=['x4'])) == [10, 11] assert sorted(x.nodeids(ivs=['x4'], quantifier=True)) == [11] assert sorted(x.nodeids(ivs=['x4'], quantifier=False)) == [10]
def test_nodeids(self): sp = Pred.stringpred x = Xmrs(eps=[(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})]) assert x.nodeids() == [10] assert x.nodeids(ivs=['x4']) == [10] assert x.nodeids(quantifier=False) == [10] assert x.nodeids(quantifier=None) == [10] assert x.nodeids(quantifier=True) == [] x.add_eps([(11, sp('_the_q_rel'), 'h5', {'ARG0': 'x4', 'RSTR': 'h6'})]) x.add_hcons([('h6', 'qeq', 'h3')]) assert sorted(x.nodeids()) == [10, 11] assert sorted(x.nodeids(ivs=['x4'])) == [10, 11] assert sorted(x.nodeids(ivs=['x4'], quantifier=True)) == [11] assert sorted(x.nodeids(ivs=['x4'], quantifier=False)) == [10]
def test_nodeid(self): sp = Pred.surface x = Xmrs() with pytest.raises(KeyError): x.nodeid('e2') x.add_eps([(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})]) assert x.nodeid('x4') == 10 assert x.nodeid('x4', quantifier=False) == 10 assert x.nodeid('x4', quantifier=None) == 10 assert x.nodeid('x4', quantifier=True) == None x.add_eps([(11, sp('_the_q_rel'), 'h5', {'ARG0': 'x4', 'RSTR': 'h6'})]) x.add_hcons([('h6', 'qeq', 'h3')]) assert x.nodeid('x4') == 10 assert x.nodeid('x4', quantifier=False) == 10 assert x.nodeid('x4', quantifier=True) == 11
def test_nodeid(self): sp = Pred.stringpred x = Xmrs() with pytest.raises(KeyError): x.nodeid('e2') x.add_eps([(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})]) assert x.nodeid('x4') == 10 assert x.nodeid('x4', quantifier=False) == 10 assert x.nodeid('x4', quantifier=None) == 10 assert x.nodeid('x4', quantifier=True) == None x.add_eps([(11, sp('_the_q_rel'), 'h5', {'ARG0': 'x4', 'RSTR': 'h6'})]) x.add_hcons([('h6', 'qeq', 'h3')]) assert x.nodeid('x4') == 10 assert x.nodeid('x4', quantifier=False) == 10 assert x.nodeid('x4', quantifier=True) == 11
def test_add_hcons(self): x = Xmrs() with pytest.raises(XmrsError): x.add_hcons([('h0')]) # only hi x.add_hcons([('h0', 'qeq')]) # only hi and relation # hi, relation, and lo (the minimum, but probably max, too) x.add_hcons([('h0', 'qeq', 'h1')]) assert len(x.hcons()) == 1 hc = x.hcon('h0') assert hc[0] == 'h0' assert hc[1] == 'qeq' assert hc[2] == 'h1' # cannot have more than one hcons with the same hi variable with pytest.raises(XmrsError): x.add_hcons([('h0', 'qeq', 'h2')]) assert len(x.hcons()) == 1