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

相关推荐
EntyIU1 小时前
mineru从安装部署到测试使用完整指南
python·ocr
安替-AnTi2 小时前
厚朴 APK 搜索接口分析
python·apk·解析·taobao
山川湖海2 小时前
AI时代快速学编程语言的陷阱(以Python为例)
大数据·人工智能·python
H Journey2 小时前
Supervisor 进程管理工具介绍
python·supervisor·linux 运维
春日见3 小时前
5分钟入门强化学习之动态规划算法与实现
大数据·人工智能·python·算法·机器学习·计算机视觉
DeniuHe3 小时前
sklearn 中所有交叉验证数据集划分方式完整总结
人工智能·python·sklearn
DeniuHe3 小时前
sklearn中不同交叉验证方法的场景适配
人工智能·python·sklearn
隐于花海,等待花开4 小时前
16.Python 常用第三方库概览 深度解析
python
我材不敲代码4 小时前
Python 函数核心:位置参数与关键字参数详解
java·前端·python
风落无尘4 小时前
第十一章《对齐与安全》 完整学习资料
python·安全·机器学习