演説における普通名詞の頻度
TextCasesを使って,例えば名詞あるいは動詞,国,電子メールアドレス,その他の指定の形式の部分文字列を取り出す.
アメリカ合衆国の両院合同会議でのアメリカ大統領によるすべての演説のデータ集合を取り出す.
In[1]:=
![Click for copyable input](assets.ja/frequency-of-common-nouns-in-speeches/In_81.png)
data = ResourceData["State of the Union Addresses"];
大統領名,演説の行われた年,演説原稿だけを残すことでデータ集合のサイズを小さくする.
In[2]:=
![Click for copyable input](assets.ja/frequency-of-common-nouns-in-speeches/In_82.png)
reduceddata = data[All, {"President", "Year", "Text"}];
演説のサンプルを10年間隔で取り出す.
In[3]:=
![Click for copyable input](assets.ja/frequency-of-common-nouns-in-speeches/In_83.png)
years = Range[1965, 2015, 10];
speeches = Select[reduceddata, MemberQ[years, #Year] &]
Out[3]=
![](assets.ja/frequency-of-common-nouns-in-speeches/O_57.png)
TextCasesを使って各演説に含まれる名詞を特定する.
In[4]:=
![Click for copyable input](assets.ja/frequency-of-common-nouns-in-speeches/In_84.png)
nouns = TextCases[Normal@speeches[All, "Text"], "Noun"];
各演説で使われた他とは異なる単語すべての頻度を数える.
In[5]:=
![Click for copyable input](assets.ja/frequency-of-common-nouns-in-speeches/In_85.png)
freqnouns = Counts /@ nouns;
ほとんどの年に共通している単語を無視する.
In[6]:=
![Click for copyable input](assets.ja/frequency-of-common-nouns-in-speeches/In_86.png)
freqnouns =
KeyDrop[freqnouns, {"country", "people", "year", "years", "world"}];
時間の変化の中での名詞頻度を示すWordCloudsを生成する.
完全なWolfram言語入力を表示する
Out[7]=
![](assets.ja/frequency-of-common-nouns-in-speeches/O_58.png)