mirror of https://github.com/explosion/spaCy.git
Fix index boundaries in Span
This commit is contained in:
parent
4f0843e0ec
commit
8f8a5c3386
|
@ -606,6 +606,7 @@ class Errors:
|
|||
'nlp = Chinese(config=cfg)')
|
||||
E1001 = ("Target token outside of matched span for match with tokens "
|
||||
"'{span}' and offset '{index}' matched by patterns '{patterns}'.")
|
||||
E1002 = ("Span index out of range.")
|
||||
|
||||
|
||||
@add_codes
|
||||
|
|
|
@ -177,9 +177,17 @@ cdef class Span:
|
|||
return Span(self.doc, start + self.start, end + self.start)
|
||||
else:
|
||||
if i < 0:
|
||||
return self.doc[self.end + i]
|
||||
token = self.doc[self.end + i]
|
||||
if self.start <= token.i < self.end:
|
||||
return token
|
||||
else:
|
||||
raise IndexError(Errors.E1002)
|
||||
else:
|
||||
return self.doc[self.start + i]
|
||||
token = self.doc[self.start + i]
|
||||
if self.start <= token.i < self.end:
|
||||
return token
|
||||
else:
|
||||
raise IndexError(Errors.E1002)
|
||||
|
||||
def __iter__(self):
|
||||
"""Iterate over `Token` objects.
|
||||
|
|
Loading…
Reference in New Issue