我试图使用包tm
过滤来自以下文档的停用词。包tm停止词参数
library(tm)
documents <- c("the quick brown fox jumps over the lazy dog", "i am the walrus")
corpus <- Corpus(VectorSource(documents))
matrix <- DocumentTermMatrix(corpus,control=list(stopwords=TRUE))
然而,当我运行此代码,我仍然可以在DocumentTermMatrix
以下。
colnames(matrix)
[1] "brown" "dog" "fox" "jumps" "lazy" "over" "quick" "the" "walrus"
“的”被列为停止词列表中的那个包tm
用途。我在stopwords
参数上做错了什么,或者这是tm
软件包中的错误?
编辑:我接触英戈Feinerer,他指出,这在技术上是不是一个错误:
用户提供的选项被首先处理,然后将所有剩余的 选项。因此,在标记化之前完成停用词的删除(因为Vincent Zoonekynd在stackoverflow.com上已经编写了 ),因此 就是您的结果。
因此,解决的办法是明确列出前stopwords
参数的默认符号化的选项,例如:
library(tm)
documents <- c("the quick brown fox jumps over the lazy dog", "i am the walrus")
corpus <- Corpus(VectorSource(documents))
matrix <- DocumentTermMatrix(corpus,control=list(tokenize=scan_tokenizer,stopwords=TRUE))
colnames(matrix)
感谢您的问题和答案......虽然他们都没有在我的问题上工作。似乎TM中的停用词在这个时候只是一个头痛的问题。 –