diff --git a/spacy/matcher/matcher.pyx b/spacy/matcher/matcher.pyx index f45dad599..443947cf1 100644 --- a/spacy/matcher/matcher.pyx +++ b/spacy/matcher/matcher.pyx @@ -1065,13 +1065,13 @@ def _get_extra_predicates_dict(attr, value_dict, vocab, predicate_types, regex=True)) continue elif cls == _FuzzyPredicate: - fuzzy = type_[len("FUZZY"):] # number after prefix - fuzzy = int(fuzzy) if fuzzy else 0 + fuzz = type_[len("FUZZY"):] # number after prefix + fuzz = int(fuzz) if fuzz else 0 if isinstance(value, dict): # add predicates inside fuzzy operator output.extend(_get_extra_predicates_dict(attr, value, vocab, predicate_types, extra_predicates, seen_predicates, - fuzzy=fuzzy)) + fuzzy=fuzz)) continue predicate = cls(len(extra_predicates), attr, value, type_, vocab=vocab, regex=regex, fuzzy=fuzzy) diff --git a/spacy/tests/matcher/test_matcher_api.py b/spacy/tests/matcher/test_matcher_api.py index 2fbdc7a4f..698995e70 100644 --- a/spacy/tests/matcher/test_matcher_api.py +++ b/spacy/tests/matcher/test_matcher_api.py @@ -214,6 +214,22 @@ def test_matcher_match_fuzzy_set3(en_vocab): (doc.vocab.strings["GoogleNow"], 3, 4), ] +def test_matcher_match_fuzzy_set4(en_vocab): + rules = { + "QUESTION": [[{"ORTH": {"FUZZY": {"IN": ["what"]}, + "NOT_IN": ["that"]}}, + {"ORTH": "do"}]] + } + matcher = Matcher(en_vocab) + for key, patterns in rules.items(): + matcher.add(key, patterns, greedy="LONGEST") + + words = ["what", "do", "you", "want"] + doc = Doc(matcher.vocab, words=words) + assert matcher(doc) == [ + (doc.vocab.strings["QUESTION"], 0, 2), + ] + def test_matcher_match_fuzzyn1(en_vocab): rules = {