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

相关推荐
zhoutongsheng4 分钟前
如何解决ORA-01078参数文件错误_pfile与spfile互相创建恢复
jvm·数据库·python
Lightning-py7 分钟前
Python 配置日志(Logging)
开发语言·python
2401_824222698 分钟前
HTML怎么标注字数限制提示_HTML实时字数统计占位【详解】
jvm·数据库·python
Hui_AI72018 分钟前
基于RAG的农产品GEO溯源智能问答系统实现
开发语言·网络·人工智能·python·算法·创业创新
不知名的老吴27 分钟前
后端知识点:Python处理加权点赞
开发语言·python
忡黑梨30 分钟前
eNSP_从直连到BGP全网互通
c语言·网络·数据结构·python·算法·网络安全
Cyber4K44 分钟前
【Python专项】基础语法(2)
开发语言·python
2601_956139421 小时前
文旅行业品牌全案公司哪家强
大数据·人工智能·python
hrhcode1 小时前
【LangGraph】二.State 和 Node 的设计细节
python·ai·langchain·langgraph·ai框架
dfdfadffa1 小时前
如何创建仅在首次订阅时执行一次计算的 RxJS 懒加载 Observable
jvm·数据库·python