rhoknp.cohesion.coreference module¶
- class rhoknp.cohesion.coreference.Entity(eid: int, exophora_referent: ExophoraReferent | None = None)[source]¶
Bases:
object共参照におけるエンティティ.
- Parameters:
eid – エンティティ ID.
exophora_referent – 自身が外界照応の照応先に対応するなら照応先の種類. 対応しないなら None.
- eid¶
エンティティ ID.
- exophora_referent¶
外界照応の照応先.対応するものがなければ None.
- mentions: list['BasePhrase']¶
このエンティティを参照するメンションのリスト.
- mentions_nonidentical: list['BasePhrase']¶
このエンティティを≒関係で参照するメンションのリスト.
- property mentions_all: list[BasePhrase]¶
nonidentical を含めたこのエンティティを参照する全てのメンションのリスト.
- add_mention(mention: BasePhrase, is_nonidentical: bool = False) None[source]¶
このエンティティを参照するメンションを追加.
- Parameters:
mention – 追加対象のメンション.
is_nonidentical – メンションが nonidentical(”≒” 付きでアノテーションされている)なら True.
Note
identical なメンションが追加されたとき,すでに nonidentical なメンションとして登録されていたら, identical なメンションとして上書きする.
- remove_mention(mention: BasePhrase) None[source]¶
このエンティティを参照するメンションを削除.
- Parameters:
mention – 削除対象のメンション.
- class rhoknp.cohesion.coreference.EntityManager[source]¶
Bases:
object文書全体のエンティティを管理.
- classmethod get_or_create_entity(exophora_referent: ExophoraReferent | None = None, eid: int | None = None) Entity[source]¶
自身が参照するエンティティを作成.
exophora_referent が singleton entity だった場合を除き,新しく Entity のインスタンスを作成して返す. singleton entity とは,「著者」や「不特定:人1」などの文書中に必ず一つしか存在しないような entity. 一方で,「不特定:人」や「不特定:物」は複数存在しうるので singleton entity ではない.
- Parameters:
exophora_referent – 外界照応における照応先.対応するものがなければ None.
eid – エンティティ ID.None の場合自動で割り振る.
- Returns:
作成されたエンティティ.
- Return type:
- classmethod merge_entities(source_mention: BasePhrase, target_mention: BasePhrase | None, source_entity: Entity, target_entity: Entity, is_nonidentical: bool) None[source]¶
2つのエンティティをマージ.
source_mention と source_entity, target_mention と target_entity の間には参照関係があるが, source と target 間には関係が作られていないので,add_mention する. source_entity と target_entity が同一のエンティティであり,exophor も同じか片方が None ならば target_entity の方を削除する.
- Parameters:
source_mention – ソース側メンション.
target_mention – ターゲット側メンション.メンションが存在しない場合は None.
source_entity – ソース側エンティティ.
target_entity – ターゲット側エンティティ.
is_nonidentical – ソース側メンションとターゲット側メンションの関係が nonidentical なら True.