猫史档案馆


【情感值分析】使用snownlp进行中文语句情感值分析

用户:JimmyBoyJimmyBoy查看:0 回复:0 评论:0 创建时间:2020-05-11T16:06:40


from snownlp import SnowNLP,summary
from pyecharts import Line
import webbrowser
import os

with open ("滚滚长江东逝水.txt","r",encoding="utf-8-sig") as a:
	text = a.readlines()
print(text)

sen_score = {}
sentiment = []
poem = []
for i in text:
	a1 = SnowNLP(i)
	a2 = a1.sentiments
	# print(i,a2)
	sentiment.append(a2)
	poem.append(i)
	sen_score[a2] = i
print(sen_score)
print(poem)
print(sentiment)

b = sorted(sentiment)
print(b)

s=" ".join(text)

print(s)

t = SnowNLP(s)
print("中心句",t.summary(2))

line = Line("滚滚长江东逝水","明状元-杨慎")
line.add("Jimmy所著,诗词之美",poem , sentiment,is_label_show=False,mark_point=["max","min"])
line.render()

webbrowser.open("file://"+os.path.realpath("render.html"))

 

这是我编写的解析

【腾讯文档】snownlp 中文
https://docs.qq.com/doc/DZWJab1BWS3RRa1dR

 

有问题可以喵qq 1969765920.备注[bcmlt6528].


回复

上一页1 页 / 共 0下一页