mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 09:26:27 +03:00
Allow entities to be set by Span, or by 4-tuple (with entity ID)
This commit is contained in:
parent
60fdf4d5f1
commit
15e42a1ba9
|
@ -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."""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user