[Python]アメリカ合衆国大統領の大統領就任演説のテキストを得る
nltkモジュールを使う。初代のワシントンから、2021年就任のバイデン大統領までが含まれている。
>>> import nltk
>>> from nltk.corpus import inaugural
>>> ss = nltk.corpus.inaugural.fileids()
>>> len(ss)
59
>>> ss[0:3]
['1789-Washington.txt', '1793-Washington.txt', '1797-Adams.txt']
>>> ss[-1:-5:-1]
['2021-Biden.txt', '2017-Trump.txt', '2013-Obama.txt', '2009-Obama.txt']
試しに、2009年に就任したオバマ大統領の一部を表示してみる。
>>> ss[-4]
'2009-Obama.txt'
>>> s = inaugural.raw(ss[-4])
>>> s[0:70]
'My fellow citizens:\n\nI stand here today humbled by the task before us,'
新聞社のウェブサイトの記事でも公開されており、一致していることが確認できる。
http://www.asahi.com/special/081113/TKY200901200391.html