flashgeotext
v0.5.3
从文本中提取和计算国家和城市(及其同义词),例如使用 FlashText(Aho-Corasick 实现)的 GeoText。 Flashgeotext 是一个快速、包含电池(和 BYOD)的原生 Python 库,可以从输入文本中提取一组或多组给定的城市和国家名称(+同义词)。
介绍性博文:https://iwpnd.github.io/articles/2020-02/flashgeotext-library
from flashgeotext . geotext import GeoText
geotext = GeoText ()
input_text = '''Shanghai. The Chinese Ministry of Finance in Shanghai said that China plans
to cut tariffs on $75 billion worth of goods that the country
imports from the US. Washington welcomes the decision.'''
geotext . extract ( input_text = input_text )
>> {
'cities' : {
'Shanghai' : {
'count' : 2 ,
'span_info' : [( 0 , 8 ), ( 45 , 53 )],
'found_as' : [ 'Shanghai' , 'Shanghai' ],
},
'Washington, D.C.' : {
'count' : 1 ,
'span_info' : [( 175 , 185 )],
'found_as' : [ 'Washington' ],
}
},
'countries' : {
'China' : {
'count' : 1 ,
'span_info' : [( 64 , 69 )],
'found_as' : [ 'China' ],
},
'United States' : {
'count' : 1 ,
'span_info' : [( 171 , 173 )],
'found_as' : [ 'US' ],
}
}
}
这些说明将为您提供在本地计算机上启动并运行的项目副本,以用于开发和测试目的。
点:
pip install flashgeotext
康达:
conda install flashgeotext
用于开发:
git clone https://github.com/iwpnd/flashgeotext.git
cd flashgeotext/
poetry install
poetry run pytest . -v
另请参阅参与该项目的贡献者列表。
该项目已根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE.md 文件
演示数据城市来自 http://www.geonames.org,已获得 Creative Commons Attribution 3.0 许可证的许可。