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

相关推荐
第404号工位4 分钟前
浏览器的“无痕模式”是当代最大安慰剂?我用 30 行 JS 提取硬件指纹,跨网络换代理照样精准锁定你
linux·人工智能·python
凌界天行15 分钟前
知名的无人机侦测肩灯制造厂名声
python
XZ-07000117 分钟前
week10-直方图
python
外收内放19 分钟前
FastAPI猜字谜实战(6):日志与异常
开发语言·python·学习·fastapi
PythonFun19 分钟前
如何生成Python50天系列学习互动网页课件
python·wps
垆边人似月.22 分钟前
预处理与参数调优(让识别率从“能看”到“可用”)
开发语言·python·自然语言处理
gf132111126 分钟前
python_高德地图驾车时长查询
数据库·python·mysql
镜子AI28 分钟前
镜子AI技术实践:用 Python 做 GEO 答案的实体提及抽取与归一化(零依赖两阶段方案)
python·ai
I Am a robert girl31 分钟前
从点到面:Superquadric 分解中“几何感知内点精修”的工程拆解
python·ransac·点云处理·三维感知·superquadric·几何基元拟合·内点判定
计算机毕业编程指导师35 分钟前
计算机毕设推荐:基于深度学习的动物图像识别方法研究(Python+Django+PyTorch)
pytorch·python·深度学习·计算机·毕业设计·课程设计·图像识别