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

相关推荐
m0_6403093012 分钟前
c++如何判断两个文件路径是否物理指向同一个磁盘文件_equivalent【详解】
jvm·数据库·python
数智工坊21 分钟前
深度拆解AnomalyAny:异常检测新工作,利用Stable Diffusion生成真实多样异常样本!
人工智能·pytorch·python·stable diffusion
Shorasul25 分钟前
Django 信号中为 ImageField 指定自定义保存路径的正确实践
jvm·数据库·python
Wyz2012102431 分钟前
CSS如何实现移动端点击高亮去除_设置tap-highlight-color
jvm·数据库·python
日光明媚33 分钟前
SoulX-FlashTalk 技术报告解读:从“严格因果”到“双向流式蒸馏”,实时数字人为什么能做到 0.87s 延迟、32FPS 和长时稳定?
人工智能·python·深度学习·ai作画·aigc·音视频
粉嘟小飞妹儿37 分钟前
如何在云主机上安装Oracle 19c_公网IP绑定与安全组端口开放
jvm·数据库·python
飞Link38 分钟前
掌控 Agent 的时空法则:LangGraph Checkpoint (检查点) 机制深度实战
开发语言·python·算法
zopple42 分钟前
Laravel与ThinkPHP框架深度对比
java·python·php·laravel
weixin_586061461 小时前
为什么Bootstrap的下拉菜单在Firefox下显示异常
jvm·数据库·python
qq_189807031 小时前
如何导出特定分区_EXPDP TABLES=表名-分区名进行单区数据备份
jvm·数据库·python