寺田寅彦と菊池寛の作品の文体比較

まず寺田寅彦と小泉八雲について文の長さに違いがあるかどうかを調べてみたいと思います。

寺田寅彦の場合

まずファイルダウンロードして、解凍、ルビ取りをします

たとえば、青空文庫から作品を選び 新字新仮名でほぼ同じサイズのファイルを、適当選び、そのURLを調べます。

夏 1997年 サイズ 7764 http://www.aozora.gr.jp/cards/000042/files/42230_ruby_13987.zip

変わった話 1997年 サイズ9970 http://www.aozora.gr.jp/cards/000042/files/4359_ruby_9270.zip

浮世絵の曲線 1947年 サイズ 4823 http://www.aozora.gr.jp/cards/000042/files/2450_ruby_11083.zip

イタリア人 1996年 サイズ 5606 http://www.aozora.gr.jp/cards/000042/files/24429_ruby_15787.zip

池 1947年 サイズ 5088 http://www.aozora.gr.jp/cards/000042/files/2453_ruby_11077.zip

海水浴 1996年 サイズ 6244 http://www.aozora.gr.jp/cards/000042/files/24427_ruby_15717.zip

この中からサイズが比較的近い4つに限定して解析します

RStudio上でダウンロード、解凍、ルビ取りを行います。

この際、出力ファイル名に作家の頭文字と作品年代を追記します。


source("/var/data/AozoraURL.R")

# 第一引数にURL, 第二引数にルビをとった後のファイル名を指定
Aozora("http://www.aozora.gr.jp/cards/000042/files/24429_ruby_15787.zip", "t_itariazin")
## [1] "./NORUBY/t_itariazin2.txt"
Aozora("http://www.aozora.gr.jp/cards/000042/files/2450_ruby_11083.zip", "t_ukiyoe")
## [1] "./NORUBY/t_ukiyoe2.txt"
Aozora("http://www.aozora.gr.jp/cards/000042/files/2453_ruby_11077.zip", "t_ike")
## [1] "./NORUBY/t_ike2.txt"
Aozora("http://www.aozora.gr.jp/cards/000042/files/24427_ruby_15717.zip", "t_kaisuiyoku")
## [1] "./NORUBY/t_kaisuiyoku2.txt"

(folder <- getwd())  # フォルダを確認
## [1] "/home/c101103024/c101103024"

まとめて解析する

library(RMeCab)
tmp <- paste(folder, "NORUBY", sep = "/")  # 保存先フォルダは、現在のフォルダ下のNORUBY
setwd(tmp)  # 保存先フォルダに移動
txts <- dir()  # 含まれている全ファイル名を指定
tera <- data.frame()  # 解析結果を保存する入れ物

for (i in txts) {
    x <- sum(nchar(readLines(i)))
    y <- RMeCabFreq(i)
    kuten <- y[y$Info2 == "句点", ]
    toten <- y[y$Info2 == "読点", ]
    z <- sum(y$Freq)  # / kuten$Freq
    tera <- rbind(tera, data.frame(text = i, chars = x, words = z, kuten = sum(kuten$Freq), 
        toten = sum(toten$Freq)))
}
## file = t_ike2.txt 
## length = 651 
## file = t_itariazin2.txt 
## length = 808 
## file = t_kaisuiyoku2.txt 
## length = 911 
## file = t_ukiyoe2.txt 
## length = 637

# 結果を確認する
head(tera)
##                text chars words kuten toten
## 1        t_ike2.txt  3831  2408    91   140
## 2  t_itariazin2.txt  3991  2568   103    59
## 3 t_kaisuiyoku2.txt  4728  3027    87    67
## 4     t_ukiyoe2.txt  3673  2293    73    53

文の長さの中央値を求めてみます。

median(tera$words/(tera$kuten + tera$toten))
## [1] 17.03
median(tera$chars/(tera$kuten + tera$toten))
## [1] 26.89

一文あたりの単語数17.0251 は、また文字数は 26.8933 とわかります。

結果をプロットしてみます。

plot(tera$words/(tera$kuten + tera$toten), main = "一文の単語数", xlab = "作品", 
    type = "l")

plot of chunk unnamed-chunk-4

