나는 지난 며칠 동안 내 머리를 아프게했습니다. 나는 모든 SO 아카이브를 검색하고 제안 된 솔루션을 시도했지만이 작업을 수행 할 수없는 것 같습니다. 나는 2000 년 6 월, 1995 -99 년 등과 같은 폴더에 txt 문서 세트를 가지고 있으며 문서 용어 행렬 및 용어 문서 행렬을 만들고 단어의 일부 위치 기반 공동 위치를 만드는 것과 같은 기본적인 텍스트 마이닝 작업을 실행하려고합니다. 내 스크립트는 더 작은 코퍼스에서 작동하지만 더 큰 코퍼스로 시도 할 때 실패합니다. 이러한 폴더 작업을위한 코드를 붙여 넣었습니다.빅 텍스트 코퍼스가 tm_map을 깨기
library(tm) # Framework for text mining.
library(SnowballC) # Provides wordStem() for stemming.
library(RColorBrewer) # Generate palette of colours for plots.
library(ggplot2) # Plot word frequencies.
library(magrittr)
library(Rgraphviz)
library(directlabels)
setwd("/ConvertedText")
txt <- file.path("2000 -06")
docs<-VCorpus(DirSource(txt, encoding = "UTF-8"),readerControl = list(language = "UTF-8"))
docs <- tm_map(docs, content_transformer(tolower), mc.cores=1)
docs <- tm_map(docs, removeNumbers, mc.cores=1)
docs <- tm_map(docs, removePunctuation, mc.cores=1)
docs <- tm_map(docs, stripWhitespace, mc.cores=1)
docs <- tm_map(docs, removeWords, stopwords("SMART"), mc.cores=1)
docs <- tm_map(docs, removeWords, stopwords("en"), mc.cores=1)
#corpus creation complete
setwd("/ConvertedText/output")
dtm<-DocumentTermMatrix(docs)
tdm<-TermDocumentMatrix(docs)
m<-as.matrix(dtm)
write.csv(m, file="dtm.csv")
dtms<-removeSparseTerms(dtm, 0.2)
m1<-as.matrix(dtms)
write.csv(m1, file="dtms.csv")
# matrix creation/storage complete
freq <- sort(colSums(as.matrix(dtm)), decreasing=TRUE)
wf <- data.frame(word=names(freq), freq=freq)
freq[1:50]
#adjust freq score in next line
p <- ggplot(subset(wf, freq>100), aes(word, freq))+ geom_bar(stat="identity")+ theme(axis.text.x=element_text(angle=45, hjust=1))
ggsave("frequency2000-06.png", height=12,width=17, dpi=72)
# frequency graph generated
x<-as.matrix(findFreqTerms(dtm, lowfreq=1000))
write.csv(x, file="freqterms00-06.csv")
png("correlation2000-06.png", width=12, height=12, units="in", res=900)
graph.par(list(edges=list(col="lightblue", lty="solid", lwd=0.3)))
graph.par(list(nodes=list(col="darkgreen", lty="dotted", lwd=2, fontsize=50)))
plot(dtm, terms=findFreqTerms(dtm, lowfreq=1000)[1:50],corThreshold=0.7)
dev.off()
tm_map에서 mc.cores = 1 인수를 사용하면 작업이 무기한 계속됩니다. 그러나 tm_map에 lazy = TRUE 인수를 사용하면 겉으로보기에는 잘되지만 이후 작업에서이 오류가 발생합니다.
Error in UseMethod("meta", x) :
no applicable method for 'meta' applied to an object of class "try-error"
In addition: Warning messages:
1: In mclapply(x$content[i], function(d) tm_reduce(d, x$lazy$maps)) :
all scheduled cores encountered errors in user code
2: In mclapply(unname(content(x)), termFreq, control) :
all scheduled cores encountered errors in user code
나는 모든 해결책을 찾고 있지만 일관되게 실패했습니다. 어떤 도움이라도 대단히 감사하겠습니다!
최고! k
감사합니다. – xbsd
고마워요! 내 SO 계정에 대한 암호를 잃어 버렸으므로 이제 이것을 보았습니다 :) – Kartik