mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 00:46:28 +03:00
Tidy up and only use self.vector once
This commit is contained in:
parent
a8f1efd2f5
commit
9d6ca18a10
|
@ -125,11 +125,9 @@ cdef class Lexeme:
|
|||
if self.vector_norm == 0 or other.vector_norm == 0:
|
||||
user_warning(Warnings.W008.format(obj='Lexeme'))
|
||||
return 0.0
|
||||
|
||||
vector = self.vector
|
||||
xp = get_array_module(vector)
|
||||
return (xp.dot(self.vector, other.vector) /
|
||||
(self.vector_norm * other.vector_norm))
|
||||
return (xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm))
|
||||
|
||||
def to_bytes(self):
|
||||
lex_data = Lexeme.c_to_bytes(self.c)
|
||||
|
|
|
@ -329,10 +329,9 @@ cdef class Doc:
|
|||
if self.vector_norm == 0 or other.vector_norm == 0:
|
||||
user_warning(Warnings.W008.format(obj='Doc'))
|
||||
return 0.0
|
||||
|
||||
vector = self.vector
|
||||
xp = get_array_module(vector)
|
||||
return xp.dot(self.vector, other.vector) / (self.vector_norm * other.vector_norm)
|
||||
return xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm)
|
||||
|
||||
property has_vector:
|
||||
"""A boolean value indicating whether a word vector is associated with
|
||||
|
|
|
@ -234,10 +234,9 @@ cdef class Span:
|
|||
if self.vector_norm == 0.0 or other.vector_norm == 0.0:
|
||||
user_warning(Warnings.W008.format(obj='Span'))
|
||||
return 0.0
|
||||
|
||||
vector = self.vector
|
||||
xp = get_array_module(vector)
|
||||
return xp.dot(self.vector, other.vector) / (self.vector_norm * other.vector_norm)
|
||||
return xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm)
|
||||
|
||||
cpdef np.ndarray to_array(self, object py_attr_ids):
|
||||
"""Given a list of M attribute IDs, export the tokens to a numpy
|
||||
|
|
|
@ -172,8 +172,7 @@ cdef class Token:
|
|||
return 0.0
|
||||
vector = self.vector
|
||||
xp = get_array_module(vector)
|
||||
return (xp.dot(vector, other.vector) /
|
||||
(self.vector_norm * other.vector_norm))
|
||||
return (xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm))
|
||||
|
||||
property lex_id:
|
||||
"""RETURNS (int): Sequential ID of the token's lexical type."""
|
||||
|
|
Loading…
Reference in New Issue
Block a user