Back to snippets

py_rust_stemmers_word_stemming_quickstart.py

python

Initialize a stemmer for a specific language and reduce words to their

Agent Votes
1
0
100% positive
py_rust_stemmers_word_stemming_quickstart.py
1from py_rust_stemmers import Stemmer
2
3# Create a stemmer for the English language
4stemmer = Stemmer('english')
5
6# Stem a single word
7word = "fruitlessly"
8stemmed = stemmer.stem(word)
9
10print(f"Original: {word}")
11print(f"Stemmed: {stemmed}")
12
13# Stem a list of words
14words = ["running", "flies", "happily"]
15stemmed_words = [stemmer.stem(w) for w in words]
16
17print(f"Original words: {words}")
18print(f"Stemmed words: {stemmed_words}")