superleaf.operators.fuzzy#

Classes

FuzzyMatchResult(string, target, score[, ...])

Score of one string against one target.

FuzzyMatchResults(results)

Scores of one string against several targets.

FuzzyMatcher(targets, normalizer, ...)

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: object

Score of one string against one target.

string and target are the normalized values that were scored; string_raw and target_raw hold 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: object

Scores 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:

FuzzyMatchResult

class superleaf.operators.fuzzy.FuzzyMatcher(targets: str | ~typing.Iterable[str], normalizer: ~typing.Callable[[str], str] | None = <cyfunction default_process>, substring: bool = True)[source]#

Bases: Operator

Score strings against one or more targets with rapidfuzz.

Calling the matcher on a string returns a FuzzyMatchResult for a single target, or FuzzyMatchResults for 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_ratio so a target can match part of the input. Otherwise use fuzz.ratio.

Raises:

ValueError – If targets is 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 TypeError for non-str inputs; otherwise they give False.

  • exceptions (type, tuple of types, or str, optional) – Exceptions that produce fallback (see bool_operator()).

  • fallback (bool, optional) – Result when one of exceptions is raised.

Returns:

The predicate.

Return type:

BooleanOperator