我的python字符串由'
而不是'(单引号)组成。我当前的目标是扩展复合词,如“是”,“不是”。
“这对我来说太好了。我已经治疗了2周,在过去的一周里,我只有3例头痛,而2例泰诺醇消失了。我每天都有慢性头痛,而这本来就不会不管我吃了什么都不要走。白天我还是有点困,但是我知道情况会好起来的。”
以上陈述是我一直尝试转换的句子的示例。
有人可以建议将其转换为字符串格式的方法吗?
答案 0 :(得分:-1)
include
输出:
text = "This has been great for me. I've been on it for 2 weeks and in the last week I only had 3 headaches which went away with 2 Tylenol. I was having chronic daily headaches that wouldn't go away no matter what I took. I'm still a little sleepy during the day, but I know that will get better."
d_contraction = {"I'm":"I am","wouldn't":"would not","I've":"I have"}
updated_text = text.replace(''', "'")
print(updated_text)
for k,v in d_contraction.items():
updated_text = updated_text.replace(k,v)
print(updated_text)
上面的代码适用于您提供的文本。基本上,您将必须创建一个包含所有可能的收缩示例的词典-它们会,等等。