mirror of https://github.com/explosion/spaCy.git
Defer some attributes to Doc, via getters_for_tokens attribute.
This commit is contained in:
parent
8829984efb
commit
5d10e2005c
|
@ -94,6 +94,8 @@ cdef class Token:
|
||||||
return self.doc[self.i+i]
|
return self.doc[self.i+i]
|
||||||
|
|
||||||
def similarity(self, other):
|
def similarity(self, other):
|
||||||
|
if 'similarity' in self.doc.getters_for_tokens:
|
||||||
|
return self.doc.getters_for_tokens['similarity'](self, other)
|
||||||
if self.vector_norm == 0 or other.vector_norm == 0:
|
if self.vector_norm == 0 or other.vector_norm == 0:
|
||||||
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)
|
||||||
|
@ -182,6 +184,8 @@ cdef class Token:
|
||||||
|
|
||||||
property has_vector:
|
property has_vector:
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
|
if 'has_vector' in self.doc.getters_for_tokens:
|
||||||
|
return self.doc.getters_for_tokens['has_vector'](self)
|
||||||
cdef int i
|
cdef int i
|
||||||
for i in range(self.vocab.vectors_length):
|
for i in range(self.vocab.vectors_length):
|
||||||
if self.c.lex.vector[i] != 0:
|
if self.c.lex.vector[i] != 0:
|
||||||
|
@ -191,6 +195,8 @@ cdef class Token:
|
||||||
|
|
||||||
property vector:
|
property vector:
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
|
if 'vector' in self.doc.getters_for_tokens:
|
||||||
|
return self.doc.getters_for_tokens['vector'](self)
|
||||||
cdef int length = self.vocab.vectors_length
|
cdef int length = self.vocab.vectors_length
|
||||||
if length == 0:
|
if length == 0:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
@ -387,11 +393,14 @@ cdef class Token:
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
"""Get a list of conjoined words."""
|
"""Get a list of conjoined words."""
|
||||||
cdef Token word
|
cdef Token word
|
||||||
if self.dep_ != 'conj':
|
if 'conjuncts' in self.doc.getters_for_tokens:
|
||||||
for word in self.rights:
|
yield from self.doc.getters_for_tokens['conjuncts'](self)
|
||||||
if word.dep_ == 'conj':
|
else:
|
||||||
yield word
|
if self.dep_ != 'conj':
|
||||||
yield from word.conjuncts
|
for word in self.rights:
|
||||||
|
if word.dep_ == 'conj':
|
||||||
|
yield word
|
||||||
|
yield from word.conjuncts
|
||||||
|
|
||||||
property ent_type:
|
property ent_type:
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
|
|
Loading…
Reference in New Issue