python英文缩写单词扩写

词典

python 复制代码
# 缩略词-扩展字典
contractions = {
    "can't": "cannot",
    "won't": "will not",
    "I'm": "I am",
    "your's":"your"
    # 添加更多的缩略词及其扩展形式
}

# 扩展缩略词的函数
def expand_contractions(text):
    words = text.split()
    expanded_words = []
    for word in words:
        if word in contractions:
            expanded_words.append(contractions[word])
        else:
            expanded_words.append(word)
    expanded_text = " ".join(expanded_words)
    return expanded_text

# 测试扩展缩略词函数
text = "I can't believe it! Won't you join us? your's honer?"
expanded_text = expand_contractions(text)
print(expanded_text)
python 复制代码
I cannot believe it! Won't you join us? your honer?

掉包

python 复制代码
pip install contractions -i  https://pypi.tuna.tsinghua.edu.cn/simple
python 复制代码
import contractions

def expand_contractions(text):
    expanded_text = contractions.fix(text)
    return expanded_text

# Example usage
input_text = "I can't believe it's already Friday! you'll be learning alongside other students who are studying for a number of different degrees, typically in small classes, supporting one another to develop and succeed."
text = expand_contractions(text)
expanded_text = expand_contractions(input_text)
print(expanded_text)
python 复制代码
I cannot believe it is already Friday! you will be learning alongside other students who are studying for a number of different degrees, typically in small classes, supporting one another to develop and succeed.

组合使用:contractions只能扩写一般缩写词组,像 your's 这种就不能扩写,可以加在词典里。

相关推荐
流云一号11 分钟前
Python实现贪吃蛇二
开发语言·python
听风吹等浪起34 分钟前
NLP实战(3):RNN英文名国家分类
人工智能·python·rnn·深度学习
啊阿狸不会拉杆1 小时前
数据结构-限定性线性表 - 栈与队列
java·c语言·数据结构·c++·python·算法
杂学者1 小时前
python办公自动化------word文件的操作
python·word
资深设备全生命周期管理1 小时前
火影 遇上 python Baby_Brother_GGY
开发语言·python·pygame
开开心心就好2 小时前
功能丰富的PDF处理免费软件推荐
java·windows·python·pdf·电脑·生活·软件需求
不想学密码的程序员不是好的攻城狮2 小时前
TGCTF web
python·网络安全·web·ctf
mahuifa2 小时前
pyqt环境配置
python·qt·pycharm·pyqt·环境配置
小白学大数据2 小时前
Python自动化爬虫:Scrapy+APScheduler定时任务
开发语言·爬虫·python·自动化
水深00安东尼2 小时前
GAT-GRAPH ATTENTION NETWORKS(论文笔记)
论文阅读·python