Snowball Stemmer token

56 Views Asked by At

The following lines of code do not work of the module SnowballStemmer from nltk

def fun(text):
    stemmer.stem(text)
TypeError: SnowballStemmer.stem() missing 1 required positional argument: 'token'
2

There are 2 best solutions below

0
epursiai On

You should include full code that you are using. From your code it is not clear how (or if) you have instantiated the stemmer.

From the error message it would look like you haven't instantiated the stemmer.

You need to do following (replace the "english" with whatever language you are using):

stemmer = SnowballStemmer("english")
stemmer.stem(text)

You can not do e.g. this:

stemmer = SnowballStemmer
stemmer.stem(text)
0
Humayun Ahmad Rajib On

The error you're encountering with the SnowballStemmer from NLTK is because the stem() method requires an additional argument, which is the token (word) you want to stem.

This example is working fine for me. You check it out.

from nltk.stem import SnowballStemmer

stemmer = SnowballStemmer("english")

def fun(text):
    stemmed_word = stemmer.stem(text)
    return stemmed_word

stemmed_word = fun("programming")
print(stemmed_word)