Skip to content

Instantly share code, notes, and snippets.

@amireshoon
Created March 10, 2021 16:54
Show Gist options
  • Save amireshoon/3d15e8942953bc8ad6988cd7f0804271 to your computer and use it in GitHub Desktop.
Save amireshoon/3d15e8942953bc8ad6988cd7f0804271 to your computer and use it in GitHub Desktop.
Get similar word from a given word
from rapidfuzz import fuzz
import operator
"""
this function return similar value for given string with given dataset
first returned value will be similar word
seccond value is accuracy
"""
def find_similar(search_for, dataset):
res = []
for data in dataset:
res.append(fuzz.ratio(search_for, data))
i, v = max(enumerate(res), key=operator.itemgetter(1))
yield dataset[i]
yield v
dataset = [ "Appereance",
"color",
"Specifie Gravity",
"PH",
"Protein",
"Glucose",
"Keton",
"Blood",
"Bilirubin",
"Urobilinogen",
"Nitrite",
"RBC/hpf",
"WBC/hpf",
"Epithelial cells/Lpf",
"EC/Lpf",
"Bacteria",
"Casts",
"Mucous"]
word, accuracy = find_similar("colr", dataset)
print(word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment