From 9590968fc170f205f8e5b9a141e4e99308511b78 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 30 Jul 2015 02:30:24 +0200 Subject: [PATCH] * Fix negative indices in Span --- spacy/tokens/spans.pyx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spacy/tokens/spans.pyx b/spacy/tokens/spans.pyx index 716d85a1a..f1c19f308 100644 --- a/spacy/tokens/spans.pyx +++ b/spacy/tokens/spans.pyx @@ -41,13 +41,17 @@ cdef class Span: def __getitem__(self, int i): if i < 0: - i = len(self) - i - return self._seq[self.start + i] + return self._seq[self.end + i] + else: + return self._seq[self.start + i] def __iter__(self): for i in range(self.start, self.end): yield self._seq[i] + def merge(self, unicode tag, unicode lemma, unicode ent_type): + self._seq.merge(self[0].idx, self[-1].idx + len(self[-1]), tag, lemma, ent_type) + property root: """The first ancestor of the first word of the span that has its head outside the span.