flashgeotext
v0.5.3
Aho-Corasick の実装である FlashText を使用した強化版の GeoText のように、テキストから国と都市 (+その同義語) を抽出してカウントします。 Flashgeotext は、入力テキストから指定された都市名と国名 (+ 同義語) の 1 つ以上のセットを抽出する、高速でバッテリー付属 (および 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 のデモ データ都市は、クリエイティブ コモンズ表示 3.0 ライセンスに基づいてライセンスされています。