Add apply_transition_sequence util function to utils

This commit is contained in:
Ines Montani 2017-01-11 21:30:14 +01:00
parent 09807addff
commit 342cb41782

View File

@ -19,3 +19,15 @@ def get_doc(vocab, words=[], tags=None, heads=None, deps=None):
attrs[i, 2] = doc.vocab.strings[dep]
doc.from_array([POS, HEAD, DEP], attrs)
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)