1

I am using Python geograpy library to extract city names from a text Here is my code:-

import geograpy

text='I live in Kadawatha'

places = geograpy.get_place_context(text=text)

print(places.country_cities)

OUTPUT:- { }

When I extract city names from a URL it works but from a text, it is not possible and also there is another way to do this by using geograpy.extraction but that is not extracting all possible city names so that I want to use above mentioned way to do this. In additionally there is another question(Unable to extract countries/cities name from text file using geograpy) related to this but that is also not working.

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186

2 Answers2

1

Kadawatha is according to wikipedia not considered a city but a suburb https://www.wikidata.org/wiki/Q2041605. It's not in the list of cities supported by geograpy.

As a committer of geograpy3 to reproduce your issue i added a test to the most recent geograpy3 https://github.com/somnathrakshit/geograpy3/blob/master/tests/test_extractor.py:

where:

def testStackOverflow54721435(self):
        '''
        see https://stackoverflow.com/questions/54721435/unable-to-extract-city-names-from-a-text-using-geograpypython
        '''
        text='I live in Kadawatha a suburb of Colombo  Sri Lanka'
        e=Extractor(text=text)
        e.find_entities()
        print(e.places)

returns:

['Kadawatha', 'Colombo Sri Lanka']
Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
-1

for this to work you need to install geograpy-nltk

ohlr
  • 1,839
  • 1
  • 13
  • 29
  • How is geograpy-nltk installed? – Wolfgang Fahl Sep 08 '20 at 13:44
  • thx for trying - but no - its a script command installed with geograpy at least with a more recent version see https://github.com/somnathrakshit/geograpy3 and the script at https://github.com/somnathrakshit/geograpy3/blob/master/geograpy/bin/geograpy-nltk please edit your answer accordingly and I'll upvote – Wolfgang Fahl Sep 11 '20 at 06:47