In the following codes, my aim is to reduce the number of words with the same stem. For example, kompis in Swedish refer a friend in English, and the words with similar roots are kompisar, kompiserna.
rm(list=ls())
Sys.setlocale("LC_ALL","sv_SE.UTF-8")
library(tm)
library(SnowballC)
kompis <- c("kompisar", "kompis", "kompiserna")
stem_doc <- stemDocument(kompis, language="swedish")
stem_doc
1] "kompis" "kompis" "kompis"
I create a sample text file including the word kompis, kompisar, kompiserna. Then, I did some preproceses in the corpus via following codes:
text <- c("TV och vara med kompisar.",
"Jobba på kompis huset",
"Ta det lugnt, umgås med kompisar.",
"Umgås med kompisar, vänner ",
"kolla anime med kompiserna")
corpus.prep <- Corpus(VectorSource(text), readerControl =list(reader=readPlain, language="swe"))
corpus.prep <- tm_map(corpus.prep, PlainTextDocument)
corpus.prep <- tm_map(corpus.prep, stemDocument,language = "swedish")
head(content(corpus.prep[[1]]))
The results as follows. However, it includes the original words rather than same stem: kompis.
1] "TV och vara med kompisar."
2] "Jobba på kompi huset"
3] "Ta det lugnt, umgå med kompisar."
4] "Umgås med kompisar, vänner"
5] "kolla anim med kompiserna"
Do you know how to fix it?