【发布时间】:2013-04-10 18:26:18
【问题描述】:
我正在使用tm-package 在 R 中进行一些文本挖掘。一切都很顺利。但是,在词干提取后会出现一个问题 (http://en.wikipedia.org/wiki/Stemming)。显然,有些词具有相同的词干,但重要的是不要将它们“放在一起”(因为这些词的含义不同)。
例如,请参阅下面的 4 个文本。在这里,您不能互换使用“讲师”或“演讲”(“协会”和“关联”)。但是,这是在第 4 步中完成的。
是否有任何优雅的解决方案如何手动为某些案例/单词实现这一点(例如,“讲师”和“演讲”被保留为两个不同的东西)?
texts <- c("i am member of the XYZ association",
"apply for our open associate position",
"xyz memorial lecture takes place on wednesday",
"vote for the most popular lecturer")
# Step 1: Create corpus
corpus <- Corpus(DataframeSource(data.frame(texts)))
# Step 2: Keep a copy of corpus to use later as a dictionary for stem completion
corpus.copy <- corpus
# Step 3: Stem words in the corpus
corpus.temp <- tm_map(corpus, stemDocument, language = "english")
inspect(corpus.temp)
# Step 4: Complete the stems to their original form
corpus.final <- tm_map(corpus.temp, stemCompletion, dictionary = corpus.copy)
inspect(corpus.final)
【问题讨论】:
-
这是词干的重点。你这样做是为了获得词根。如果您想保留差异,请不要停止。
-
我知道。但是在某些情况下是否有一种优雅的方式可以将其改回来?
标签: r text-mining tm