我有这样的字符串列表:
["Ola, Uber's India rival, invests $100M in scooter rental startup Vogo","Chattanooga startup Bellhops Moving raises over $31 million in latest", "Boston biotech Entrada launches with $59M to tackle deadly disease"]
我想从字符串列表中识别印度,波士顿,查塔努加等字符串,这些字符串可以是城市,城镇,国家,州或大洲,并按地区进行分类。
我无法找到实现此特定输出的正确路径或方式。任何建议都会很有帮助。
答案 0 :(得分:2)
您需要使用GeoText
库。您可以通过在Windows的命令提示符cmd
中键入以下内容来安装它。
pip install https://github.com/elyase/geotext/archive/master.zip
安装后,您可以提取城市和国家/地区。
from geotext import GeoText
your_list=["Ola, Uber's India rival, invests $100M in scooter rental startup Vogo","Chattanooga startup Bellhops Moving raises over $31 million in latest", "Boston biotech Entrada launches with $59M to tackle deadly disease"]
complete_string=','.join(map(str,your_list) ) # converting the list 'your_list' to string
locations=GeoText(complete_string)
locations.countries
['India']
locations.cities
['Chattanooga', 'Boston']
答案 1 :(得分:0)
要检测国家和城市,您可以使用地理文字:https://pypi.org/project/geotext/