2

I am working on a script to extract relevant tags from the text file which i converted from a URL. One part of the script is giving me error when i apply stemmer, the code is as below

def __call__(self, tag):
    '''
    @param tag: the tag to be stemmed

    @returns: the stemmed tag
    '''

    string = self.preprocess(tag.string)
    tag.stem = self.stemmer.stem(string)
    return tag 

the error is as below

Type Error - stem() missing 1 required positional argument : 'word'

the line causing the error is

tag.stem = self.stemmer.stem(string)

I am using Python, if anyone can help me to modify the code to get rid of the error please.

2 Answers2

2

I think you didn't instantiate self.stemmer,ie

class stemmer(object):
    def stem(self, word):
        print('stem')

obj = stemmer 
obj.stem("word")

this will cause same error,beacause Class won't pass self argument to method,so you need instantiate the stemmer

obj = stemmer()
obj.stem("word")
Jeff Learman
  • 2,506
  • 1
  • 18
  • 28
Kr.98
  • 106
  • 8
  • Right. `stemmer.stem()` invokes `stem` as a *class method* so there's no object to implicitly pass as the first (`self`) parameter. `stemmer().stem()` invokes it as an *object method* and implicitly passes the object (created by `stemmer()`) as the first argument (`self`). – Jeff Learman Dec 03 '19 at 14:41
0

While initializing ps=PorterStemmer(), kindly check the braces are correct.

Ann Kilzer
  • 1,146
  • 1
  • 13
  • 36
  • I think you mean "parentheses" (`()`) not "braces" (`[]` or `{}`). – Jeff Learman Dec 03 '19 at 14:01
  • 1
    Though we thank you for your answer, it would be better if it provided additional value on top of the other answers. In this case, your answer does not provide additional value, since another user already posted that solution. If a previous answer was helpful to you, you should vote it up instead of repeating the same information. – Toby Speight Dec 03 '19 at 14:04