*disclaimer
1197148
myTextIndex.R
myTextIndex.R(323)
myTextIndex <- function(){
#ディレクトリー内のすべてのテキストファイルの基礎的言語特徴量を算出
output.file <- choose.files() #結果の保存ファイルの作成
files <- list.files()
for (i in files){
Token <- 0
Type <- 0
NoS <- 0
TTR <- 0
GI <- 0
AWL <- 0
ASL <- 0
wttr <- 0
ttrsum <- 0
MATTR <- 0
lines.tmp <- scan(i, what="char", sep="\n")
lines.lower <- tolower(lines.tmp)
words.tmp <- unlist(strsplit(lines.lower, "\\W+"))
Token <- length(words.tmp)
Type <- length(unique(words.tmp))
NoS <- length(lines.tmp)
TTR <- Type/Token
GI <- Type/sqrt(Token)
AWL <- nchar(paste(words.tmp, collapse=""))/Token
ASL <- Token/NoS
words.tmp2 <- c(words.tmp, words.tmp)
for (j in 1:Token){
mado <- words.tmp2[j:(99+j)]
wttr <- length(unique(sort(mado)))/100
ttrsum <- ttrsum + wttr
}
MATTR <- ttrsum/Token
cat(i, Token, Type, NoS, TTR, GI, MATTR, AWL, ASL, "\n", file=output.file, append=T)
}
}
スコアも出力する
myTextIndex2.R(344)
criterion.tmp <- grep("@Criterion", lines.tmp, value = T)
Score <- gsub("@Criterion:\t", "", criterion.tmp)
トピックも
myTextIndexTopic.R(368)
topic.tmp <- grep("@Topic:\t", lines.tmp, value = T)
topic <- gsub("@Topic:\t", "", topic.tmp)
https://sugiura-ken.org/wiki/