* Fix Issue #367: Missing has_vector property on Doc and Span objects

This commit is contained in:
Matthew Honnibal 2016-05-09 12:36:14 +02:00
parent 7b78239436
commit 5d86c30f0b
3 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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:

View File

@ -113,6 +113,10 @@ cdef class Span:
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):
if self._vector is None: