#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to lemmatize words in R?
Description

To lemmatize words in R

Functions Used

lemmatize_strings(x, dictionary = lexicon::hash_lemmas) – To lemmatize a vector of strings
lemmatize_words(x, dictionary = lexicon::hash_lemmas) – To lemmatize a vector of words

Libraries Required :

library(“textstem”)

Process

  Load required libraries

  Load the data

  Transform the data to a vector of strings to perform lemmatization of string

  Transform the data to a vector of words to perform lemmatization of words

Sapmle Code

#Load necessary libaries
library(“readtext”)
library(“textstem”)
data data1=(strsplit(data$text,”\n”))
data2=unlist(data1[[1]])
data3=strsplit(data2,”\t”)
data4=unlist(data3)
i=0
j=0
k=0
text=c()
pol=c()
for (i in (1:length(data4)))
{
if(i%%2!=0)
{
j=j+1
text[j]=data4[i]
}else
{
k=k+1
pol[k]=data4[i]
}
}
df=data.frame(text=text,polarity=pol,stringsAsFactors = FALSE)
df$text[1:10]
#To lemmatize a vector of strings
lemmatize_strings(df$text[1:10], dictionary = lexicon::hash_lemmas)
#To convert the string to vector of words
vect_words=scan(text = df$text[1:10], what = “”)
vect_words
#To lemmatize a vector of words
lemmatize_words(vect_words, dictionary = lexicon::hash_lemmas)

Screenshots