我想使用 python 将所有同义词和复数形式的单词转换为单词的基本版本。
例如,婴儿会变成婴儿,婴儿和婴儿也会变成婴儿。
我尝试为根代码创建一个朴素的复数版本,但它的问题是它并不总是正常运行并且无法检测到大量案例。
contents = ["buying", "stalls", "responsibilities"]
for token in contents:
if token.endswith("ies"):
token = token.replace('ies','y')
elif token.endswith('s'):
token = token[:-1]
elif token.endswith("ed"):
token = token[:-2]
elif token.endswith("ing"):
token = token[:-3]
print(contents)