mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 01:48:04 +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:
 | 
					        if self.vector_norm == 0 or other.vector_norm == 0:
 | 
				
			||||||
            user_warning(Warnings.W008.format(obj='Lexeme'))
 | 
					            user_warning(Warnings.W008.format(obj='Lexeme'))
 | 
				
			||||||
            return 0.0
 | 
					            return 0.0
 | 
				
			||||||
 | 
					 | 
				
			||||||
        vector = self.vector
 | 
					        vector = self.vector
 | 
				
			||||||
        xp = get_array_module(vector)
 | 
					        xp = get_array_module(vector)
 | 
				
			||||||
        return (xp.dot(self.vector, other.vector) /
 | 
					        return (xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm))
 | 
				
			||||||
                (self.vector_norm * other.vector_norm))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def to_bytes(self):
 | 
					    def to_bytes(self):
 | 
				
			||||||
        lex_data = Lexeme.c_to_bytes(self.c)
 | 
					        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:
 | 
					        if self.vector_norm == 0 or other.vector_norm == 0:
 | 
				
			||||||
            user_warning(Warnings.W008.format(obj='Doc'))
 | 
					            user_warning(Warnings.W008.format(obj='Doc'))
 | 
				
			||||||
            return 0.0
 | 
					            return 0.0
 | 
				
			||||||
 | 
					 | 
				
			||||||
        vector = self.vector
 | 
					        vector = self.vector
 | 
				
			||||||
        xp = get_array_module(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:
 | 
					    property has_vector:
 | 
				
			||||||
        """A boolean value indicating whether a word vector is associated with
 | 
					        """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:
 | 
					        if self.vector_norm == 0.0 or other.vector_norm == 0.0:
 | 
				
			||||||
            user_warning(Warnings.W008.format(obj='Span'))
 | 
					            user_warning(Warnings.W008.format(obj='Span'))
 | 
				
			||||||
            return 0.0
 | 
					            return 0.0
 | 
				
			||||||
 | 
					 | 
				
			||||||
        vector = self.vector
 | 
					        vector = self.vector
 | 
				
			||||||
        xp = get_array_module(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):
 | 
					    cpdef np.ndarray to_array(self, object py_attr_ids):
 | 
				
			||||||
        """Given a list of M attribute IDs, export the tokens to a numpy
 | 
					        """Given a list of M attribute IDs, export the tokens to a numpy
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -172,8 +172,7 @@ cdef class Token:
 | 
				
			||||||
            return 0.0
 | 
					            return 0.0
 | 
				
			||||||
        vector = self.vector
 | 
					        vector = self.vector
 | 
				
			||||||
        xp = get_array_module(vector)
 | 
					        xp = get_array_module(vector)
 | 
				
			||||||
        return (xp.dot(vector, other.vector) /
 | 
					        return (xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm))
 | 
				
			||||||
                (self.vector_norm * other.vector_norm))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    property lex_id:
 | 
					    property lex_id:
 | 
				
			||||||
        """RETURNS (int): Sequential ID of the token's lexical type."""
 | 
					        """RETURNS (int): Sequential ID of the token's lexical type."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user