2018年3月18日日曜日

開発環境

入門 自然言語処理 (Steven Bird (著)、Ewan Klein (著)、Edward Loper (著)、萩原 正人 (翻訳)、中山 敬広 (翻訳)、水野 貴明 (翻訳)、オライリージャパン)の1章(言語処理とPython)、1.8(演習問題)6を取り組んでみる。

コード(Emacs)

Python 3

#!/usr/bin/env python3

from nltk.book import *


fdist = FreqDist(text2)
names = ['Elinor', 'Marianne', 'Edward', 'Willoughby']

for name in names:
    print(f'{name:10}: {fdist[name]}')

入出力結果(Terminal, Jupyter(IPython))

$ ./sample6.py
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
Elinor    : 684
Marianne  : 566
Edward    : 262
Willoughby: 215
$

0 コメント:

コメントを投稿