我试图抓住博客的评论,并决定它是否具有情感性和信息性。
我找到了最常用的名词(前10名)。
在那个过程之后,我制作了两个txt文件。
第一个文件包含情感名词。第二个文件包含信息名词。
最后,我想知道博客是否有更多情感名词或更多信息名词。我需要为最后一个流程制作哪些代码?
答案 0 :(得分:0)
# This is the file where you have your top 10 nouns
fc = open("words.txt")
list_blog = []
for line in fc:
list_blog.append(line.strip())
f1 = open("file1.txt") # This is your first file of emotional nouns
d1 = {}
c = 0
for line in fc:
c+=1
d1[line] = str(c)
f2 = open("file2.txt") # This is your seconf file of informational nouns
d2 = {}
c = 0
for line in fc:
c+=1
d2[line] = str(c)
count1 = 0
count2 = 0
count3 = 0
for i in list_blog:
if i in d1:
count1+=1
elif i in d2:
count2+=1
else:
count3+=1
print(count1,count2,count3)
可能有更好的方式来编写它,但我只是快速写它,所以它不是最有效的代码