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 这种就不能扩写,可以加在词典里。

相关推荐
tryCbest3 分钟前
Django 基础入门教程(第三篇):Admin后台与ORM进阶(单表、多表、聚合查询)
python·django
好家伙VCC5 分钟前
# Deno框架实战:从零搭建一个安全、高效的Node.js替代项目 在现代
java·python·安全·node.js
Zwj-c10 分钟前
【测试报告】学评一体化平台测试报告(功能测试、自动化测试、Bug描述)
python·功能测试·selenium·测试用例·bug
chushiyunen15 分钟前
django数据库配置
数据库·python·django
全栈凯哥17 分钟前
01.Python 和 PyCharm 安装与运行完全指南
python·pycharm
java1234_小锋18 分钟前
Python常见面试题:请解释或描述一下Django的架构?
python·架构·django
青瓷程序设计19 分钟前
【蝴蝶识别系统】~Python+深度学习+人工智能+算法模型+图像识别+2026原创
人工智能·python·深度学习
所谓伊人,在水一方33321 分钟前
【Python零基础到精通】第13讲 | TensorFlow深度学习:从神经网络原理到实战
python·深度学习·神经网络·信息可视化·tensorflow
Fuxiao___26 分钟前
RoboTwin2.0中训练OpenVLA-oft 全流程(bell + alarmclock)
人工智能·python·深度学习
justtoomuchforyou30 分钟前
deepseek- 上千种类别如何image classification
python