myLing7 <- function() { files <- list.files() for (i in files) { lines.tmp <- scan(i, what="char", sep="\n") #ファイルを選択。 data.tmp <- grep("\\*(JPN|NS)...:\t", lines.tmp, value=T) #*で始まる行のみ。 body.tmp <- gsub("\\*(JPN|NS)...:\t", "", data.tmp) #行頭の記号とタグを削除。 body.tmp <- body.tmp[body.tmp != ""] # 空の要素を削除する「イディオム」 body.lower <- tolower(body.tmp) body.token <- unlist(strsplit(body.lower, "\\W")) body.token <- body.token[body.token != ""] # 空の要素を削除する「イディオム」 type <- length(unique(body.token)) token <- length(body.token) TTR <- type/token GI <- type/sqrt(token) # ファイル名の取得は、i に入っている # トピックの取得 topic.line <- grep("^@Topic:\t", lines.tmp, value=T) topic <- gsub("^@Topic:\t", "", topic.line) # スコアの取得 criterion.line <- grep("^@Criterion:\t", lines.tmp, value=T) score <- gsub("^@Criterion:\t", "", criterion.line) # Average Word Length awl <- nchar(paste(body.token, collapse=""))/length(body.token) # Average Sentence Length asl <- length(body.token)/length(body.tmp) cat(i, score, topic, type, token, TTR, GI, awl, asl, "\n", file="../LingFeatures.txt", append=T) } }