From 15e42a1ba94729876b99384bdbc79ff41acf5b9a Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 24 Sep 2016 01:17:43 +0200 Subject: [PATCH] Allow entities to be set by Span, or by 4-tuple (with entity ID) --- spacy/tokens/doc.pyx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index 661a14153..e1d90e921 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -240,7 +240,16 @@ cdef class Doc: self.c[i].ent_iob = 0 cdef attr_t ent_type 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: # Mark as O for i in range(start, end): @@ -254,7 +263,6 @@ cdef class Doc: # Set start as B self.c[start].ent_iob = 3 - @property def noun_chunks(self): """Yield spans for base noun phrases."""