使用地理图形3(https://pypi.org/project/geograpy3/):
> import geograpy
> text = "Welcome to beautiful Seattle"
> p = geograpy.get_geoPlace_context(text=text)
> p.cities
['Seattle']
> p.countries
['United States']
> p.regions
[]
是否有我需要下载的包或数据集?
我是作为geograpy3的提交者回答的。有一个新的定位器界面,旨在改善歧义消除和定位。它还没有与自然语言处理部分完全集成——欢迎提出问题和拉取请求。。。
def testStackOverflow64418919(self):
'''
https://stackoverflow.com/questions/64418919/problem-retrieving-region-in-us-with-geograpy3
'''
examples=['Seattle']
for example in examples:
city=geograpy.locateCity(example,debug=False)
print(city)
结果:
Seattle (US-WA(Washington) - US(United States))