我目前正在做一个文本挖掘过程,我想在其中转换相似的单词(表,表等)。变成一个单词(表)‘。我看到tm包提供了一个这样的工具,但是这个包不支持我正在寻找的语言。因此,我想自己创造一些东西。
对于该函数,我希望有一个链接表->
a <- c("Table", "Tables", "Tree", "Trees")
b <- c("Table", "Tree", "Chair", "Invoice")
df <- data.frame(b, a)这样我就可以自动将所有的"Tables“值转换成"Table”
有没有想过我该怎么做?
发布于 2015-08-07 16:03:08
在R中搜索词干,你可以查找here,你可以尝试:
a <- c("Table", "Tables", "Tree", "Trees")
b <- c("Table", "Tree", "Chair", "Invoice")
library("SnowballC")
wordStem(words = a, language = "porter")
##[1] "Tabl" "Tabl" "Tree" "Tree"
library("tm") # tm use wordStem
stemCompletion(x = stemDocument(x = a), dictionary = b)
## Tabl Tabl Tree Tree
##"Table" "Table" "Tree" "Tree" 或者使用起来更复杂但更完整,您可以查看korPus包并使用TreeTagger处理您的文本:
library("koRpus")
tagged.results <- treetag(tolower(a), treetagger="manual", format="obj",
TT.tknz=FALSE , lang="en",
TT.options=list(path="./TreeTagger", preset="en"))
tagged.results@TT.res
## token tag lemma lttr wclass desc stop stem
##1 table NN table 5 noun Noun, singular or mass NA NA
##2 tables NNS table 6 noun Noun, plural NA NA
##3 tree NN tree 4 noun Noun, singular or mass NA NA
##4 trees NNS tree 5 noun Noun, plural NA NA你想要的是:
tagged.results@TT.res$lemma
##[1] "table" "table" "tree" "tree" https://stackoverflow.com/questions/31870959
复制相似问题