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

相关推荐
MediaTea5 分钟前
Scikit-learn:一个最小机器学习工作流示例
人工智能·python·机器学习·scikit-learn
qq_349317488 分钟前
Layui如何修改表格单元格内文字的行间距
jvm·数据库·python
2301_7751481518 分钟前
Redis如何实现用户标签管理_利用Set结构存储唯一属性集合
jvm·数据库·python
m0_5964063722 分钟前
mysql如何配置审计日志输出_mysql audit_log_format设置
jvm·数据库·python
2301_8166602132 分钟前
Bootstrap框架的最小宽度限制是多少
jvm·数据库·python
水木流年追梦1 小时前
CodeTop Top 300 热门题目2-最长回文子串
开发语言·人工智能·python·算法·leetcode
狗都不学爬虫_1 小时前
小程序逆向 - Hai尔(AliV3拖动物品)
javascript·爬虫·python·网络爬虫
abc123456sdggfd1 小时前
HTML5中Vuex持久化插件中WebStorage的底层配置
jvm·数据库·python
小龙Guo1 小时前
Yolo 多任务推理,摄像头+视频实时推理,实现关键点、分割、检测等模型推理部署
python·yolo·关键点检测·模型推理
pele1 小时前
Go语言如何发GET请求_Go语言HTTP GET请求教程【总结】
jvm·数据库·python