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

相关推荐
茉莉玫瑰花茶几秒前
LangGraph 拓展核心知识点
开发语言·windows·python
iAm_Ike1 分钟前
PHP错误和异常如何处理_PHP错误与异常处理机制详解【详解】
jvm·数据库·python
m0_631529826 分钟前
宝塔面板安装后无法修改配置文件_处理chattr锁定属性
jvm·数据库·python
坐吃山猪8 分钟前
【Hanako】README08_LEVEL4_插件系统架构
python·架构·agent·源码阅读
dFObBIMmai11 分钟前
Go语言怎么用GitHub Actions_Go语言GitHub Actions教程【基础】
jvm·数据库·python
Michelle802313 分钟前
25大数据 11-1 函数
开发语言·python
dFObBIMmai20 分钟前
SQL复杂数据聚合_嵌套子查询与GROUP BY配合
jvm·数据库·python
小许同学记录成长32 分钟前
基于幅度形态与参数聚类的工作模式判别
python·算法·scikit-learn
dinglu1030DL37 分钟前
CSS Grid布局如何实现网格项目排序_使用order属性改变显示顺序
jvm·数据库·python
财经资讯数据_灵砚智能42 分钟前
基于全球经济类多源新闻的NLP情感分析与数据可视化(日间)2026年5月13日
大数据·人工智能·python·信息可视化·自然语言处理