Tôi đã phá vỡ đầu của tôi về điều này trong vài ngày qua. Tôi đã tìm kiếm tất cả các lưu trữ SO và thử các giải pháp được đề xuất nhưng dường như không thể làm được điều này. Tôi có tập hợp các tài liệu txt trong các thư mục như 2000 06, 1995 -99 vv và muốn chạy một số thao tác khai phá văn bản cơ bản như tạo ma trận thuật ngữ tài liệu và ma trận tài liệu thuật ngữ và thực hiện một số hoạt động dựa trên vị trí của các từ. Kịch bản của tôi hoạt động trên một kho văn bản nhỏ hơn, tuy nhiên, khi tôi thử nó với kho văn bản lớn hơn, nó không làm tôi thất vọng. Tôi đã dán trong mã cho một hoạt động thư mục như vậy.Văn bản lớn Corpus vi phạm 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()
Khi tôi sử dụng đối số mc.cores = 1 trong tm_map, thao tác sẽ tiếp tục vô thời hạn. Tuy nhiên, nếu tôi sử dụng đối số lazy = TRUE trong tm_map, nó có vẻ khá ổn, nhưng các phép toán tiếp theo cho lỗi này.
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
Tôi đã tìm kiếm tất cả các giải pháp nhưng đã thất bại một cách nhất quán. Mọi sự trợ giúp sẽ rất được trân trọng!
Tốt nhất! k
Cảm ơn, đã giúp rất nhiều! – xbsd
Cảm ơn rất nhiều! Tôi bị mất mật khẩu vào tài khoản SO của tôi, vì vậy chỉ cần nhìn thấy điều này ngay bây giờ :) – Kartik