コード例 #1
0
 def test_pred(self):
     x = Xmrs()
     # KeyError on bad nodeid
     with pytest.raises(KeyError): x.pred(10)
     # but otherwise preds can be retrieved by nodeid
     x.add_eps([(10, Pred.surface('_n_n_rel'), 'h3', {'ARG0': 'x4'})])
     assert x.pred(10).string == '_n_n_rel'
コード例 #2
0
    def test_add_eps(self):
        x = Xmrs()
        # only nodeid
        with pytest.raises(XmrsError):
            x.add_eps([(10000,)])
        assert len(x.eps()) == 0
        # nodeid and pred
        with pytest.raises(XmrsError):
            x.add_eps([(10000, Pred.stringpred('_v_v_rel'))])
        assert len(x.eps()) == 0
        # nodeid, pred, and label (the minimum)
        x.add_eps([(10000, Pred.stringpred('_v_v_rel'), 'h1')])
        # make sure it was entered correctly and is unchanged
        assert len(x.eps()) == 1
        assert x.eps()[0][0] == 10000
        ep = x.ep(10000)
        assert isinstance(ep[1], Pred) and ep[1].string == '_v_v_rel'
        assert ep[2] == 'h1'

        # nodeid, pred, label, and argdict
        x = Xmrs()
        x.add_eps([(10000, Pred.stringpred('_v_v_rel'), 'h1', {})])
        assert len(x.eps()) == 1
        assert x.eps()[0][0] == 10000
        ep = x.ep(10000)
        assert ep[0] == 10000
        assert isinstance(ep[1], Pred) and ep[1].string == '_v_v_rel'
        assert ep[2] == 'h1'
        assert ep[3] == {}

        # cannot have more than one ep with the same nodeid
        with pytest.raises(XmrsError):
            x.add_eps([(10000, Pred.stringpred('_n_n_rel'), 'h3', {})])
        assert len(x.eps()) == 1
コード例 #3
0
    def test_add_eps(self):
        x = Xmrs()
        # only nodeid
        with pytest.raises(XmrsError):
            x.add_eps([(10000,)])
        assert len(x.eps()) == 0
        # nodeid and pred
        with pytest.raises(XmrsError):
            x.add_eps([(10000, Pred.surface('_v_v_rel'))])
        assert len(x.eps()) == 0
        # nodeid, pred, and label (the minimum)
        x.add_eps([(10000, Pred.surface('_v_v_rel'), 'h1')])
        # make sure it was entered correctly and is unchanged
        assert len(x.eps()) == 1
        assert x.eps()[0][0] == 10000
        ep = x.ep(10000)
        assert isinstance(ep[1], Pred) and ep[1].string == '_v_v_rel'
        assert ep[2] == 'h1'

        # nodeid, pred, label, and argdict
        x = Xmrs()
        x.add_eps([(10000, Pred.surface('_v_v_rel'), 'h1', {})])
        assert len(x.eps()) == 1
        assert x.eps()[0][0] == 10000
        ep = x.ep(10000)
        assert ep[0] == 10000
        assert isinstance(ep[1], Pred) and ep[1].string == '_v_v_rel'
        assert ep[2] == 'h1'
        assert ep[3] == {}

        # cannot have more than one ep with the same nodeid
        with pytest.raises(XmrsError):
            x.add_eps([(10000, Pred.surface('_n_n_rel'), 'h3', {})])
        assert len(x.eps()) == 1
コード例 #4
0
 def test_pred(self):
     x = Xmrs()
     # KeyError on bad nodeid
     with pytest.raises(KeyError): x.pred(10)
     # but otherwise preds can be retrieved by nodeid
     x.add_eps([(10, Pred.stringpred('_n_n_rel'), 'h3', {'ARG0': 'x4'})])
     assert x.pred(10).string == '_n_n_rel'
コード例 #5
0
 def test_ep(self):
     sp = Pred.surface
     x = Xmrs()
     with pytest.raises(TypeError):
         x.ep()
     with pytest.raises(KeyError):
         x.ep(10)
     x.add_eps([(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})])
     assert x.ep(10)[1] == sp('_n_n_rel')
