Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-010

Naive Suffix Stemmer

Problem

Apply a naive suffix-stripping stem to each token, checked in this order: if the word is longer than 5 characters and ends in 'ing', drop 'ing'; otherwise, if it is longer than 4 characters and ends in 'ed', drop 'ed'; otherwise, if it is longer than 3 characters, ends in 's', and does not end in 'ss', drop the 's'.

Return the list of stems; at most one suffix is removed per token.

Hint

Use elif so only the first matching rule applies.

Test cases

case 1
in: [["running","jumped","cats","class","is","boss","hoped","flying"]]
expected: ["runn","jump","cat","class","is","boss","hop","fly"]
case 2
in: [["seeing","agreed","beds"]]
expected: ["see","agre","bed"]
case 3
in: [[]]
expected: []
case 4
in: [["s"]]
expected: ["s"]
Starter codePython
def naive_stem(tokens):
    # Your code here
    pass

4 test cases · run your code against them in the editor