2015-01-30 08:43:55 +03:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2015-10-09 05:37:25 +03:00
|
|
|
from spacy import attrs
|
2015-01-30 08:43:55 +03:00
|
|
|
|
|
|
|
|
2015-06-07 19:02:24 +03:00
|
|
|
def test_attr_of_token(EN):
|
2015-01-30 08:43:55 +03:00
|
|
|
text = u'An example sentence.'
|
2015-05-25 02:02:03 +03:00
|
|
|
tokens = EN(text, tag=True, parse=False)
|
2015-01-30 08:43:55 +03:00
|
|
|
example = EN.vocab[u'example']
|
|
|
|
assert example.orth != example.shape
|
|
|
|
feats_array = tokens.to_array((attrs.ORTH, attrs.SHAPE))
|
|
|
|
assert feats_array[0][0] != feats_array[0][1]
|
|
|
|
|
|
|
|
|
2015-07-23 10:26:43 +03:00
|
|
|
@pytest.mark.models
|
2015-06-07 19:02:24 +03:00
|
|
|
def test_tag(EN):
|
2015-04-07 06:51:44 +03:00
|
|
|
text = u'A nice sentence.'
|
|
|
|
tokens = EN(text)
|
|
|
|
assert tokens[0].tag != tokens[1].tag != tokens[2].tag != tokens[3].tag
|
|
|
|
feats_array = tokens.to_array((attrs.ORTH, attrs.TAG))
|
|
|
|
assert feats_array[0][1] == tokens[0].tag
|
|
|
|
assert feats_array[1][1] == tokens[1].tag
|
|
|
|
assert feats_array[2][1] == tokens[2].tag
|
|
|
|
assert feats_array[3][1] == tokens[3].tag
|
|
|
|
|
|
|
|
|
2015-07-23 10:26:43 +03:00
|
|
|
@pytest.mark.models
|
2015-06-07 19:02:24 +03:00
|
|
|
def test_dep(EN):
|
2015-04-07 07:00:43 +03:00
|
|
|
text = u'A nice sentence.'
|
|
|
|
tokens = EN(text)
|
|
|
|
feats_array = tokens.to_array((attrs.ORTH, attrs.DEP))
|
|
|
|
assert feats_array[0][1] == tokens[0].dep
|
|
|
|
assert feats_array[1][1] == tokens[1].dep
|
|
|
|
assert feats_array[2][1] == tokens[2].dep
|
|
|
|
assert feats_array[3][1] == tokens[3].dep
|