?\|': txt = txt.replace(ch," ") return txttext = getTe_python英文情感分析">
赞
踩
英文文本:
- from textblob import TextBlob
-
- def getText():
- txt = open('comment.text','r',encoding='utf-8').read()
- txt = txt.lower()
- for ch in '`~!@#$%^&*()_+-={}[];":,/<>?\|':
- txt = txt.replace(ch," ")
- return txt
-
-
- text = getText()
- blob = TextBlob(text)
- print("每条评论单独的分析如下:")
- for i in range(len(blob.sentences)):
- print(blob.sentences[i].sentiment)
- print("所有评论的分析如下:")
- print(blob.sentiment)
中文实例:
- #中文情感分析SnowNLP
- from snownlp import SnowNLP
- text = u'我很高兴啊。 我很难过。'
- s = SnowNLP(text)
- for sentence in s.sentences:
- print(sentence)
- s1 = SnowNLP(s.sentences[0])
- s2 = SnowNLP(s.sentences[1])
- print(s1.sentiments)
- print(s2.sentiments)
结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。