Add apply_transition_sequence util function to utils
@@ -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)
