superleaf.operators.fuzzy#
Classes
|
Score of one string against one target. |
|
Scores of one string against several targets. |
|
Score strings against one or more targets with rapidfuzz. |
- class superleaf.operators.fuzzy.FuzzyMatchResult(string: str, target: str, score: float, string_raw: str | None = None, target_raw: str | None = None)[source]#
Bases:
objectScore of one string against one target.
stringandtargetare the normalized values that were scored;string_rawandtarget_rawhold the originals when normalization changed them.- string: str#
- target: str#
- score: float#
- string_raw: str | None = None#
- target_raw: str | None = None#
- class superleaf.operators.fuzzy.FuzzyMatchResults(results: list[FuzzyMatchResult])[source]#
Bases:
objectScores of one string against several targets.
- results: list[FuzzyMatchResult]#
- best_match() FuzzyMatchResult[source]#
Return the highest-scoring result.
- Returns:
The result with the highest score.
- Return type:
- class superleaf.operators.fuzzy.FuzzyMatcher(targets: str | ~typing.Iterable[str], normalizer: ~typing.Callable[[str], str] | None = <cyfunction default_process>, substring: bool = True)[source]#
Bases:
OperatorScore strings against one or more targets with rapidfuzz.
Calling the matcher on a string returns a
FuzzyMatchResultfor a single target, orFuzzyMatchResultsfor several.- Parameters:
targets (str or iterable of str) – Strings to match against.
normalizer (callable or None, optional) – Applied to inputs and targets before scoring. Default
rapidfuzz.utils.default_process(lowercase, non-alphanumerics replaced by spaces, trimmed). None disables normalization.substring (bool, optional) – If True (default), score with
fuzz.partial_ratioso a target can match part of the input. Otherwise usefuzz.ratio.
- Raises:
ValueError – If
targetsis empty.
- to_bool_operator(threshold: float = 80.0, raise_type_error: bool = False, exceptions=None, fallback=False) BooleanOperator[source]#
Predicate testing that the best score is at least
threshold.- Parameters:
threshold (float, optional) – Minimum score (0-100). Default 80.
raise_type_error (bool, optional) – If True, raise
TypeErrorfor non-strinputs; otherwise they give False.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback(seebool_operator()).fallback (bool, optional) – Result when one of
exceptionsis raised.
- Returns:
The predicate.
- Return type: