Posts

Showing posts from March, 2023

Fuzzy Search made easy

Image
Image from https://www.pexels.com/@apasaric/ I was finding a Python library to do fuzzy search. Given a blob of text, we want to find a string of texts. And fuzzysearch Python library is perfect. Here are some code snippets on how to use the find_near_matches function. Taking a famous typo from a book, Karen Harper's The Queen's Governess. wanton was misspelled as wonton (Chinese dumplings) "I tugged on the gown and sleeves I’d discarded like a wonton last night to fall into John’s arms" I searched for "a wanton last night" with an exact match string search, and I will not get any results. Below is an example of using fuzzy search. from fuzzysearch import find_near_matches blob_txt = ("I tugged on the gown and sleeves I’d discarded like a " "wonton last night to fall into John’s arms") fuzzy_result = find_near_matches("a wanton last night", blob_txt, max_l_dist=3) print(fuzzy_result) max_l_dist=3 tells the function