Allow entities to be set by Span, or by 4-tuple (with entity ID)

This commit is contained in:
Matthew Honnibal 2016-09-24 01:17:43 +02:00
parent 60fdf4d5f1
commit 15e42a1ba9

View File

@ -240,7 +240,16 @@ cdef class Doc:
self.c[i].ent_iob = 0 self.c[i].ent_iob = 0
cdef attr_t ent_type cdef attr_t ent_type
cdef int start, end cdef int start, end
for ent_type, start, end in ents: for ent_info in ents:
if isinstance(ent_info, Span):
ent_id = ent_info.ent_id
ent_type = ent_info.label
start = ent_info.start
end = ent_info.end
elif len(ent_info) == 3:
ent_type, start, end = ent_info
else:
ent_id, ent_type, start, end = ent_info
if ent_type is None or ent_type < 0: if ent_type is None or ent_type < 0:
# Mark as O # Mark as O
for i in range(start, end): for i in range(start, end):
@ -254,7 +263,6 @@ cdef class Doc:
# Set start as B # Set start as B
self.c[start].ent_iob = 3 self.c[start].ent_iob = 3
@property @property
def noun_chunks(self): def noun_chunks(self):
"""Yield spans for base noun phrases.""" """Yield spans for base noun phrases."""