mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-11 04:08:09 +03:00
* Reform constructor and save/load workflow in parser model
This commit is contained in:
parent
1d7f2d3abc
commit
a3d5e6c0dd
|
@ -11,7 +11,6 @@ from .stateclass cimport StateClass
|
|||
|
||||
|
||||
cdef class Parser:
|
||||
cdef readonly object cfg
|
||||
cdef readonly Model model
|
||||
cdef readonly TransitionSystem moves
|
||||
|
||||
|
|
|
@ -67,16 +67,22 @@ def ParserFactory(transition_system):
|
|||
|
||||
|
||||
cdef class Parser:
|
||||
def __init__(self, StringStore strings, model_dir, transition_system):
|
||||
def __init__(self, StringStore strings, transition_system, model):
|
||||
self.moves = transition_system
|
||||
self.model = model
|
||||
|
||||
@classmethod
|
||||
def from_dir(cls, model_dir, strings, transition_system):
|
||||
if not os.path.exists(model_dir):
|
||||
print >> sys.stderr, "Warning: No model found at", model_dir
|
||||
elif not os.path.isdir(model_dir):
|
||||
print >> sys.stderr, "Warning: model path:", model_dir, "is not a directory"
|
||||
else:
|
||||
self.cfg = Config.read(model_dir, 'config')
|
||||
self.moves = transition_system(strings, self.cfg.labels)
|
||||
templates = get_templates(self.cfg.features)
|
||||
self.model = Model(self.moves.n_moves, templates, model_dir)
|
||||
cfg = Config.read(model_dir, 'config')
|
||||
moves = transition_system(strings, cfg.labels)
|
||||
templates = get_templates(cfg.features)
|
||||
model = Model(moves.n_moves, templates, model_dir)
|
||||
return cls(strings, moves, model)
|
||||
|
||||
|
||||
def __call__(self, Doc tokens):
|
||||
cdef StateClass stcls = StateClass.init(tokens.data, tokens.length)
|
||||
|
|
Loading…
Reference in New Issue
Block a user