如何使用 python 将推文中的短词替换为完整词

How to replace short words into full words from tweets using python

我正在对推文进行情绪分析。大多数推文都包含短词,我想将它们替换为 original/full 词。

假设推文是:

I was wid Ali.

我要转换:

wid -> with

同样

wud -> would
u -> you
r -> are

我有 6000 条推文,其中有很多短词。 我怎样才能更换它们? python 中是否有可用于此任务的库?或在线提供的任何短词词典?

我阅读了 问题的答案,但它只提供撇号字典。

目前我正在使用 NLTK,但使用 NLTK 无法完成此任务。

好像下面这个网站有必要的词典: https://www.noslang.com/search 您可以通过 python 代码发送请求并取回翻译。

这是工作代码:

import requests
prefixStr = '<div class="translation-text">'
postfixStr = '</div'

slangText = 'I was wid Ali.'

r = requests.post('https://www.noslang.com/', {'action': 'translate', 'p': 
slangText, 'noswear': 'noswear', 'submit': 'Translate'})
startIndex = r.text.find(prefixStr)+len(prefixStr)
endIndex = startIndex + r.text[startIndex:].find(postfixStr)
print(r.text[startIndex:endIndex])