如何检查字符串是否相似

How to check if strings are similar

我有以下字符串

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

text下的第一个是输入字符串,第二个是匹配的字符串。最后是他们的 fuzzywuzzy 比率。我是这样匹配的:

ratio = fuzz.partial_ratio(t.lower(), txt.lower())

如果国家/地区名称不同,它应该 return 比相似时得分低。有什么办法吗?

根据您提供的代码,要比较的文本似乎具有

的模式

country_name + "guidances/regulations"

可以通过spilt()方法获取国家名称

>>> str = 'US guidances/regulations'
>>> myList = str.split(' ') //spilt by the space after the country name
>>> myList[0]
US
>>> myList[1]
guidances/regulations

然后只比较国家名称

anotherStr = 'USA guidances/regulations'
anotherList = anotherStr.split(' ') //spilt by the space after the country name
ratio = fuzz.partial_ratio(myList[0].lower(), anotherList[0]())