mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 01:48:04 +03:00 
			
		
		
		
	* Don't allow Span objects to be written to, as it introduces subtle bugs because they're created afresh from Doc.sents, Doc.ents etc.
This commit is contained in:
		
							parent
							
								
									d6945bf880
								
							
						
					
					
						commit
						d00fe2bbc6
					
				| 
						 | 
					@ -13,7 +13,8 @@ from ..parts_of_speech cimport univ_pos_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cdef class Span:
 | 
					cdef class Span:
 | 
				
			||||||
    """A slice from a Doc object."""
 | 
					    """A slice from a Doc object."""
 | 
				
			||||||
    def __cinit__(self, Doc tokens, int start, int end, int label=0):
 | 
					    def __cinit__(self, Doc tokens, int start, int end, int label=0, vector=None,
 | 
				
			||||||
 | 
					                  vector_norm=None):
 | 
				
			||||||
        if start < 0:
 | 
					        if start < 0:
 | 
				
			||||||
            start = tokens.length - start
 | 
					            start = tokens.length - start
 | 
				
			||||||
        if end < 0:
 | 
					        if end < 0:
 | 
				
			||||||
| 
						 | 
					@ -22,8 +23,8 @@ cdef class Span:
 | 
				
			||||||
        self.start = start
 | 
					        self.start = start
 | 
				
			||||||
        self.end = end
 | 
					        self.end = end
 | 
				
			||||||
        self.label = label
 | 
					        self.label = label
 | 
				
			||||||
        self._vector = None
 | 
					        self._vector = vector
 | 
				
			||||||
        self._vector_norm = None
 | 
					        self._vector_norm = vector_norm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __richcmp__(self, Span other, int op):
 | 
					    def __richcmp__(self, Span other, int op):
 | 
				
			||||||
        # Eq
 | 
					        # Eq
 | 
				
			||||||
| 
						 | 
					@ -67,9 +68,6 @@ cdef class Span:
 | 
				
			||||||
                self._vector = sum(t.vector for t in self) / len(self)
 | 
					                self._vector = sum(t.vector for t in self) / len(self)
 | 
				
			||||||
            return self._vector
 | 
					            return self._vector
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def __set__(self, value):
 | 
					 | 
				
			||||||
            self._vector = value
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    property vector_norm:
 | 
					    property vector_norm:
 | 
				
			||||||
        def __get__(self):
 | 
					        def __get__(self):
 | 
				
			||||||
            cdef float value
 | 
					            cdef float value
 | 
				
			||||||
| 
						 | 
					@ -80,9 +78,6 @@ cdef class Span:
 | 
				
			||||||
                self._vector_norm = math.sqrt(self._vector_norm)
 | 
					                self._vector_norm = math.sqrt(self._vector_norm)
 | 
				
			||||||
            return self._vector_norm
 | 
					            return self._vector_norm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def __set__(self, value):
 | 
					 | 
				
			||||||
            self._vector_norm = value
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    property text:
 | 
					    property text:
 | 
				
			||||||
        def __get__(self):
 | 
					        def __get__(self):
 | 
				
			||||||
            text = self.text_with_ws
 | 
					            text = self.text_with_ws
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user