【问题标题】:Slicing the prefix from the stem in Python在 Python 中从词干中切片前缀
【发布时间】:2011-05-26 06:55:02
【问题描述】:

我想从词干上切下词缀。我用以下命令尝试了后缀,“菜”没问题。但是,当我想使用前缀(例如,'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')]

【问题讨论】:

    标签: python slice prefixes


    【解决方案1】:

    那么,为什么不像以前一样使用正则表达式呢?

    >>> re.findall(r'^(un|ir)(.*)$', 'undo')
    [('un', 'do')]
    

    【讨论】:

      猜你喜欢
      • 2021-11-03
      • 2015-03-10
      • 1970-01-01
      • 2017-11-18
      • 2020-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多