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

相关推荐
WXX_s6 分钟前
【OpenCV篇】OpenCV——03day.图像预处理(2)
人工智能·python·opencv·学习·计算机视觉
Jackilina_Stone1 小时前
【论文|复现】YOLOFuse:面向多模态目标检测的双流融合框架
人工智能·python·目标检测·计算机视觉·融合
双叶8362 小时前
(Python)文件储存的认识,文件路径(文件储存基础教程)(Windows系统文件路径)(基础教程)
开发语言·windows·python
枫昕柚2 小时前
python
开发语言·python
木头左2 小时前
自动驾驶领域中的Python机器学习
python·机器学习·自动驾驶
Dxy12393102162 小时前
Python Requests-HTML库详解:从入门到实战
开发语言·python·html
seasonsyy2 小时前
2.安装CUDA详细步骤(含安装截图)
python·深度学习·环境配置·cuda
写点什么啦3 小时前
一键修复ipynb,Jupyter Notebook损坏文件
ide·python·jupyter
fishwheel3 小时前
Android:Reverse 实战 part 2 番外 IDA python
android·python·安全
测试19983 小时前
cmake应用:集成gtest进行单元测试
自动化测试·软件测试·python·测试工具·职场和发展·单元测试·测试用例