converting stemmed word to the root word in R

邮差的信 提交于 2019-12-08 05:13:56

问题


Hi I have a list of words which have been stemmed using the "tm" package in R. Can I get back the root word some how after this step. Thanks in Advance.

Ex : activiti --> activity


回答1:


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.




回答2:


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"


来源:https://stackoverflow.com/questions/25160521/converting-stemmed-word-to-the-root-word-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!