mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-27 17:54:39 +03:00
Add apply_transition_sequence util function to utils
This commit is contained in:
parent
09807addff
commit
342cb41782
|
@ -19,3 +19,15 @@ def get_doc(vocab, words=[], tags=None, heads=None, deps=None):
|
||||||
attrs[i, 2] = doc.vocab.strings[dep]
|
attrs[i, 2] = doc.vocab.strings[dep]
|
||||||
doc.from_array([POS, HEAD, DEP], attrs)
|
doc.from_array([POS, HEAD, DEP], attrs)
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|
||||||
|
def apply_transition_sequence(parser, doc, sequence):
|
||||||
|
"""Perform a series of pre-specified transitions, to put the parser in a
|
||||||
|
desired state."""
|
||||||
|
for action_name in sequence:
|
||||||
|
if '-' in action_name:
|
||||||
|
move, label = action_name.split('-')
|
||||||
|
parser.add_label(label)
|
||||||
|
with parser.step_through(doc) as stepwise:
|
||||||
|
for transition in sequence:
|
||||||
|
stepwise.transition(transition)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user