コード例 #6
0
 def test_ep(self):
     sp = Pred.stringpred
     x = Xmrs()
     with pytest.raises(TypeError):
         x.ep()
     with pytest.raises(KeyError):
         x.ep(10)
     x.add_eps([(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})])
     assert x.ep(10)[1] == sp('_n_n_rel')
コード例 #7
0
 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]
コード例 #8
0
 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]
コード例 #9
0
 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
コード例 #10
0
 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
コード例 #11
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'}
コード例 #12
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'}
コード例 #13
0
 def test_eps(self):
     sp = Pred.surface
     x = Xmrs()
     assert len(x.eps()) == 0
     x.add_eps([(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})])
     eps = x.eps()
     assert len(eps) == 1
     assert eps[0][0] == 10
     assert eps[0][1] == sp('_n_n_rel')
     assert eps[0][2] == 'h3'
     assert eps[0][3] == {'ARG0': 'x4'}
     x.add_eps([
         (11, sp('_q_q_rel'), 'h5', {'ARG0': 'x4', 'RSTR': 'h6'}),
         (12, sp('_v_v_rel'), 'h7', {'ARG0': 'e2', 'ARG1': 'x4'})
     ])
     eps = x.eps()
     assert len(eps) == 3
     assert eps[0][1] == sp('_n_n_rel')
     assert eps[1][1] == sp('_q_q_rel')
     assert eps[2][1] == sp('_v_v_rel')
     # make sure order is preserved
     x = Xmrs()
     x.add_eps([
         (12, sp('_v_v_rel'), 'h7', {'ARG0':'e2', 'ARG1': 'x4'}),
         (11, sp('_q_q_rel'), 'h5', {'ARG0':'x4', 'RSTR': 'h6'}),
         (10, sp('_n_n_rel'), 'h3', {'ARG0':'x4'})
     ])
     eps = x.eps()
     assert eps[0][1] == sp('_v_v_rel')
     assert eps[1][1] == sp('_q_q_rel')
     assert eps[2][1] == sp('_n_n_rel')
     # only get with given nodeids and in that order
     eps = x.eps(nodeids=[10, 11])
     assert eps[0][1] == sp('_n_n_rel')
     assert eps[1][1] == sp('_q_q_rel')
     # but asking for a non-existing one raises a KeyError
     with pytest.raises(KeyError):
         x.eps(nodeids=[10, 13])
コード例 #14
0
 def test_eps(self):
     sp = Pred.stringpred
     x = Xmrs()
     assert len(x.eps()) == 0
     x.add_eps([(10, sp('_n_n_rel'), 'h3', {'ARG0': 'x4'})])
     eps = x.eps()
     assert len(eps) == 1
     assert eps[0][0] == 10
     assert eps[0][1] == sp('_n_n_rel')
     assert eps[0][2] == 'h3'
     assert eps[0][3] == {'ARG0': 'x4'}
     x.add_eps([
         (11, sp('_q_q_rel'), 'h5', {'ARG0': 'x4', 'RSTR': 'h6'}),
         (12, sp('_v_v_rel'), 'h7', {'ARG0': 'e2', 'ARG1': 'x4'})
     ])
     eps = x.eps()
     assert len(eps) == 3
     assert eps[0][1] == sp('_n_n_rel')
     assert eps[1][1] == sp('_q_q_rel')
     assert eps[2][1] == sp('_v_v_rel')
     # make sure order is preserved
     x = Xmrs()
     x.add_eps([
         (12, sp('_v_v_rel'), 'h7', {'ARG0':'e2', 'ARG1': 'x4'}),
         (11, sp('_q_q_rel'), 'h5', {'ARG0':'x4', 'RSTR': 'h6'}),
         (10, sp('_n_n_rel'), 'h3', {'ARG0':'x4'})
     ])
     eps = x.eps()
     assert eps[0][1] == sp('_v_v_rel')
     assert eps[1][1] == sp('_q_q_rel')
     assert eps[2][1] == sp('_n_n_rel')
     # only get with given nodeids and in that order
     eps = x.eps(nodeids=[10, 11])
     assert eps[0][1] == sp('_n_n_rel')
     assert eps[1][1] == sp('_q_q_rel')
     # but asking for a non-existing one raises a KeyError
     with pytest.raises(KeyError):
         x.eps(nodeids=[10, 13])