spaCy/tests/test_merge.py

33 lines
929 B
Python
Raw Normal View History

2015-03-30 02:37:57 +03:00
from __future__ import unicode_literals
import pytest
from spacy.en import English
NLU = English()
def test_merge_tokens():
2015-04-07 05:51:31 +03:00
tokens = NLU(u'Los Angeles start.')
2015-03-30 02:37:57 +03:00
assert len(tokens) == 4
2015-04-07 05:51:31 +03:00
assert tokens[0].head.orth_ == 'Angeles'
2015-03-30 02:37:57 +03:00
assert tokens[1].head.orth_ == 'start'
2015-04-07 05:51:31 +03:00
tokens.merge(0, len('Los Angeles'), 'NNP', 'Los Angeles', 'GPE')
2015-03-30 02:37:57 +03:00
assert len(tokens) == 3
2015-04-07 05:51:31 +03:00
assert tokens[0].orth_ == 'Los Angeles'
2015-03-30 02:37:57 +03:00
assert tokens[0].head.orth_ == 'start'
def test_merge_heads():
tokens = NLU(u'I found a pilates class near work.')
assert len(tokens) == 8
tokens.merge(tokens[3].idx, tokens[4].idx + len(tokens[4]), tokens[4].tag_,
'pilates class', 'O')
assert len(tokens) == 7
assert tokens[0].head.i == 1
assert tokens[1].head.i == 1
assert tokens[2].head.i == 3
assert tokens[3].head.i == 1
assert tokens[4].head.i in [1, 3]
assert tokens[5].head.i == 4