* Rename _seq to doc attribute in Span

This commit is contained in:
Matthew Honnibal 2015-09-29 23:03:55 +10:00
parent ab694b0364
commit 87e6186828
2 changed files with 10 additions and 10 deletions

View File

@ -2,7 +2,7 @@ from .doc cimport Doc
cdef class Span: cdef class Span:
cdef readonly Doc _seq cdef readonly Doc doc
cdef public int i cdef public int i
cdef public int start cdef public int start
cdef public int end cdef public int end

View File

@ -19,7 +19,7 @@ cdef class Span:
start = tokens.length - start start = tokens.length - start
if end < 0: if end < 0:
end = tokens.length - end end = tokens.length - end
self._seq = tokens self.doc = tokens
self.start = start self.start = start
self.end = end self.end = end
self.label = label self.label = label
@ -48,16 +48,16 @@ cdef class Span:
def __getitem__(self, int i): def __getitem__(self, int i):
if i < 0: if i < 0:
return self._seq[self.end + i] return self.doc[self.end + i]
else: else:
return self._seq[self.start + i] return self.doc[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.doc[i]
def merge(self, unicode tag, unicode lemma, unicode ent_type): 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) self.doc.merge(self[0].idx, self[-1].idx + len(self[-1]), tag, lemma, ent_type)
def similarity(self, other): def similarity(self, other):
if self.vector_norm == 0.0 or other.vector_norm == 0.0: if self.vector_norm == 0.0 or other.vector_norm == 0.0:
@ -127,12 +127,12 @@ cdef class Span:
def __get__(self): def __get__(self):
# This should probably be called 'head', and the other one called # This should probably be called 'head', and the other one called
# 'gov'. But we went with 'head' elsehwhere, and now we're stuck =/ # 'gov'. But we went with 'head' elsehwhere, and now we're stuck =/
cdef const TokenC* start = &self._seq.data[self.start] cdef const TokenC* start = &self.doc.data[self.start]
cdef const TokenC* end = &self._seq.data[self.end] cdef const TokenC* end = &self.doc.data[self.end]
head = start head = start
while start <= (head + head.head) < end and head.head != 0: while start <= (head + head.head) < end and head.head != 0:
head += head.head head += head.head
return self._seq[head - self._seq.data] return self.doc[head - self.doc.data]
property lefts: property lefts:
"""Tokens that are to the left of the Span, whose head is within the Span.""" """Tokens that are to the left of the Span, whose head is within the Span."""
@ -172,5 +172,5 @@ cdef class Span:
property label_: property label_:
def __get__(self): def __get__(self):
return self._seq.vocab.strings[self.label] return self.doc.vocab.strings[self.label]