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

相关推荐
JWASX2 分钟前
【agent 开发】Agent 智能体
大数据·人工智能·python
智购科技无人售货机工厂店6 分钟前
玻璃瓶饮料破损率突然上升,排查发现是取货口缓冲垫老化了~YH
java·开发语言·人工智能·python·eclipse
JWASX14 分钟前
【agent 开发】agent 开发学习 - LangChain(2)
python·学习·langchain
kimnoic28 分钟前
Python常用标准库模块及查询使用方法
开发语言·python
范中勤29 分钟前
Python 与 Java:模块、包、对象、反射核心差异总结
java·python·面试·反射·元类
I Am a robert girl29 分钟前
HelixWorld 源码剖析:当世界模型第一次“开口说话”
python·多模态·扩散模型·世界模型·自回归·空间音频·流式推理
棉猴32 分钟前
玩游戏学Python6-演员Actor
python·pygame·玩游戏·游戏编程·actor·pgzero
旖旎夜光1 小时前
【LangGraph实战】LangGraph 学习笔记(四):持久化——从线程记忆到跨会话长期记忆
人工智能·笔记·python·学习·ai编程·langgraph
yeflx1 小时前
万向节死锁
python
亿道电子Emdoor1 小时前
【Perforce】Klocwork-kwgcheck图形化界面无法打开如何解决
git·python·github