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

相关推荐
查无此人byebye3 分钟前
从零解读CLIP核心源码:PyTorch实现版逐行解析
人工智能·pytorch·python·深度学习·机器学习·自然语言处理·音视频
chao_7894 分钟前
双设备全栈开发最佳实践[mac系统]
git·python·macos·docker·vue·全栈
筷乐老六喝旺仔9 分钟前
使用PyQt5创建现代化的桌面应用程序
jvm·数据库·python
LilySesy11 分钟前
【SAP-MOM项目】二、接口对接(中)
开发语言·python·pandas·restful·sap·abap
零度@14 分钟前
专为 Java 开发者 整理的《Python编程:从入门到实践》前8章核心内容
java·开发语言·windows·python
规划酱15 分钟前
Arcgis中pip安装ezdxf部分GIS有pyparsing安装失败的情况处理
python·arcgis·pip·规划酱
witAI16 分钟前
**AI漫剧一键生成2025指南,解锁零门槛动画创作新体验*
人工智能·python
ktoking16 分钟前
Stock Agent AI 模型的选股器实现 [七]
人工智能·python·django
无人装备硬件开发爱好者22 分钟前
Python + Blender 5.0 几何节点全栈实战教程1
开发语言·python·blender
witAI23 分钟前
**AI漫剧制作工具2025推荐,解锁高效创作新体验**
人工智能·python