【问题标题】:English verbs processing ending with 'e'处理以'e'结尾的英语动词
【发布时间】:2017-06-24 16:15:45
【问题描述】:

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

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

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

但问题在于以 e 结尾的英语动词,因为根据上下文我需要在某些部分修剪 est 并在其余部分修剪 st

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

【问题讨论】:

  • 使用 NLTK 研究词干。

标签: python nlp stemming text-processing


【解决方案1】:

可能是最快最脏的:

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

【讨论】:

  • 请注意,它还正确地从“sittest”中删除了双辅音!
  • 真的又快又脏……我喜欢。
  • 到目前为止太棒了,如果有像 word.is_verb() 这样的方法,我确实在寻找。这效果最好。接受。
  • @Kirill 这是我在github.com/nehemiahjacob/CKJV 的工作我正在构建一个基于 KJV 的现代化圣经翻译。你应该得到很多荣誉。
  • @itsneo 谢谢。谁知道呢,也许有一天我会使用你的项目,因为我正在做一个有点类似的逐字翻译。
猜你喜欢
  • 1970-01-01
  • 2021-02-25
  • 1970-01-01
  • 2022-01-03
  • 1970-01-01
  • 2021-12-22
  • 1970-01-01
  • 2021-05-29
  • 2016-06-10
相关资源
最近更新 更多