開発環境
- macOS High Sierra - Apple
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
入門 自然言語処理 (Steven Bird (著)、Ewan Klein (著)、Edward Loper (著)、萩原 正人 (翻訳)、中山 敬広 (翻訳)、水野 貴明 (翻訳)、オライリージャパン)の1章(言語処理とPython)、1.8(演習問題)11、12、13、14.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
print('11.')
phrase1 = ['dog', 'cat']
phrase2 = ['python', 'javascript', 'language']
l1 = len(phrase1 + phrase2)
l2 = len(phrase1) + len(phrase2)
print(l1 == l2)
print('12.')
print('(b)(?)')
print('13')
from nltk.book import *
# sent1[2]は文字列 sent1[2][2]は文字(文字列)
print(sent1)
print(sent1[2])
print(sent1[2][2])
print(type(sent1[2][2]) == str)
print('14.')
# 5 8
print(sent3)
for i, s in enumerate(sent3):
if s == 'the':
print(i)
入出力結果(Terminal, Jupyter(IPython))
$ ./sample10.py 11. True 12. (b)(?) 13 *** 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 ['Call', 'me', 'Ishmael', '.'] Ishmael h True 14. ['In', 'the', 'beginning', 'God', 'created', 'the', 'heaven', 'and', 'the', 'earth', '.'] 1 5 8 $
0 コメント:
コメントを投稿