pygeonlp.api.workflow module

class pygeonlp.api.workflow.Workflow(db_dir=None, address_regex=None, jageocoder=None, scoring_class=None, scoring_options=None, filters=None, **options)

ベースクラス: object

一連のジオパース処理を行なうワークフロー。

parser

テキストを解析し、地名語を埋め込む Parser のインスタンス。 Parser はテキスト(文字列)からラティス表現を作成します。

Type:

pygeonlp.parser.Parser

filters

ラティス表現に含まれる候補に対し、条件による選別を行い、 候補を絞り込む Filter インスタンスのリスト。 リストの順番に Filter を適用します。

Type:

list of pygeonlp.filter.Filter

evaluator

ラティス表現から順位付きパス表現を作成する Evaluator のインスタンス。

Type:

pygeonlp.linker.Evaluator

__init__(db_dir=None, address_regex=None, jageocoder=None, scoring_class=None, scoring_options=None, filters=None, **options)

パーザを初期化します。

パラメータ:
  • db_dir (PathLike, optional) -- データベースディレクトリ。 省略した場合は api.init.get_db_dir() が返す値を利用します。

  • address_regex (str, optional) -- 住所表記の開始とみなす地名語の固有名クラスを表す正規表現。 省略した場合、r'^(都道府県|市区町村|行政地域|居住地名)(/.+|)' を利用します。

  • jageocoder (jageocoder.tree.AddressTree, optional) -- 利用する住所ジオコーダーを指定します。省略した場合、 jageocoder モジュールのデフォルトオブジェクトを利用します。 False を指定した場合、ジオコーディング機能を利用しません。

  • scoring_class (class, optional) -- パスのスコアとノード間のスコアを計算する関数を持つ スコアリングクラス。 指定しない場合、pygeonlp.api.scoring モジュール内の ScoringClass が利用されます。

  • scoring_options (any, optional) -- スコアリングクラスの初期化に渡すオプションパラメータ。

  • filters (list) -- 適用するフィルタオブジェクトのリスト。 省略した場合は InputBasedFilter がセットされます。

activateDictionaries(idlist=None, pattern=None)
disactivateDictionaries(idlist=None, pattern=None)
geoparse(sentence: str)

文を解析して GeoJSON Feature 形式に変換可能な dict の リストを返します。

パラメータ:

sentence (str) -- 解析する文字列

戻り値:

GeoJSON Feature 形式に変換可能な dict のリスト。

戻り値の型:

list

サンプル

>>> import pygeonlp.api as api
>>> api.init()
>>> workflow = api.workflow.Workflow()
>>> workflow.geoparse('国会議事堂前まで歩きました。')
[{'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [139.74305333333334, 35.673543333333335]}, 'properties': {'surface': '国会議事堂前', 'node_type': 'GEOWORD', 'morphemes': {'conjugated_form': '*', 'conjugation_type': '*', 'original_form': '国会議事堂前', 'pos': '名詞', 'prononciation': '', 'subclass1': '固有名詞', 'subclass2': '地名語', 'subclass3': 'cE8W4w:国会議事堂前駅', 'surface': '国会議事堂前', 'yomi': ''}, 'geoword_properties': {'body': '国会議事堂前', 'dictionary_id': 3, 'entry_id': '4NFELa', 'geolod_id': 'cE8W4w', 'hypernym': ['東京地下鉄', '9号線千代田線'], 'institution_type': '民営鉄道', 'latitude': '35.673543333333335', 'longitude': '139.74305333333334', 'ne_class': '鉄道施設/鉄道駅', 'railway_class': '普通鉄道', 'suffix': ['駅', ''], 'dictionary_identifier': 'geonlp:ksj-station-N02'}}}, {'type': 'Feature', 'geometry': None, 'properties': {'surface': 'まで', 'node_type': 'NORMAL', 'morphemes': {'conjugated_form': '*', 'conjugation_type': '*', 'original_form': 'まで', 'pos': '助詞', 'prononciation': 'マデ', 'subclass1': '副助詞', 'subclass2': '*', 'subclass3': '*', 'surface': 'まで', 'yomi': 'マデ'}}}, {'type': 'Feature', 'geometry': None, 'properties': {'surface': '歩き', 'node_type': 'NORMAL', 'morphemes': {'conjugated_form': '五段・カ行イ音便', 'conjugation_type': '連用形', 'original_form': '歩く', 'pos': '動詞', 'prononciation': 'アルキ', 'subclass1': '自立', 'subclass2': '*', 'subclass3': '*', 'surface': '歩き', 'yomi': 'アルキ'}}}, {'type': 'Feature', 'geometry': None, 'properties': {'surface': 'まし', 'node_type': 'NORMAL', 'morphemes': {'conjugated_form': '特殊・マス', 'conjugation_type': '連用形', 'original_form': 'ます', 'pos': '助動詞', 'prononciation': 'マシ', 'subclass1': '*', 'subclass2': '*', 'subclass3': '*', 'surface': 'まし', 'yomi': 'マシ'}}}, {'type': 'Feature', 'geometry': None, 'properties': {'surface': 'た', 'node_type': 'NORMAL', 'morphemes': {'conjugated_form': '特殊・タ', 'conjugation_type': '基本形', 'original_form': 'た', 'pos': '助動詞', 'prononciation': 'タ', 'subclass1': '*', 'subclass2': '*', 'subclass3': '*', 'surface': 'た', 'yomi': 'タ'}}}, {'type': 'Feature', 'geometry': None, 'properties': {'surface': '。', 'node_type': 'NORMAL', 'morphemes': {'conjugated_form': '*', 'conjugation_type': '*', 'original_form': '。', 'pos': '記号', 'prononciation': '。', 'subclass1': '句点', 'subclass2': '*', 'subclass3': '*', 'surface': '。', 'yomi': '。'}}}]
getActiveClasses()
getActiveDictionaries()
get_processible_lattice_part(lattice)

組み合わせの候補数が MAX_COMBINATIONS 未満になるように ラティスの先頭部分から区切りの良い一部分を抽出するジェネレータ。

パラメータ:

lattice (list) -- 入力となるラティス表現。

戻り値:

先頭部分から切り出した部分的なラティス表現。

戻り値の型:

list

注釈

この関数はジェネレータなので yield で返します。

入力テキストの区切り文字が事前に分かっている場合や、 途中で分割されたくない場合には、意図した位置で分割するように オーバーライドしてください。

setActiveClasses(patterns=None)
setActiveDictionaries(idlist=None, pattern=None)
class pygeonlp.api.workflow.WorkflowError

ベースクラス: RuntimeError

ワークフロー処理の際に例外が起こると、このクラスが発生します。