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 授權的許可。