从Python的词干中切出前缀

问题描述

| 我想从词干中切出词缀。我用以下命令尝试了后缀,对于“'菜''来说还可以。但是,当我想使用前缀(例如\'undo \')时,如何在Python中定义前缀以获取撤消结果?
>>> 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\')]
    

解决方法

好吧,为什么不像以前那样使用正则表达式呢?
>>> re.findall(r\'^(un|ir)(.*)$\',\'undo\')
[(\'un\',\'do\')]
    

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...