forked from rapidfuzz/RapidFuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Python implementation of Editops/Opcodes
- Loading branch information
1 parent
aa6a88f
commit 773a45e
Showing
73 changed files
with
2,188 additions
and
1,638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[flake8] | ||
max-line-length = 120 | ||
show_source = True | ||
exclude = .git, __pycache__, build, dist, docs, tools, venv | ||
extend-ignore = E203, E722, B903, B950, N801, N802, N806 | ||
extend-select = B9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
# SPDX-License-Identifier: MIT | ||
# Copyright (C) 2022 Max Bachmann | ||
|
||
from __future__ import annotations | ||
|
||
from rapidfuzz._utils import default_distance_attribute as _dist_attr | ||
from rapidfuzz._utils import default_normalized_distance_attribute as _norm_dist_attr | ||
from rapidfuzz._utils import default_normalized_similarity_attribute as _norm_sim_attr | ||
from rapidfuzz._utils import default_similarity_attribute as _sim_attr | ||
from rapidfuzz._utils import fallback_import as _fallback_import | ||
|
||
_mod = "rapidfuzz.distance.DamerauLevenshtein" | ||
distance = _fallback_import(_mod, "distance") | ||
similarity = _fallback_import(_mod, "similarity") | ||
normalized_distance = _fallback_import(_mod, "normalized_distance") | ||
normalized_similarity = _fallback_import(_mod, "normalized_similarity") | ||
|
||
distance._RF_ScorerPy = _dist_attr | ||
similarity._RF_ScorerPy = _sim_attr | ||
normalized_distance._RF_ScorerPy = _norm_dist_attr | ||
normalized_similarity._RF_ScorerPy = _norm_sim_attr | ||
distance = _fallback_import(_mod, "distance", cached_scorer_call=_dist_attr) | ||
similarity = _fallback_import(_mod, "similarity", cached_scorer_call=_sim_attr) | ||
normalized_distance = _fallback_import( | ||
_mod, "normalized_distance", cached_scorer_call=_norm_dist_attr | ||
) | ||
normalized_similarity = _fallback_import( | ||
_mod, "normalized_similarity", cached_scorer_call=_norm_sim_attr | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,35 @@ | ||
from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar | ||
# SPDX-License-Identifier: MIT | ||
# Copyright (C) 2022 Max Bachmann | ||
|
||
from typing_extensions import Protocol | ||
from __future__ import annotations | ||
|
||
from rapidfuzz.distance import Editops, Opcodes | ||
from typing import Callable, Hashable, Sequence | ||
|
||
class _ScorerAttributes(Protocol): | ||
_RF_ScorerPy: Dict | ||
|
||
def _attr_decorator(func: Any) -> _ScorerAttributes: | ||
return func | ||
|
||
_StringType = Sequence[Hashable] | ||
_S1 = TypeVar("_S1") | ||
_S2 = TypeVar("_S2") | ||
|
||
@_attr_decorator | ||
def distance( | ||
s1: _S1, | ||
s2: _S2, | ||
s1: Sequence[Hashable], | ||
s2: Sequence[Hashable], | ||
*, | ||
processor: Optional[Callable[..., _StringType]] = None, | ||
score_cutoff: Optional[int] = None | ||
processor: Callable[..., Sequence[Hashable]] | None = None, | ||
score_cutoff: int | None = None, | ||
) -> int: ... | ||
@_attr_decorator | ||
def normalized_distance( | ||
s1: _S1, | ||
s2: _S2, | ||
*, | ||
processor: Optional[Callable[..., _StringType]] = None, | ||
score_cutoff: Optional[float] = 0 | ||
) -> float: ... | ||
@_attr_decorator | ||
def similarity( | ||
s1: _S1, | ||
s2: _S2, | ||
s1: Sequence[Hashable], | ||
s2: Sequence[Hashable], | ||
*, | ||
processor: Optional[Callable[..., _StringType]] = None, | ||
score_cutoff: Optional[int] = None | ||
processor: Callable[..., Sequence[Hashable]] | None = None, | ||
score_cutoff: int | None = None, | ||
) -> int: ... | ||
@_attr_decorator | ||
def normalized_distance( | ||
s1: Sequence[Hashable], | ||
s2: Sequence[Hashable], | ||
*, | ||
processor: Callable[..., Sequence[Hashable]] | None = None, | ||
score_cutoff: float | None = None, | ||
) -> float: ... | ||
def normalized_similarity( | ||
s1: _S1, | ||
s2: _S2, | ||
s1: Sequence[Hashable], | ||
s2: Sequence[Hashable], | ||
*, | ||
processor: Optional[Callable[..., _StringType]] = None, | ||
score_cutoff: Optional[float] = 0 | ||
processor: Callable[..., Sequence[Hashable]] | None = None, | ||
score_cutoff: float | None = None, | ||
) -> float: ... |
Oops, something went wrong.