* Fix negative indices in Span

This commit is contained in:
Matthew Honnibal 2015-07-30 02:30:24 +02:00
parent 74d8cb3980
commit 9590968fc1
1 changed files with 6 additions and 2 deletions

View File

@ -41,13 +41,17 @@ cdef class Span:
def __getitem__(self, int i): def __getitem__(self, int i):
if i < 0: if i < 0:
i = len(self) - i return self._seq[self.end + i]
return self._seq[self.start + i] else:
return self._seq[self.start + i]
def __iter__(self): def __iter__(self):
for i in range(self.start, self.end): for i in range(self.start, self.end):
yield self._seq[i] 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: property root:
"""The first ancestor of the first word of the span that has its head """The first ancestor of the first word of the span that has its head
outside the span. outside the span.