plot(tera$chars/(tera$kuten + tera$toten), main = "一文の文字数", xlab = "作品", 
    type = "l")

plot of chunk unnamed-chunk-4

unlink(tmp, recursive = T)  # 寺田寅彦の解析結果の入ったフォルダをいったん空にする

菊池寛の場合

まずファイルの選定、ダウンロードと処理

入れ札 1988年 サイズ 9320 http://www.aozora.gr.jp/cards/000083/files/486_ruby_19917.zip

恩を返す話 1988年 サイズ 10557 http://www.aozora.gr.jp/cards/000083/files/495_ruby_19922.zip

出世 1988年 サイズ 9205 http://www.aozora.gr.jp/cards/000083/files/500_ruby_19846.zip

大力物語 1988年 サイズ 8128 http://www.aozora.gr.jp/cards/000083/files/50447_ruby_35876.zip

極楽 1960年 サイズ 7229 http://www.aozora.gr.jp/cards/000083/files/2695_ruby_40483.zip

藤十郎の恋 1988年 サイズ 12833 http://www.aozora.gr.jp/cards/000083/files/503_ruby_19915.zip

この中からサイズが比較的近い4つに限定して解析します

source("/var/data/AozoraURL.R")

Aozora("http://www.aozora.gr.jp/cards/000083/files/486_ruby_19917.zip", "k_irehuda")
## [1] "./NORUBY/k_irehuda2.txt"
Aozora("http://www.aozora.gr.jp/cards/000083/files/500_ruby_19846.zip", "k_syusse")
## [1] "./NORUBY/k_syusse2.txt"
Aozora("http://www.aozora.gr.jp/cards/000083/files/50447_ruby_35876.zip", "k_dairiki")
## [1] "./NORUBY/k_dairiki2.txt"
Aozora("http://www.aozora.gr.jp/cards/000083/files/2695_ruby_40483.zip", "k_gokuraku")
## [1] "./NORUBY/k_gokuraku2.txt"

(folder <- getwd())  # フォルダを確認
## [1] "/home/c101103024/c101103024"

まとめて解析する

library(RMeCab)
tmp <- paste(folder, "NORUBY", sep = "/")  # 保存先フォルダは、現在のフォルダ下のNORUBY
setwd(tmp)  # 保存先フォルダに移動
txts <- dir()  # 含まれている全ファイル名を指定
kiku <- data.frame()  # 解析結果を保存する入れ物

for (i in txts) {
    x <- sum(nchar(readLines(i)))
    y <- RMeCabFreq(i)
    kuten <- y[y$Info2 == "句点", ]
    toten <- y[y$Info2 == "読点", ]
    z <- sum(y$Freq)  # / kuten$Freq
    kiku <- rbind(kiku, data.frame(text = i, chars = x, words = z, kuten = kuten$Freq, 
        toten = toten$Freq))
}
## file = k_dairiki2.txt 
## length = 984 
## file = k_gokuraku2.txt 
## length = 912 
## file = k_irehuda2.txt 
## length = 1017 
## file = k_syusse2.txt 
## length = 1077
# 結果を確認

head(kiku)
##              text chars words kuten toten
## 1  k_dairiki2.txt  6684  4567   188   360
## 2 k_gokuraku2.txt  6538  4596   205   316
## 3  k_irehuda2.txt  8923  5959   370   329
## 4   k_syusse2.txt  8845  5738   201   436

文の長さの中央値を求めてみます。

median(kiku$words/(kiku$kuten + kiku$toten))
## [1] 8.673
median(kiku$chars/(kiku$kuten + kiku$toten))
## [1] 12.66

一文あたりの単語数8.6733 は、また文字数は 12.6572 とわかります。

結果をプロットしてみます。

plot(kiku$words/(kiku$kuten + kiku$toten), main = "一文の単語数", xlab = "作品", 
    type = "l")

plot of chunk unnamed-chunk-9

plot(kiku$chars/(kiku$kuten + kiku$toten), main = "一文の文字数", xlab = "作品", 
    type = "l")

plot of chunk unnamed-chunk-9

unlink(tmp, recursive = T)  # 寺田寅彦の解析結果の入ったフォルダをいったん空にする

寺田と菊池に文長に違いかあるか調べます。

