入門 自然言語処理 第1章まとめ

nltkをインポートする

import nltk
from nltk.book import *

ある単語がどのような文脈で使われているか

text1.concordance("monstrous")

ある単語と同じ文脈で使われる単語にはどんなものがあるか

text1.similar("monstrous")

2以上の単語で共通に使われる文脈

text2.common_contexts(["monstrous", "very"])

テキスト中の単語の出現回数や出現場所をプロットする

text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])

テキストのスタイルを元に出鱈目なテキストを生成する

text3.generate()

重複を排除する

set(text)

頻度分布を取得する

fdist = FreqDist(text)

頻度分布のキーを取得する

fdist.keys()

累積頻度プロット

fdist1.plot(50, cumulative=True)

バイグラムを取得する

bigrams(["more", "is", "said", "than", "done"]

コロケーションを取得する
意味があるそうな単語のバイグラムを取得する

text4.collocations()

機械翻訳

babelize_shell()
Babel> how long before the next flight to Alice Spring?
Babel> german
Babel> run