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
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"
来源:https://stackoverflow.com/questions/25160521/converting-stemmed-word-to-the-root-word-in-r