You can download this code by clicking the button below.
This code is now available for download.
This function takes a list of words, randomly selects one word, and uses the stem and lemmatize functions from the Lingua library to perform stemming and lemmatization.
Technology Stack : Lingua
Code Type : Function
Code Difficulty : Intermediate
import random
from lingua import stem, lemmatize
def random_word_processing(word_list):
# Select a random word from the provided list
word = random.choice(word_list)
# Stem the word using the stem function from lingua
stemmed_word = stem(word)
# Lemmatize the word using the lemmatize function from lingua
lemmatized_word = lemmatize(word)
return stemmed_word, lemmatized_word
# Example usage
words = ["running", "jumping", "eating", "sitting", "writing"]
stemmed, lemmatized = random_word_processing(words)
print(f"Stemmed: {stemmed}, Lemmatized: {lemmatized}")