* Allow slice indexing in Doc.__getitem__, returning a Span object

This commit is contained in:
Matthew Honnibal 2015-07-09 15:15:32 +02:00
parent 7d2964f673
commit c0255ed7d8
1 changed files with 6 additions and 0 deletions

View File

@ -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)