Skip to content

Commit

Permalink
Merge pull request #18 from zMoooooritz/levenshtein
Browse files Browse the repository at this point in the history
Replace levenshtein with thefuzz for better compatiblity
  • Loading branch information
zMoooooritz authored Nov 11, 2021
2 parents 8ade599 + eaf827c commit 022183e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
geojson==2.5.0
requests==2.26.0
geojson==2.5.0
thefuzz==0.19.0
PyInquirer==1.0.3
python_dateutil==2.8.2
python_Levenshtein==0.12.2
6 changes: 3 additions & 3 deletions stapy/sta/entity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
import Levenshtein as lev
from thefuzz import fuzz

class Entity(Enum):
"""
Expand Down Expand Up @@ -60,5 +60,5 @@ def match(cls, entity, threshold=0.5):
"""
if not isinstance(entity, str):
return None
max_ent = max(Entity, key=lambda x: lev.ratio(entity.lower(), x.value.lower()))
return max_ent if lev.ratio(entity.lower(), max_ent.value.lower()) > threshold else None
max_ele, max_val = max([(ent, fuzz.ratio(entity.lower(), ent.value.lower())) for ent in Entity], key=lambda x: x[1])
return max_ele if max_val / 100 > threshold else None
6 changes: 3 additions & 3 deletions stapy/sta/geo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
import geojson
import Levenshtein as lev
from thefuzz import fuzz

class GeoJSON(Enum):
"""
Expand Down Expand Up @@ -49,5 +49,5 @@ def match(cls, obj, threshold=0.5):
"""
if not isinstance(obj, str):
return None
max_obj = max(GeoJSON, key=lambda x: lev.ratio(obj.lower(), x.value.lower()))
return max_obj if lev.ratio(obj.lower(), max_obj.value.lower()) > threshold else None
max_ele, max_val = max([(geo, fuzz.ratio(obj.lower(), geo.value.lower())) for geo in GeoJSON], key=lambda x: x[1])
return max_ele if max_val / 100 > threshold else None
2 changes: 1 addition & 1 deletion stapy/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.3"
__version__ = "0.2.4"

0 comments on commit 022183e

Please sign in to comment.