【发布时间】:2016-03-20 07:28:41
【问题描述】:
我有一些从网上得到的文字,但人们用简短的形式写出来,比如 uni 代表大学,awsm 代表真棒等,但我可以猜出这些单词的列表。但是如何用 Python 纠正它们呢?我尝试了以下方法,但没有成功。
APPOSTOPHES= {"'s": "is", "'re":"are"}
s= " i luv my iphone, you're awsm apple. DisplayisAwesome, Sooooo happppppy"
words = s.split()
rfrm=[APPOSTOPHES[word] if word in APPOSTOPHES else word for word in words]
rfrm= " ".join(rfrm)
print(rfrm)
i luv my iphone, you're awsm apple. DisplayisAwesome, Sooooo happppppy
但它会打印相同的句子。它没有改变任何东西。
【问题讨论】:
-
APPOSTOPHES[word]不会匹配您列表中的任何项目。
标签: python-3.x nltk error-correction spelling