def test_init(self): n = N(1, 'entity') assert n.id == 1 assert n.entity == 'entity' assert n.score == -1.0 assert n.start == -1 assert n.end == -1 assert n.daughters == [] assert n.is_head() # it has no siblings assert n.type is None n = N(1, 'entity', 0.5, 1, 2, [], head=True, type='type') assert n.id == 1 assert n.entity == 'entity' assert n.score == 0.5 assert n.start == 1 assert n.end == 2 assert n.daughters == [] assert n.is_head() assert n.type == 'type'
def test_init(self): with pytest.raises(TypeError): D() with pytest.raises(TypeError): D(1) D(1, 'some-thing') D(1, 'some-thing', 0.5, 0, 3, [T('some-token')]) # roots are special: id is None, entity is root, daughters must # exactly 1 node; rest are None with pytest.raises(TypeError): D(None) with pytest.raises(TypeError): D(None, 'some-root', 0.5) with pytest.raises(TypeError): D(None, 'some-root', start=1) with pytest.raises(TypeError): D(None, 'some-root', end=1) with pytest.raises(ValueError): D(None, 'some-root', daughters=[N(1, 'some-thing'), N(2, 'some-thing')]) with pytest.raises(ValueError): D(None, 'some-root', daughters=[T('some-token')]) D(None, 'some-root', daughters=[N(1, 'some-thing')]) D(None, 'some-root', None, None, None, daughters=[N(1, 'some-thing')]) # root not as top with pytest.raises(ValueError): D(1, 'some-thing', daughters=[ N(None, 'some-root', daughters=[N(2, 'a-lex', daughters=[T('some-token')])]) ])
def test_parent(self): n1 = N(None, 'entity') assert n1.parent is None n2 = N(1, 'entity', 0.5, 1, 2, [], head=True, type='type', parent=n1) assert n2.parent is n1