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

相关推荐
wljt14 小时前
Linux 常用命令速查手册(Java开发版)
java·linux·python
WPG大大通14 小时前
AIoT | 软件:Astra MCP边缘算力构建详解
经验分享·笔记·python·硬件架构·代码
波诺波15 小时前
环境管理器
linux·前端·python
诸葛思颖15 小时前
把本地 Python 项目用 Git 进行版本控制并推送到 GitHub
git·python·github
测试老哥15 小时前
自动化测试用例的编写和管理
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
周杰伦_Jay15 小时前
【Python Web开源框架】Django/Flask/FastAPI/Tornado/Pyramid
前端·python·开源
周杰伦_Jay15 小时前
【Python后端API开发对比】FastAPI、主流框架Flask、Django REST Framework(DRF)及高性能框架Tornado
数据结构·人工智能·python·django·flask·fastapi·tornado
chenchihwen15 小时前
AI代码开发宝库系列:PDF文档解析MinerU
人工智能·python·pdf·dashscope
程序员爱钓鱼16 小时前
Python编程实战:面向对象与进阶语法——上下文管理器(with语句)
后端·python·ipython
程序员爱钓鱼16 小时前
Python编程实战:面向对象与进阶语法——装饰器(Decorator)
后端·python·ipython