2018年5月21日月曜日

開発環境

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

コード(Emacs)

Python 3

#!/usr/bin/env python3

print('20.')

# isupper は大文字だと真
# not islower は小文字でなければ真
# 大文字小文字の違いがない文字で結果が異なる

w = '蛇'

for t in [w, w.isupper(), not w.islower()]:
    print(t)

print('21.')
from nltk.book import *

print(text2[-2:])

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

$ ./sample14.py
20.
蛇
False
True
21.
*** 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
['THE', 'END']
$

0 コメント:

コメントを投稿