2017-05-09 35 views
0

我從公開的審閱數據創建相關的主題模型並獲取相當奇怪的錯誤。R中的主題建模

當我在我的CTM上調用術語(ctm1,5)時,我找回了文檔的名稱,而不是每個主題的前5個術語。

更詳細我跑,

library(topicmodels) 
library(data.table) 
library(tm) 

a <-Corpus(DirSource("~/text", encoding="UTF-8"), readerControl = 
list(language="lat")) 
a <- tm_map(a, removeNumbers) 
a <- tm_map(a, removePunctuation) 
a <- tm_map(a , stripWhitespace) 
a <- tm_map(a, tolower) 
a <- tm_map(a, removeWords, stopwords("english")) 
a <- tm_map(a, stemDocument, language = "english") 
adtm <-TermDocumentMatrix(a) 
adtm <- removeSparseTerms(adtm, 0.75) 

ctm1 <- CTM(adtm, 30, method = "VEM", control = NULL, model = NULL) 
terms(ctm1, 5) 

其返回

terms(ctm1) 
      Topic 1 "cmnt656661.txt" 

(等)

回答

0

我們不能確切知道,因爲你沒有提供的數據;但很可能您沒有正確導入文件。見?DirSource(我的重點):

目錄:中全路徑名一個特徵向量;默認 對應於工作目錄getwd()。

對你來說,好像你應該做這樣的事情:

a <- Corpus(DirSource(list.files("~/text", full.names = TRUE)))