用 r 蒸单词

steamming words with r

我很难理解 R 词干词处理。

在我的示例中,我创建了以下语料库对象

a <- Corpus(VectorSource("device so much more funand  unlike most android torrent download clients"))

所以a是

a[[1]]$content

[1] "device so much more funand  unlike most android torrent download clients"

这个字符串中的第一个单词是 "device",我创建了我的术语矩阵

b <- TermDocumentMatrix(a, control = list(stemming = TRUE)) 

并将其作为输出

dimnames(b)$Terms
[1] "android"  "client"   "devic"    "download" "funand"   "more"     "most"      "much"     "torrent" 
[10] "unlik"

我想知道的是为什么我在 "device" 和 "unlike" 丢失了 "e" 但没有在 "more".

丢失它

我怎样才能避免这种情况发生在这个词和其他一些词中?

谢谢。

我假设您使用的是 tmSnowballC 软件包。

这些软件包中的词干提取使用 Porter Stemming algorithm(英文)。

如果您想使用词干提取算法,可以运行:

getStemLanguages()

并尝试使用其他的 - 唯一的其他内置英语在这里:

wordStem(words, language = "english")

对于你的数据,returns相同:

 [1] "android"  "client"   "devic"    "download" "funand"   "more"     "most"     "much"     "torrent" 
[10] "unlik" 

另一种选择是使用 MorphAdorner lemmatizer at Northwestern University. This answer 具有 lemmatize(...) 函数的代码。

library(tm)
a     <- Corpus(VectorSource("device so much more funand  unlike most android torrent download clients"))
words <- Terms(TermDocumentMatrix(a))
lemmatize(words)
#    android    clients     device   download     funand       more       most       much    torrent     unlike 
#  "android"   "client"   "device" "download"   "funand"     "more"     "most"     "much"  "torrent"   "unlike" 

如您所见,它删除了 "clients" 中的 "s",但没有删除 "device" 中的 "e"。