OCR / app /extract_country /country_validator.py
ShahzainHaider's picture
Upload folder using huggingface_hub
7bbae49
raw
history blame
429 Bytes
import pycountry
import re
def extract_country_name(string):
pattern = r"\b[A-Za-z ]+\b" # Matches any sequence of letters and spaces
matches = re.findall(pattern, string)
for match in matches:
try:
country = pycountry.countries.lookup(match)
print("COUNTRY : ",country.name)
return True, country.name
except LookupError:
pass
return False, None