I have the following strings
text USA guidances/regulations US guidances/regulations 96 text US guidances/regulations US guidances/regulations 100 text Australia guidances/regulations US guidances/regulations 92 text China Guidances/Regulations US guidances/regulations 92 text EU guidances/regulations US guidances/regulations 98
First one under text is input string and the second is the one against which it is matched. Last is their fuzzywuzzy ratio. I’m matching it like this:
ratio = fuzz.partial_ratio(t.lower(), txt.lower())
If the country name is different it should return a lower score as opposed to when it is similar. Is there any way to do this?
Advertisement
Answer
According to the code you’ve provided, the text to compare seems to have a pattern of
country_name + "guidances/regulations"
You can get the country name by spilt() method
>>> str = 'US guidances/regulations' >>> myList = str.split(' ') //spilt by the space after the country name >>> myList[0] US >>> myList[1] guidances/regulations
then compare only the Country name
anotherStr = 'USA guidances/regulations' anotherList = anotherStr.split(' ') //spilt by the space after the country name ratio = fuzz.partial_ratio(myList[0].lower(), anotherList[0]())