* Improve test for root token in Span

This commit is contained in:
Matthew Honnibal 2016-01-16 16:19:09 +01:00
parent c025a0c64b
commit fc5962a77d

View File

@ -1,9 +1,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from spacy.attrs import HEAD
from spacy.en import English
import numpy as np
import pytest import pytest
@pytest.fixture @pytest.fixture
def doc(EN): def doc(EN):
return EN('This is a sentence. This is another sentence. And a third.') return EN('This is a sentence. This is another sentence. And a third.')
@ -25,3 +27,13 @@ def test_root(doc):
assert np.orth_ == 'a sentence' assert np.orth_ == 'a sentence'
assert np.root.orth_ == 'sentence' assert np.root.orth_ == 'sentence'
assert np.root.head.orth_ == 'is' assert np.root.head.orth_ == 'is'
def test_root2():
text = 'through North and South Carolina'
EN = English(parser=False)
doc = EN(text)
heads = np.asarray([[0, 3, -1, -2, -4]], dtype='int32')
doc.from_array([HEAD], heads.T)
south_carolina = doc[-2:]
assert south_carolina.root.text == 'Carolina'