1

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.

perde
  • 35
  • 4
  • 1
    Are all the other fields empty, like `places.other`? Does `text = 'I am from the United Kingdom'` do anything different? – Random Davis Nov 18 '20 at 21:54
  • Yes, it identifies correctly `['United Kingdom']` with `places.countries` with the `text = 'I am from the United Kingdom'`. The `places.other` field contains `['UK']` with the original text. I am not sure if this should make sense, though - why is the UK not identified as a country? – perde Nov 23 '20 at 10:04

1 Answers1

3

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']
Sash Sinha
  • 18,743
  • 3
  • 23
  • 40
  • Great, thank you, it works! But I am not sure why the 'UK' doesn't appear under `places.countries` - is there a reason for it and is this the desired behaviour? – perde Nov 23 '20 at 10:06
  • 1
    Not sure, `USA` seems to also be put in other but interestingly `NZ` seems to be placed under regions, and `New Zealand` placed under countries at the same time. Maybe it is just how unambiguous it is or something – Sash Sinha Nov 23 '20 at 14:41