Bunsetsu modules

BunsetsuList module

class pyknp.knp.blist.BList(spec='', pattern='EOS', juman_format=0)[source]

Bases: object

ある文に関する文節列を保持するオブジェクト

Parameters
  • spec (str) – KNP出力

  • pattern (str) – KNP出力の終端記号

  • juman_format (JUMAN_FORMAT) – Jumanのlattice出力形式

comment

KNP出力における、#から始まる行に書かれた文字列

Type

str

sid

文ID (KNP出力中のS-ID)

Type

str

__init__(spec='', pattern='EOS', juman_format=0)[source]

Initialize self. See help(type(self)) for accurate signature.

parse(spec)[source]

KNPの出力を読み取る

Parameters

spec (str) – KNP出力

get_tag_span(tag_id)[source]

基本句の位置情報を返す

Parameters

tag_id (int) – 基本句ID

Returns

(基本句の開始位置, 終了位置)

Return type

tuple

push_bnst(bnst)[source]
tag_list()[source]

文を構成する全基本句オブジェクトを返す

Returns

基本句オブジェクトTagのリスト

Return type

list of Tag

mrph_list()[source]

文を構成する全形態素オブジェクトを返す

Returns

形態素オブジェクトMorphemeのリスト

Return type

list of Morpheme

bnst_list()[source]

文を構成する全文節オブジェクトを返す

Returns

文節オブジェクトBunsetsuのリスト

Return type

list of Bunsetsu

set_readonly()[source]
spec()[source]
all()[source]

KNPの出力結果を返す

draw_tree(fh=None, show_pos=True)[source]
draw_bnst_tree(fh=None, show_pos=True)[source]

文節列の依存関係を木構造として表現して出力する.

draw_tag_tree(fh=None, show_pos=True)[source]

タグ列の依存関係を木構造として表現して出力する.

sprint_tree(show_pos=True)[source]
get_clause_starts(concat_clause_in_paren=False, discourse_clause=False)[source]

節の冒頭句の位置情報を返す

Parameters
  • concat_clause_in_paren (bool) – 括弧内では節を切らないかどうか

  • discourse_clause (bool) – 補文節、連体修飾節を切らないかどうか

Returns

節の冒頭となる基本句idのリスト

Return type

list

Bunsetsu module

class pyknp.knp.bunsetsu.Bunsetsu(spec, bnst_id=0, juman_format=0)[source]

Bases: object

KNP による係り受け解析の単位である文節の各種情報を保持するオブジェクト.

Parameters
  • spec (str) – KNP出力のうち文節に該当する箇所の文字列

  • bnst_id (int) – 文節ID

  • juman_format (JUMAN_FORMAT) – Jumanのlattice出力形式

bnst_id

文節ID

Type

int

midasi

見出し

Type

str

parent

親の文節オブジェクト

Type

Bunsetsu

parent_id

親の文節ID

Type

int

children

子の文節オブジェクトのリスト

Type

list

repname

正規化代表表記 (normalized_repnameに同じ)

Type

str

normalized_repname

正規化代表表記

Type

str

head_repname

主辞代表表記

Type

str

head_prime_repname

主辞’代表表記

Type

str

fstring

feature情報

Type

str

__init__(spec, bnst_id=0, juman_format=0)[source]

Initialize self. See help(type(self)) for accurate signature.

push_mrph(mrph)[source]

新しい形態素オブジェクトをセットする

push_tag(tag)[source]

新しい基本句オブジェクトをセットする

set_midasi()[source]

midasiをセットする

spec()[source]

文節に対応するKNP出力

mrph_list()[source]

文節を構成する全形態素オブジェクトを返す

Returns

形態素オブジェクトMorphemeのリスト

Return type

list

tag_list()[source]

文節を構成する全基本句オブジェクトを返す

Returns

基本句オブジェクトTagのリスト

Return type

list

pstring(string=None)[source]

draw_treeしたときに右側に出力する文字列を返す