我嘗試從一個語料庫構建Document-Term Meatrix。我使用的命令是:爲什麼R在使用NGramTokenizer時掛起?
library(parallel)
library(tm)
library(RWeka)
library(topicmodels)
library(RTextTools)
cl=makeCluster(detectCores())
invisible(clusterEvalQ(cl, library(tm)))
invisible(clusterEvalQ(cl, library(RWeka)))
invisible(clusterEvalQ(cl, library(topicmodels)))
invisible(clusterEvalQ(cl, library(RTextTools)))
myCorpus <-Corpus(DirSource("/home/neeph/Test/DMOZ_Business"), encoding="UTF-8", readerControl=list(reader=readPlain))
removeURL <- function(x) gsub("http[[:alnum:]]*", "", x)
myCorpus <- tm_map(myCorpus, removeURL)
removeAmp <- function(x) gsub("&", "", x)
myCorpus <- tm_map(myCorpus, removeAmp)
removeWWW <- function(x) gsub("www[[:alnum:]]*", "", x)
myCorpus <- tm_map(myCorpus, removeWWW)
myCorpus <- tm_map(myCorpus, tolower)
myCorpus <- tm_map(myCorpus, removeNumbers)
myCorpus <- tm_map(myCorpus, removePunctuation)
myCorpus <- tm_map(myCorpus, removeWords, stopwords("english"))
myCorpus <- tm_map(myCorpus, removeWords, stopwords("SMART"))
myCorpus <- tm_map(myCorpus, stripWhitespace)
summary(myCorpus)
與696個的文本文件
元數據包含2標籤 - 值對和數據幀 可用代碼語料庫: CREATE_DATE創造者在數據 可用變量框架是: MetaID
myDtm <- DocumentTermMatrix(myCorpus, control = list(wordLengths = c(1,Inf)))
一切正常高達這個階段,如果我不包括標記化。但是,當我運行以下更改代碼:
dictCorpus <- myCorpus
myDtm <- DocumentTermMatrix(myCorpus, control = list(wordlengths=c(1,Inf),tokenize=NGramTokenizer, dictionary=dictCorpus))
它掛起。我一直保持它過夜,但沒有結果。任何幫助將非常感激。
更新:
summary(myDtm)
Error in order(list(i = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, :
unimplemented type 'list' in 'orderVector1'
這個錯誤是什麼意思?