From c0255ed7d82ed280389b774bd6758d542191a4ad Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 9 Jul 2015 15:15:32 +0200 Subject: [PATCH] * Allow slice indexing in Doc.__getitem__, returning a Span object --- spacy/tokens.pyx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spacy/tokens.pyx b/spacy/tokens.pyx index 22bf6e2dc..c15b92366 100644 --- a/spacy/tokens.pyx +++ b/spacy/tokens.pyx @@ -115,6 +115,12 @@ cdef class Doc: Returns: 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: i = self.length + i bounds_check(i, self.length, PADDING)