FuzzyWuzzy Python library
In this article, we see the FuzzyWuzzy library. The name of this library something weird and funny, but it is advantageous. It has a unique way to compare both strings and returns the score out of 100 of how much string is matched. FuzzyWuzzy is a library of Python which is used for string matching. Fuzzy string matching is the process of finding strings that match a given pattern.
There are many methods of comparing strings in python. Some of the main methods are:
- Using regex
- Simple compare
- Using difflib
First, understand the following methods of fuzzywuzzy library:
Fuzz Module:
The fuzz module is used to compare the two given strings at a time. It returns a score out of 100 after comparison using the different methods.
Fuzz.ratio():
It is one of the important methods of the fuzz module. It compares the string and score on the basis of how much the given string is matched.
Fuzz.partial_ratio():
The fuzzywuzzy library provides another powerful method partial_ratio(). It is used to handle the complex sting comparison such as substring matching. The partial_ratio() method can detect the substring. It follows the optimal partial logic where the short length string k and longer string m, the algorithm finds the best matching length k-string.
Fuzz.token_sort_ratio:
This method does not guarantee to get an accurate result because if we make the changes in the order of string. It may not give an accurate result.
Fuzz.token_set_ratio():
We used another method fuzz.token_set_ratio() that performs a set operation and takes out the common token and then makes a ratio() pairwise comparison.
Example:
Process Module:
The fuzzywuzzy package provides the processing module that allows us to calculate the string with the highest similarity.
Fuzz.WRatio:
The processing module also provides the WRatio, which gives a better result than the simple ratio. It handles lower and upper cases and some other parameters too.
Example:
Example:
strToMatch = "Hello Good Morning"
givenOpt = ["hello","Hello Good","Morning","Good Evenining"]
ratios = process.extract(strToMatch,givenOpt)
print(ratios)
# We can choose the string that has highest matching percentage
high = process.extractOne(strToMatch,givenOpt)
print(high)
Thank you 😊 for reading. Please read other blogs. And also share with your friends and
family.
ꜰᴏʀ ᴇxᴘʟᴏʀɪɴɢ ᴛʜᴇ ᴡᴏʀʟᴅ ᴘʟᴇᴀꜱᴇ ʜᴀᴠᴇ ʟᴏᴏᴋ ᴀɴᴅ ꜰᴏʟʟᴏᴡ.
https://maps.app.goo.gl/jnKyzdDpKMFutUqR7
ʟᴇᴛ ᴍᴇ ᴋɴᴏᴡ ɪꜰ ʏᴏᴜ ʜᴀᴠᴇ ᴀɴʏ Qᴜᴇʀɪᴇꜱ ᴏʀ Qᴜᴇꜱᴛɪᴏɴꜱ.
pratikshagarkar871999@gmail.com
Comments
Post a Comment
If you have any doubt, please let me know. To check my other blog kindly check the following links:
https://pythoholic.blogspot.com/
If you are interested in reading Marathi stories and other stuff, kindly check the following link.
https://pratilipi.page.link/q8dZ4ffZwKPHUx6R9
ꜰᴏʀ ᴇxᴘʟᴏʀɪɴɢ ᴛʜᴇ ᴡᴏʀʟᴅ ᴘʟᴇᴀꜱᴇ ʜᴀᴠᴇ ʟᴏᴏᴋ ᴀɴᴅ ꜰᴏʟʟᴏᴡ.
https://maps.app.goo.gl/jnKyzdDpKMFutUqR7