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

相关推荐
向科→向总工→空间动态计系统5 分钟前
动态零轴融合三铁律
大数据·开发语言·人工智能·python·机器人
Cosolar1 小时前
Agent Harness 架构演进与核心设计原则:基于 Pi、OpenCode、Hermes、OpenClaw 的对比研究
python·llm·agent
鸽嗷高.1 小时前
基于博客系统的接口自动化测试报告
python·功能测试·可用性测试
砚底藏山河1 小时前
量化行情横截面中性化闭式与回归实现
android·java·python·金融·kotlin
CCblandy1 小时前
尾延迟请求对冲实测:20ms阈值让p99降至54–56ms,代价是约60%冗余流量
python·性能优化·架构·分布式系统·尾延迟
高洁011 小时前
高质量数据集的时效性:数据也会过期
人工智能·python·深度学习·机器学习·transformer
都在酒里2 小时前
嵌入式台架自动化:用 Python 回归测试 RS-485 和 CAN
网络·python·自动化
垆边人似月.2 小时前
机器人交互测评(二):测试场景设计与Python自动化测试实战
python·机器人·交互
爱嘿嘿的小黑3 小时前
用 Google Antigravity 踩遍登录和环境坑后,我开源了个 30 秒只读体检脚本 + Agent Skill
人工智能·python·github
ComPDFKit3 小时前
扫描对账单 PDF 转 Excel,怎么查出金额错行?
python·pdf·excel