Skip to content

Instantly share code, notes, and snippets.

@tattyamm
Created July 27, 2013 13:47
Show Gist options
  • Save tattyamm/6094929 to your computer and use it in GitHub Desktop.
Save tattyamm/6094929 to your computer and use it in GitHub Desktop.
ニコニコ動画コメント等データから、動画コメントを取す例2 http://www.nii.ac.jp/cscenter/idr/nico/nico-apply.html
# 動画コメントを取り出す例 2
# 動画コメントのjsonデータは行単位になっているが、どうも扱いづらいので、jsonの配列に変換しておく。
#
# 元
# {"date":1,"no":2,"vpos":3,"comment":"hello!","command":"184"}
# {"date":2,"no":3,"vpos":4,"comment":"hello!!","command":"184"}
# …
#
# これを変換して
# [{"date":1,"no":2,"vpos":3,"comment":"hello!","command":"184"},
# {"date":2,"no":3,"vpos":4,"comment":"hello!!","command":"184"},
# …]
#
# としておく。
#
# もっとまともな方法が欲しい。
#install.packages("rjson")
library("rjson")
json_file <- "/ファイル/thread/sm15108950_json.dat"
json_data <- fromJSON(paste(readLines(json_file), collapse=""))
comment <- c()
comment_length <- c()
vpos <- c()
# for ( i in 1:length(json_data) ) {
for ( i in 1:10000 ) {
comment <- c( comment, json_data[[i]]$comment[1] )
comment_length <- c( comment_length, nchar(json_data[[i]]$comment[1] ) )
vpos <- c( vpos, json_data[[i]]$vpos[1] )
}
# vposは1/100secなので、分にする
plot(
head(vpos, n=10000)/100/60, head(comment_length, n=10000) ,
main = "Alice in Musicland (sm15108950, 10000 comments)",
xlab = "vpos (min)",
ylab = "length(comment)",
xlim=c(0,12.5), ylim=c(0,80)
)
#lowessを重ねる
#f=2/3
par(new=T)
lines(
lowess( head(vpos, n=10000)/100/60, head(comment_length, n=10000), f=2/3),
main = "Alice in Musicland (sm15108950, 10000 comments)",
xlab = "vpos (min)",
ylab = "length(comment)",
xlim=c(0,12.5), ylim=c(0,80),
col = "red"
)
#f=0.2
par(new=T)
lines(
lowess( head(vpos, n=10000)/100/60, head(comment_length, n=10000), f=0.2),
main = "Alice in Musicland (sm15108950, 10000 comments)",
xlab = "vpos (min)",
ylab = "length(comment)",
xlim=c(0,12.5), ylim=c(0,80),
col = "green"
)
#label
legend(0, 80, c(paste("f = ", c("2/3", "0.2"))), lty = 1, col = 2:3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment