From 342cb4178217ab6bfb52a5612f7d8c7ef03d368d Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Wed, 11 Jan 2017 21:30:14 +0100 Subject: [PATCH] Add apply_transition_sequence util function to utils --- spacy/tests/util.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spacy/tests/util.py b/spacy/tests/util.py index 417996c3f..4fb0701f4 100644 --- a/spacy/tests/util.py +++ b/spacy/tests/util.py @@ -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)