?\|': txt = txt.replace(ch," ") return txttext = getTe_python英文情感分析">
当前位置:   article > 正文

python中英文文本情感分析_python英文情感分析

python英文情感分析

英文文本:

  1. from textblob import TextBlob
  2. def getText():
  3. txt = open('comment.text','r',encoding='utf-8').read()
  4. txt = txt.lower()
  5. for ch in '`~!@#$%^&*()_+-={}[];":,/<>?\|':
  6. txt = txt.replace(ch," ")
  7. return txt
  8. text = getText()
  9. blob = TextBlob(text)
  10. print("每条评论单独的分析如下:")
  11. for i in range(len(blob.sentences)):
  12. print(blob.sentences[i].sentiment)
  13. print("所有评论的分析如下:")
  14. print(blob.sentiment)

中文实例:

  1. #中文情感分析SnowNLP
  2. from snownlp import SnowNLP
  3. text = u'我很高兴啊。 我很难过。'
  4. s = SnowNLP(text)
  5. for sentence in s.sentences:
  6. print(sentence)
  7. s1 = SnowNLP(s.sentences[0])
  8. s2 = SnowNLP(s.sentences[1])
  9. print(s1.sentiments)
  10. print(s2.sentiments)

结果:

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/721373
推荐阅读
相关标签
  

闽ICP备14008679号