From eaf827c6e5ab38b6286bfb7862a184a3764f3685 Mon Sep 17 00:00:00 2001 From: Moritz Biering Date: Thu, 11 Nov 2021 20:35:33 +0100 Subject: [PATCH] Replace levenshtein with thefuzz for better compatiblity --- requirements.txt | 4 ++-- stapy/sta/entity.py | 6 +++--- stapy/sta/geo.py | 6 +++--- stapy/version.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index f398ab5..5363e54 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/stapy/sta/entity.py b/stapy/sta/entity.py index ac5d61d..d340b5b 100755 --- a/stapy/sta/entity.py +++ b/stapy/sta/entity.py @@ -1,5 +1,5 @@ from enum import Enum -import Levenshtein as lev +from thefuzz import fuzz class Entity(Enum): """ @@ -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 diff --git a/stapy/sta/geo.py b/stapy/sta/geo.py index 576610b..bc0fd20 100644 --- a/stapy/sta/geo.py +++ b/stapy/sta/geo.py @@ -1,6 +1,6 @@ from enum import Enum import geojson -import Levenshtein as lev +from thefuzz import fuzz class GeoJSON(Enum): """ @@ -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 diff --git a/stapy/version.py b/stapy/version.py index d31c31e..788da1f 100644 --- a/stapy/version.py +++ b/stapy/version.py @@ -1 +1 @@ -__version__ = "0.2.3" +__version__ = "0.2.4"