Reputation: 45
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.
Upvotes: 1
Views: 1461
Reputation: 15769
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']
Upvotes: 1