perde
perde

Reputation: 35

Unable to extract country name 'UK' from text using geograpy

I am trying to extract the UK as a country name from text file using geograpy, but It's returning an empty list. My code is:

import geograpy
text = 'I am from the UK'
places = geograpy.get_place_context(text=text)

print (places.countries)

Output:

[]

Is there a way get ['UK'] as an output? Thank you.

Upvotes: 1

Views: 503

Answers (1)

Sash Sinha
Sash Sinha

Reputation: 22472

Try places.other:

lists everything that wasn't clearly a country, region or city.

import geograpy

text = 'I am from the UK'
places = geograpy.get_place_context(text=text)
print(places.other)

Output:

['UK']

Upvotes: 3

Related Questions