I have the following strings
JavaScript
x
21
21
1
text
2
USA guidances/regulations
3
US guidances/regulations
4
96
5
text
6
US guidances/regulations
7
US guidances/regulations
8
100
9
text
10
Australia guidances/regulations
11
US guidances/regulations
12
92
13
text
14
China Guidances/Regulations
15
US guidances/regulations
16
92
17
text
18
EU guidances/regulations
19
US guidances/regulations
20
98
21
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:
JavaScript
1
2
1
ratio = fuzz.partial_ratio(t.lower(), txt.lower())
2
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
JavaScript
1
7
1
>>> str = 'US guidances/regulations'
2
>>> myList = str.split(' ') //spilt by the space after the country name
3
>>> myList[0]
4
US
5
>>> myList[1]
6
guidances/regulations
7
then compare only the Country name
JavaScript
1
4
1
anotherStr = 'USA guidances/regulations'
2
anotherList = anotherStr.split(' ') //spilt by the space after the country name
3
ratio = fuzz.partial_ratio(myList[0].lower(), anotherList[0]())
4