python - 余弦相似度和句子
问题描述
我想知道如何逐句打印这个句子,而不是 readline() 逐行阅读。我正在尝试创建句子变量。例如
s1 = "the mississippi is well worth reading about"
s2 = "it is not a commonplace river, but on the contrary is in all ways remarkable"
这是第一个解决方法吗?如果是这样,我知道该怎么做的下一步是从句子中删除常用词,只留下唯一词进行比较。
如何在句号处停止,然后将该句子存储到循环遍历文本的变量中?
谢谢
解决方案
你是这个意思吗:
with open("file.txt",'r') as in_f:
sentences = in_f.read().replace('\n','').split('.')
for each s in sentences:
#your code
推荐阅读
- mysql - 什么是正确的语法?
- c# - Entity Framework Core:如何将不同的对象实例映射到同一个实体?
- python - 下面的代码显示错误..请解决
- php - 如何将 var_dump/json_decode 中的 int 存储到 php 中的变量中?
- ssl - 模块化 Java 13 / JavaFx WebWiew 在 jlinked 时无法显示
- jmeter - 请求在 Postman 中运行良好,但出现错误 Apache-JMETER
- maximo - 在 maximo 中将事务类型有条件地设置为 RETURN
- java - 将休眠配置文件放在哪里
- python - 是否可以绘制曲线下填充的地平线渐变颜色?
- ubuntu-18.04 - 尝试“ant -deploy”后如何修复“BUILD FAILED”?