余弦相似与句子

2024-10-01 04:59:38 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我试着用一个文本文件做一个余弦相似性。https://lms.uwa.edu.au/bbcswebdav/pid-1143173-dt-content-rid-16133365_1/courses/CITS1401_SEM-2_2018/CITS1401_SEM-2_2018_ImportedContent_20180713092326/CITS1401_SEM-1_2018/Unit%20Content/Resources/Project2_2018/sample.txt

我想知道我怎么一句一句地打印这个句子而不是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"

这是第一条路吗?如果是的话,我知道下一步该怎么做,就是从句子中去掉常用词,只留下独特的词来比较。你知道吗

我如何在句号处停下来,然后把这个句子存储到一个循环遍历文本的变量中?你知道吗

谢谢


Tags: thehttpsisdt相似性pid句子au
1条回答
网友
1楼 · 发布于 2024-10-01 04:59:38

你的意思是:

with open("file.txt",'r') as in_f:
  sentences = in_f.read().replace('\n','').split('.')
  for each s in sentences:
     #your code

相关问题 更多 >