Python的词干来自于前缀

2024-06-16 11:56:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把词缀从词干上切下来。我用下面的命令尝试了后缀,对'dishes'没问题。但是,当我想用前缀(例如,'undo')来执行时,如何在Python中定义前缀以获得undo的结果?在

>>> def stem(word):
    for suffix in ['ing', 'lity', 'es']:
        if word.endswith(suffix):
            return word[:-len(suffix)]
        return word
>>> re.findall(r'^(.*)(ing|lity|es)$', 'dishes')
[('dish', 'es')]

Tags: 命令return定义esdefsuffix后缀word