Tag modules

TagList module

class pyknp.knp.tlist.TList[source]

Bases: object

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

__init__()[source]

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

push_tag(tag)[source]
push_mrph(mrph)[source]
push_synnodes(synnodes)[source]
push_synnode(synnode)[source]
spec()[source]
set_readonly()[source]
draw_tree(fh=None, show_pos=True)[source]
draw_tag_tree(fh=None, show_pos=True)[source]

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

sprint_tree()[source]
tag_list()[source]

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

Returns

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

Return type

list of Tag

Tag module

class pyknp.knp.tag.Tag(spec, tag_id=0, juman_format=0)[source]

Bases: object

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

Parameters
  • spec (str) – KNP出力

  • tag_id (int) – 基本句ID

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

tag_id

基本句ID

Type

int

midasi

見出し

Type

str

parent

親の基本句オブジェクト

Type

Tag

parent_id

親の基本句ID

Type

int

children

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

Type

list

dpndtype

係り受けタイプ

Type

str

fstring

feature情報

Type

str

repname

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

Type

str

normalized_repname

正規化代表表記

Type

str

head_repname

主辞代表表記

Type

str

head_prime_repname

主辞’代表表記

Type

str

pred_repname

用言代表表記

Type

str

disambiguated_pred_repname

標準用言代表表記

Type

str

features

基本句のfeatureを表すFeatureオブジェクト

Type

Features

pas

基本句が述語の場合は項の情報(Pasオブジェクト), そうでない場合None

Type

Pas

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

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

push_mrph(mrph)[source]

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

set_midasi()[source]

midasiをセットする

spec()[source]

基本句に対応するKNP出力

mrph_list()[source]

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

Returns

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

Return type

list

pstring(string=None)[source]

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

get_surface()[source]

基本句の見出しを返す

Returns

基本句の見出し

Return type

str

PAS module

class pyknp.knp.pas.Pas(tid=None, result=None)[source]

Bases: object

述語項構造を扱うクラス

Usage:

result = knp.result(knp_result) pas = result.tag_list()[tid].pas # tid番目の基本句(述語)の項構造

cfid

格フレームID (例: “行う/おこなう:動10”)

Type

str

arguments

格と項を対応付けた辞書 {case: [Argument, ..]} keyは格を表す文字列, valueはArgumentオブジェクトのリスト。 リスト形式なのは、ガ格などは複数の項を取り得るため。

Type

dict of (case, list of Argument)

__init__(tid=None, result=None)[source]

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

is_valid()[source]
get_arguments(case)[source]

指定した格の各項ごとに代表表記の配列を返す

Usage:

result = knp.parse(“研究者になる”) print(result.tag_list()[2].midasi) >> なる print(result.tag_list()[2].pas.get_arguments(“ニ”)) >> [ArgRepname(repname=’者/しゃ’, tid_list=1)]

Parameters

case (str) – 格の文字列

Returns

項の代表表記を格納したnamedtupleである ArgRepname のリスト

Return type

list

get_orig_result()[source]
class pyknp.knp.pas.Argument(sid=None, tid=None, eid=None, midasi='', flag=None, sdist=None)[source]

Bases: object

項に関する情報を保持するオブジェクト

詳しくは下記ページの「格要素側」の記述方法を参照 http://nlp.ist.i.kyoto-u.ac.jp/index.php?KNP%2F%E6%A0%BC%E8%A7%A3%E6%9E%90%E7%B5%90%E6%9E%9C%E6%9B%B8%E5%BC%8F

sid

文ID

Type

str

tid

基本句ID

Type

int

eid

Entity ID

Type

int

midasi

表記

Type

str

flag

フラグ (C, N, O, D, E, U)

Type

str

sdist

述語の何文前か

Type

int

__init__(sid=None, tid=None, eid=None, midasi='', flag=None, sdist=None)[source]

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

Feature module

class pyknp.knp.features.Features(spec, splitter='><', ignore_first_character=True)[source]

Bases: dict

feature情報を保持するオブジェクト

feature情報に含まれるタグをパースし、辞書形式にする。 ex. “<正規化代表表記:遅れる/おくれる>” –> {“正規化代表表記”: “遅れる/おくれる”}

__init__(spec, splitter='><', ignore_first_character=True)[source]

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

property pas