converting stemmed word to the root word in R

坚强是说给别人听的谎言 提交于 2019-12-06 20:41:30

You can use the stemCompletion() function to achieve this, but you may need to trim the stems first. Consider the following:

library(tm)

library(qdap) # providers the stemmer() function

active.text = "there are plenty of funny activities"

active.corp = Corpus(VectorSource(active.text))

(st.text = tolower(stemmer(active.text,warn=F))) 
# this is what the columns of your Term Document Matrix are going to look like
[1] "there"  "are"    "plenti" "of"     "funni"  "activ" 

st.text = gsub("[aeyuio]+$","",st.text) # removing vowels on the end of each word
stemCompletion(st.text,active.corp,"prevalent") # now it works
        ther           ar        plent           of         funn        activ 
     "there"        "are"     "plenty"         "of"      "funny" "activities" 

Do keep in mind though that stemming confabulates certain words. For example "university" and "universal" both become "univers" after stemming and there is nothing you can do to restore it correctly.

Hope this helps.

Have a look at stemCompletion from the package tm:

library(tm)
v <- "There are plenty of activities."
stemCompletion("activiti", scan_tokenizer(tolower(v)))
#     activiti 
# "activities"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!