python - 以 'e'结尾的英语动词处理

标签 python nlp stemming text-processing

考虑到这些转换,我正在实现一些字符串替换器

'thou sittest' → 'you sit'
'thou walkest' → 'you walk'
'thou liest' → 'you lie'
'thou risest' → 'you rise'

如果我保持天真,在这种情况下可以使用正则表达式来查找和替换,例如 thou [a-z]+est

但问题来自以 e 结尾的英语动词,因为根据上下文我需要修剪 est in some & trim just st在休息

实现此目标的快速解决方案是什么?

最佳答案

可能是最快最脏的:

import nltk
words = set(nltk.corpus.words.words())
for old in 'sittest walkest liest risest'.split():
    new = old[:-2]
    while new and new not in words:
        new = new[:-1]
    print(old, new)

输出:

sittest sit
walkest walk
liest lie
risest rise

更新。稍微不那么快速和肮脏(例如适用于 rotest → 动词 rot,而不是名词 rote):

from nltk.corpus import wordnet as wn
for old in 'sittest walkest liest risest rotest'.split():
    new = old[:-2]
    while new and not wn.synsets(new, pos='v'):
        new = new[:-1]
    print(old, new)

输出:

sittest sit
walkest walk
liest lie
risest rise
rotest rot

关于python - 以 'e'结尾的英语动词处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42089517/

相关文章:

python - 使用正则表达式仅将文本从列中的字符串提取到 python 数据框中的另一列时出错

python - 这个计算是用 Python 执行的吗?

python - 图像侵 eclipse 手动实现没有做任何事情 Python

python - 使用 spaCy 更好的命名实体识别和相似性

python - 如何在将训练语料库传递到 sklearn 中的 TfidfVectorizer 之前应用自定义词干分析器?

python - 如何使用Python可靠地提取URL中包含的URL?

algorithm - 谷歌如何识别没有空格的2个词?

twitter - 如何处理推文中的俚语和简短形式,如 luv 、 kool 和 brb ?

python - 阿拉伯语词干分析器不适用于句子

python - 除了词干还有什么其他选择?