mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 09:26:27 +03:00
* Fix Issue #367: Missing has_vector property on Doc and Span objects
This commit is contained in:
parent
7b78239436
commit
5d86c30f0b
|
@ -7,6 +7,7 @@ from spacy.attrs import HEAD
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.models
|
@pytest.mark.models
|
||||||
def test_getitem(EN):
|
def test_getitem(EN):
|
||||||
tokens = EN(u'Give it back! He pleaded.')
|
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]
|
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 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','
|
assert token.right_edge.text == u','
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.vectors
|
||||||
|
def test_has_vector(EN):
|
||||||
|
doc = EN(u'''apple orange pear''')
|
||||||
|
assert doc.has_vector
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,10 @@ cdef class Doc:
|
||||||
return 0.0
|
return 0.0
|
||||||
return numpy.dot(self.vector, other.vector) / (self.vector_norm * other.vector_norm)
|
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:
|
property vector:
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
if self._vector is None:
|
if self._vector is None:
|
||||||
|
|
|
@ -113,6 +113,10 @@ cdef class Span:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
return self.doc[root.l_edge : root.r_edge + 1]
|
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:
|
property vector:
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
if self._vector is None:
|
if self._vector is None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user