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

相关推荐
tomelrg14 分钟前
多台服务器批量发布arcgisserver服务并缓存切片
服务器·python·arcgis
A尘埃30 分钟前
Java+Python混合微服务OCR系统设计
java·python·微服务·混合
哈里谢顿42 分钟前
Python 依赖注入详解
python
冬天vs不冷1 小时前
Java基础(九):Object核心类深度剖析
java·开发语言·python
TS的美梦1 小时前
【1:1复刻R版】python版火山图函数一键出图
开发语言·python·r语言·scanpy·火山图
CF14年老兵1 小时前
Python万物皆对象:从懵懂到顿悟的奇妙之旅
后端·python·trae
这里有鱼汤1 小时前
发现个用《道德经》+价值投资大咖的智慧,做A股的AI诊股神器,居然还开源了
python
陈天伟教授2 小时前
(二)Python + 地球信息科学与技术 (GeoICT)=?
开发语言·python
之歆3 小时前
大模型微调分布式训练-大模型压缩训练(知识蒸馏)-大模型推理部署(分布式推理与量化部署)-大模型评估测试(OpenCompass)
人工智能·笔记·python
人工干智能3 小时前
pygame的帧处理中,涉及键盘的有`pg.event.get()`与`pg.key.get_pressed()` ,二者有什么区别与联系?
python·游戏·计算机外设·pygame