diff --git a/spacy/matcher/matcher.pyi b/spacy/matcher/matcher.pyi index 390629ff8..e485d07c4 100644 --- a/spacy/matcher/matcher.pyi +++ b/spacy/matcher/matcher.pyi @@ -52,3 +52,5 @@ class Matcher: with_alignments: bool = ... ) -> List[Span]: ... def _normalize_key(self, key: Any) -> Any: ... + +def fuzzy_match(s1: str, s2: str, fuzzy: int=-1) -> bool: ... diff --git a/spacy/matcher/matcher.pyx b/spacy/matcher/matcher.pyx index f985cf76c..4aacc00f3 100644 --- a/spacy/matcher/matcher.pyx +++ b/spacy/matcher/matcher.pyx @@ -1147,11 +1147,11 @@ def _get_extensions(spec, string_store, name2index): return attr_values -def fuzzy_match(input_string: str, rule_string: str, fuzzy: int=-1) -> bool: - distance = min(len(input_string), len(rule_string)) +def fuzzy_match(s1: str, s2: str, fuzzy: int=-1) -> bool: + distance = min(len(s1), len(s2)) distance -= 1 # don't allow completely different tokens if fuzzy == -1: # FUZZY operator with unspecified fuzzy fuzzy = 5 # default max fuzzy distance -= 1 # be more restrictive distance = min(fuzzy, distance if distance > 0 else 1) - return levenshtein(input_string, rule_string, distance) <= distance + return levenshtein(s1, s2, distance) <= distance diff --git a/spacy/tests/matcher/test_levenshtein.py b/spacy/tests/matcher/test_levenshtein.py index 6159fb97e..e17eb5623 100644 --- a/spacy/tests/matcher/test_levenshtein.py +++ b/spacy/tests/matcher/test_levenshtein.py @@ -71,3 +71,4 @@ def test_levenshtein(dist, a, b): ) def test_fuzzy_match(a, b, fuzzy, expected): assert fuzzy_match(a, b, fuzzy) == expected + assert fuzzy_match(b, a, fuzzy) == expected