mirror of https://github.com/explosion/spaCy.git
* Allow slice indexing in Doc.__getitem__, returning a Span object
This commit is contained in:
parent
7d2964f673
commit
c0255ed7d8
|
@ -115,6 +115,12 @@ cdef class Doc:
|
||||||
Returns:
|
Returns:
|
||||||
token (Token):
|
token (Token):
|
||||||
"""
|
"""
|
||||||
|
if isinstance(i, slice):
|
||||||
|
if i.step is not None:
|
||||||
|
raise ValueError("Stepped slices not supported in Span objects."
|
||||||
|
"Try: list(doc)[start:stop:step] instead.")
|
||||||
|
return Span(self, i.start, i.stop, label=0)
|
||||||
|
|
||||||
if i < 0:
|
if i < 0:
|
||||||
i = self.length + i
|
i = self.length + i
|
||||||
bounds_check(i, self.length, PADDING)
|
bounds_check(i, self.length, PADDING)
|
||||||
|
|
Loading…
Reference in New Issue