Fix on_match callback for DependencyMatcher
Fix `DependencyMatcher` so that the callback is called only once per
match.
@@ -218,11 +218,16 @@ def test_dependency_matcher_callback(en_vocab, doc):
pattern = [
{"RIGHT_ID": "quick", "RIGHT_ATTRS": {"ORTH": "quick"}},
]
+ nomatch_pattern = [
+ {"RIGHT_ID": "quick", "RIGHT_ATTRS": {"ORTH": "NOMATCH"}},
+ ]
matcher = DependencyMatcher(en_vocab)
mock = Mock()
matcher.add("pattern", [pattern], on_match=mock)
+ matcher.add("nomatch_pattern", [nomatch_pattern], on_match=mock)
matches = matcher(doc)
+ assert len(matches) == 1
mock.assert_called_once_with(matcher, doc, 0, matches)
# check that matches with and without callback are the same (#4590)
