今回扱う例:算術式を扱うサンプル Expr (Expression)
abstract classの中身を実装していく 変数、数値、単項演算(-, ++, !, ...)、二項演算(+, - , <, &&)
abstract class Expr
case class Var(name:String) extends Expr
case class Number(num:Double) extends Expr
# 動画コメントを取り出す例 | |
#install.packages("rjson") | |
library("rjson") | |
json_file <- "/ファイルの場所/sm57.dat" | |
thread<-file(json_file,"r") | |
for(i in 1:10000000){ |
# 動画コメントを取り出す例 2 | |
# 動画コメントのjsonデータは行単位になっているが、どうも扱いづらいので、jsonの配列に変換しておく。 | |
# | |
# 元 | |
# {"date":1,"no":2,"vpos":3,"comment":"hello!","command":"184"} | |
# {"date":2,"no":3,"vpos":4,"comment":"hello!!","command":"184"} | |
# … | |
# | |
# これを変換して |
def text2sentiment(source, dictionary) | |
score = 0; | |
# sourceのノーマリゼーション?が必要。全角半角とか。特に数字。 | |
# 単語が複数回登場することがあるがその場合の評価は? | |
dictionary.each{ |dic| | |
pattern = dic[:word].gsub(/ /, '.*') #スペースは単純に削除でも良いかもしれない |