mirror of
https://github.com/explosion/spaCy.git
synced 2025-04-06 02:04:13 +03:00
Draft a refactored init for the GoldParse class
This commit is contained in:
parent
47afef7d6b
commit
e07fe92b27
|
@ -215,6 +215,26 @@ def _consume_ent(tags):
|
|||
|
||||
|
||||
cdef class GoldParse:
|
||||
@classmethod
|
||||
def new_init(cls, doc, annot_tuples=None, words=None, tags=None, heads=None,
|
||||
deps=None, entities=None):
|
||||
if words is None:
|
||||
words = [token.text for token in doc]
|
||||
if tags is None:
|
||||
tags = [None for _ in doc]
|
||||
if heads is None:
|
||||
heads = [None for _ in doc]
|
||||
if deps is None:
|
||||
deps = [None for _ in doc]
|
||||
if entities is None:
|
||||
entities = [None for _ in doc]
|
||||
elif len(entities) == 0:
|
||||
entities = ['O' for _ in doc]
|
||||
elif not isinstance(entities[0], basestring):
|
||||
# Assume we have entities specified by character offset.
|
||||
entities = biluo_tags_from_offsets(doc, entities)
|
||||
return cls(doc, [(range(len(doc)), words, tags, heads, deps, entities)])
|
||||
|
||||
def __init__(self, tokens, annot_tuples, make_projective=False):
|
||||
self.mem = Pool()
|
||||
self.loss = 0
|
||||
|
|
Loading…
Reference in New Issue
Block a user