boxplot(tera$words/(tera$kuten + tera$toten), kiku$words/(kiku$kuten + kiku$toten), 
    name = c("寺田", "菊池"))

plot of chunk unnamed-chunk-11

この結果をを見ると、寺田虎彦の一文の単語数、文字数は菊池寛の約2倍であり、二人の文長が全く違っているのがわかります。

二人の比較

さらに視点を変えて、二人の作家の助詞および読点の使い分けに差があるかどうかを調べます。

寺田と菊池、それぞれのファイルを読み込みます

source("/var/data/AozoraURL.R")

Aozora("http://www.aozora.gr.jp/cards/000042/files/24429_ruby_15787.zip", "t_itariazin")
## [1] "./NORUBY/t_itariazin2.txt"
Aozora("http://www.aozora.gr.jp/cards/000042/files/2450_ruby_11083.zip", "t_ukiyoe")
## [1] "./NORUBY/t_ukiyoe2.txt"
Aozora("http://www.aozora.gr.jp/cards/000042/files/2453_ruby_11077.zip", "t_ike")
## [1] "./NORUBY/t_ike2.txt"
Aozora("http://www.aozora.gr.jp/cards/000042/files/24427_ruby_15717.zip", "t_kaisuiyoku")
## [1] "./NORUBY/t_kaisuiyoku2.txt"
Aozora("http://www.aozora.gr.jp/cards/000083/files/486_ruby_19917.zip", "k_irehuda")
## [1] "./NORUBY/k_irehuda2.txt"
Aozora("http://www.aozora.gr.jp/cards/000083/files/500_ruby_19846.zip", "k_syusse")
## [1] "./NORUBY/k_syusse2.txt"
Aozora("http://www.aozora.gr.jp/cards/000083/files/50447_ruby_35876.zip", "k_dairiki")
## [1] "./NORUBY/k_dairiki2.txt"
Aozora("http://www.aozora.gr.jp/cards/000083/files/2695_ruby_40483.zip", "k_gokuraku")
## [1] "./NORUBY/k_gokuraku2.txt"

(folder <- getwd())  # フォルダを確認
## [1] "/home/c101103024/c101103024"

まとめて解析する

library(RMeCab)
tmp <- paste(folder, "NORUBY", sep = "/")  # 保存先フォルダは、現在のフォルダ下のNORUBY
setwd(tmp)  # 保存先フォルダに移動

# 文字のNgramを取り出す
x <- docNgram(tmp, type = 0)
## file = /home/c101103024/c101103024/NORUBY/k_dairiki2.txt Ngram = 2 
## length = 2877 
## 
## file = /home/c101103024/c101103024/NORUBY/k_gokuraku2.txt Ngram = 2 
## length = 2725 
## 
## file = /home/c101103024/c101103024/NORUBY/k_irehuda2.txt Ngram = 2 
## length = 3154 
## 
## file = /home/c101103024/c101103024/NORUBY/k_syusse2.txt Ngram = 2 
## length = 3327 
## 
## file = /home/c101103024/c101103024/NORUBY/t_ike2.txt Ngram = 2 
## length = 1893 
## 
## file = /home/c101103024/c101103024/NORUBY/t_itariazin2.txt Ngram = 2 
## length = 2301 
## 
## file = /home/c101103024/c101103024/NORUBY/t_kaisuiyoku2.txt Ngram = 2 
## length = 2581 
## 
## file = /home/c101103024/c101103024/NORUBY/t_ukiyoe2.txt Ngram = 2 
## length = 1908

読み込んだ中から、助詞と読点の組み合わせを幾つか抽出する

x <- x[rownames(x) %in% c("[と-、]", "[て-、]", "[は-、]", "[が-、]", 
    "[で-、]", "[に-、]", "[ら-、]", "[も-、]"), ]

####主成分分析を行なってみます。

x <- princomp(t(x))

結果をプロットします。

biplot(x)

plot of chunk unnamed-chunk-16

結論

この図では、左上に菊池寛の作品が集まっており、菊池は「も、」や「に、」、「が、」を頻繁に使い、一方、左下にかけては寺田寅彦の作品が集まっており、寺田の場合、「で、」や「て、」を好んで使うことが見て取れます。

unlink(tmp, recursive = T)