user1946217
user1946217

Reputation: 1753

converting stemmed word to the root word in R

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

Upvotes: 1

Views: 3288

Answers (2)

IVR
IVR

Reputation: 1848

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.

Upvotes: 2

lukeA
lukeA

Reputation: 54237

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"

Upvotes: 1

Related Questions