Changed to difflib instead of Lavenshtein

This commit is contained in:
Jeison Yehuda Amihud (Blender Dumbass) 2022-03-30 14:54:49 +00:00
parent df98e6db69
commit 46a9130e41

View file

@ -8,8 +8,13 @@
import os import os
import json import json
import Levenshtein from difflib import SequenceMatcher
def similar(a, b):
# I guess it simpifies the syntax for SequenceMatcher
# In the previous version we use Lavenshtain but it made
# it an issue for some people to install.
return SequenceMatcher(None, a, b).ratio()
def search_app(name): def search_app(name):
@ -35,7 +40,7 @@ def search_app(name):
for i in all_apps: for i in all_apps:
for n in i.get("names",[]): for n in i.get("names",[]):
m = Levenshtein.jaro_winkler(n.lower(), name.lower()) m = similar(n.lower(), name.lower())
if m > match and m > 0.49: if m > match and m > 0.49:
closest = i closest = i
match = m match = m
@ -47,7 +52,7 @@ def search_app(name):
for i in all_apps: for i in all_apps:
for n in i.get("generic_name",[]): for n in i.get("generic_name",[]):
m = Levenshtein.jaro_winkler(n.lower(), name.lower()) m = similar(n.lower(), name.lower())
if m > match: if m > match:
closest = i closest = i
match = m match = m