ブログエントリの関連度をMDSで処理して図示

解析対象はshoheiaoki.comの記事

library(RMySQL) 
library(RMeCab)
md <- dbDriver('MySQL')
dbconnector <- dbConnect(md,dbname='ghana_blog',user='root',password='*****')
shohei.table <- dbGetQuery(dbconnector,'set names utf8') #utf8に変換
shohei.table <- dbGetQuery(dbconnector,'select * from articles') #title,html2列のデータフレーム
all.shohei <- as.vector(shohei.table[,2])  #htmlテキストを要素とする列ベクトルに
names(all.shohei) <- shohei.table[,1] #ベクトルの要素名をタイトルに指定
shohei.tdm <- docMatrixDF(all.shohei) #docMatrixDF(RMeCab)でTDMを作成
colnames(shohei.tdm) <- names(all.shohei) #TDMのタイトル(文書名)を付加(自動でやってくれなかったので)
shohei.mult <- t(shohei.tdm) %*% shohei.tdm #文書隣接行列(doc-doc adjacent matrix)を計算
shohei.dist <- dist(shohei.mult) #距離行列を計算
shohei.mds <- cmdscale(shohei.dist) #多次元尺度構成法(MDS)を適用
plot(shohei.mds,type='n') 
text(shohei.mds,names(all.shohei))