-2

I stemmed a text and got radicals and now I want to have an output that has a meaning. I know that a radical has many words that can be created from, I just need one. Is it possible ?

1 Answers1

1

You may want to try lemmatization rather than stemming. This process attempts to generate a canonical "dictionary word" rather than a radical for each input. See What is the difference between lemmatization vs stemming?.

Otherwise, you could use a dict to keep track of the words that mapped to each stem. (This code stores a set of words, but you could modify it to just record a single word per stem.)

from collections import defaultdict

def get_stem_dict(words, stemmer):
    stem_to_words = defaultdict(set)
    for word in words:
        stem = stemmer.stem(word)
        stem_to_words[stem].add(word)
    return stem_to_words

Then you could use the dict to look up an example word for a given stem:

def get_example(stem_to_words, stem):
    return next(iter(stem_to_words[stem]))
augurar
  • 12,081
  • 6
  • 50
  • 65