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

相关推荐
还是鼠鼠4 分钟前
AI掘金头条新闻系统 (Toutiao News)-用户注册-创建用户
后端·python·mysql·fastapi·web
灰灰勇闯IT13 分钟前
DeepSeek-R1 在 CANN 上的推理部署
pytorch·python·深度学习
天才测试猿1 小时前
Jenkins+Docker自动化测试全攻略
自动化测试·软件测试·python·测试工具·docker·jenkins·测试用例
5201-2 小时前
向量数据库在 NPU 上的加速
数据库·pytorch·python
arbitrary192 小时前
自动化业务通报系统实现
大数据·数据库·python·jupyter
yuhuofei20212 小时前
【Python入门】Python中字符串相关拓展
android·java·python
weixin199701080162 小时前
[特殊字符] 人工抓取数据革命:从“人肉爬虫”到“智能数据工厂”全面转型指南
开发语言·爬虫·python
shangxianjiao3 小时前
fastapi
python·fastapi
我材不敲代码3 小时前
Python 基础:列表的切片与嵌套列表使用技巧
开发语言·python
彦为君4 小时前
JavaSE-03-集合框架(详细版)
java·开发语言·python