的findThoughts函数返回错误“提供文本和建模文件数数不匹配”时长(文本)!= out.stm的行数。
这是来自用于处理文档的textProcessor函数的错误在调用'stm'函数之前。
这就是为什么会发生这种情况: 临时输出有一个属性temp $ docs.removed,它列出了已删除的行。所以“临时文件$”的长度会比温度$ docs.removed的长度“意见”较小。
所以STM对象“a”和它使用的临时文件$将具有相同长度的临时文件$建模的$ THETA(与文件专题概率矩阵)。
temp<-textProcessor(comments, metadata=NULL, lowercase=TRUE, removestopwords=TRUE, removenumbers=TRUE, removepunctuation=TRUE, stem=TRUE, wordLengths=c(3,Inf), sparselevel=1, language="en", verbose=TRUE, onlycharacter= FALSE, striphtml=FALSE, customstopwords=NULL, onlytxtfiles=TRUE)
meta<-temp$meta
vocab<-temp$vocab
docs<-temp$documents
a<-stm(documents=docs, vocab=vocab, K=7,data=meta, max.em.its=800)
解决方案:删除在“临时”的对象被拆除从“文本”的对象,这些文件。下面的代码通过创建一个新的向量z来删除temp $ docs.removed中引用的索引。
z<-comments[-temp$docs.removed,]
length(z)
thoughts3 <- findThoughts(a,texts=z,topics=3, n=10,thresh=0.0)