diff --git a/spacy/tests/tokens/test_tokens_api.py b/spacy/tests/tokens/test_tokens_api.py index 457b20f46..29c559a07 100644 --- a/spacy/tests/tokens/test_tokens_api.py +++ b/spacy/tests/tokens/test_tokens_api.py @@ -7,6 +7,7 @@ from spacy.attrs import HEAD import pytest + @pytest.mark.models def test_getitem(EN): tokens = EN(u'Give it back! He pleaded.') @@ -192,3 +193,10 @@ def test_right_edge(EN): subtree = [w.text for w in token.subtree] assert subtree == [u'for' , u'the', u'sake', u'of', u'such', u'as', u'live', u'under', u'the', u'government', u'of', u'the', u'Romans', u','] assert token.right_edge.text == u',' + + +@pytest.mark.vectors +def test_has_vector(EN): + doc = EN(u'''apple orange pear''') + assert doc.has_vector + diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index c964d294b..eaec68675 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -137,6 +137,10 @@ cdef class Doc: return 0.0 return numpy.dot(self.vector, other.vector) / (self.vector_norm * other.vector_norm) + property has_vector: + def __get__(self): + return any(token.has_vector for token in self) + property vector: def __get__(self): if self._vector is None: diff --git a/spacy/tokens/span.pyx b/spacy/tokens/span.pyx index d2e657c21..884bb74d8 100644 --- a/spacy/tokens/span.pyx +++ b/spacy/tokens/span.pyx @@ -112,6 +112,10 @@ cdef class Span: if n >= self.doc.length: raise RuntimeError return self.doc[root.l_edge : root.r_edge + 1] + + property has_vector: + def __get__(self): + return any(token.has_vector for token in self) property vector: def __get__(self):