2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Linuxコマンドを用いてテキストマイニング【聖書】

Last updated at Posted at 2020-07-07

奈佐原顕郎氏の著作『入門者のLinux』(ブルーバックス出版)の282ページに記載されている内容を
自分でやってみる。

0. はじめに

彼(奈佐原顕郎氏)は以前、聖書の解析を行ったようです。
聖書の中で最もよく使われる単語は「The」で、「and」「of」「to」「that」の順なのだそうです。
本当にそうなのか、自分もやってみます。

1. データの取得

テキストファイル形式の聖書を探してみると、Githubにありました。
こっそりお借りします。
下中央にある「View Law」を押すと手頃なテキストデータが開きます。
Ctrl+Aで全選択し、Ctrl+Cでコピーしましょう。

bible.txt
Screenshot from 2020-07-07 22-12-59.png

続いて、ターミナルを開きます(UbuntuであればCtrl+Alt+T)。

$ cat > bible

として、先ほどコピーした部分をターミナルの上にペーストし、Enterを押し、Ctrl+Cで完了です。

2. 頻出単語の調査(テキストマイニング例)

では早速、聖書の中で最もよく使われる単語を調べます。
ターミナルにコマンドを打ち込みます。

$ cat bible | sed 's/[,|.|:|;|"|?| ]/\n/g' | tr A-Z a-z | sort | uniq -c | sort -n -r | less

result_bible.png

「the」が64184回で、確かに頻出単語のようですね。
そして記載通り「and」「of」「to」「that」の順に多いようです。
スペースキーを押してどんどん下まで見ていきましょう。終了するときは q を押します。

3. メモ

『入門者のLinux』は非常にわかりやすい本でした。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?