Fix on_match callback for DependencyMatcher (#6313)

Fix `DependencyMatcher` so that the callback is called only once per
match.
This commit is contained in:
Adriane Boyd 2020-10-31 12:20:27 +01:00 committed by GitHub
parent 2918923541
commit 5d2cb86c34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

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