I am having some text which may or may not contain a country name in it. for example:
' Nigeria: Hotspot Network LTD Rural Telephony Feasibility Study'
this is how I extract the country name from it. in my first attempt:
findcountry("Nigeria: Hotspot Network LTD Rural Telephony Feasibility Study")
def findCountry(stringText):
for country in pycountry.countries:
if country.name.lower() in stringText.lower():
return country.name
return None
unfortunately, it gives me the wrong output as [Niger]
whereas the correct one is Nigeria. Note Niger and Nigeria are two different existing countries in the world.
in second attempt:
def findCountry(stringText):
full_list =[]
for country in pycountry.countries:
if country.name.lower() in stringText.lower():
full_list.append(country)
if len(full_list) > 0:
return full_list
return None
I get ['Niger', 'Nigeria']
as output. but I can't find a way to get Nigeria as my final output. How to achieve this.
Note: here I know Nigeria is the correct answer but later one I will put it to the code to choose the final country name if present in the text and it should be having very high accuracy for detection.