NLP之TEA:基于SnowNLP实现自然语言处理之对输入文本进行情感分析(分词→词性标注→拼音简繁转换→情感分析→测试)
NLP之TEA:基于SnowNLP實現自然語言處理之對輸入文本進行情感分析(分詞→詞性標注→拼音&簡繁轉換→情感分析→測試)
?
?
?
?
目錄
NLP分詞
NLP詞性標注
NLP情感分析—TEA
NLP常見功能(輸出拼音、支持方法)
NLP測試
?
?
?
?
?
?
?
NLP分詞
sentence = u"今年春節檔的電影,我尤其喜歡吳京主演的電影《流浪地球》" s = SnowNLP(sentence)print("Segmented words = {}".format(s.words))Segmented words = ['今年', '春節', '檔', '的', '電影', ',', '我', '尤其', '喜歡', '吳', '京', '主演', '的', '電影', '《', '流浪', '地球', '》']
?
?
?
NLP詞性標注
for word, tag in s.tags:print("Word = {}, Tag = {}\n".format(word, tag))Tagging:?
Word = 今年, Tag = t
Word = 春節, Tag = t
Word = 檔, Tag = Ng
Word = 的, Tag = u
Word = 電影, Tag = n
Word = ,, Tag = w
Word = 我, Tag = r
Word = 尤其, Tag = d
Word = 喜歡, Tag = v
Word = 吳, Tag = nr
Word = 京, Tag = nr
Word = 主演, Tag = v
Word = 的, Tag = u
Word = 電影, Tag = n
Word = 《, Tag = w
Word = 流浪, Tag = vn
Word = 地球, Tag = n
Word = 》, Tag = w
?
?
?
NLP情感分析—TEA
print("Sentiment score = {}".format(s.sentiments))Sentiment score = 0.999991806695989
?
?
?
?
NLP常見功能(輸出拼音、支持方法)
print("Pinyin = {}".format(s.pinyin))print(dir(s))Pinyin = ['jin', 'nian', 'chun', 'jie', 'dang', 'de', 'dian', 'ying', ',', 'wo', 'you', 'qi', 'xi', 'huan', 'wu', 'jing', 'zhu', 'yan', 'de', 'dian', 'ying', '《', 'liu', 'lang', 'di', 'qiu', '》']
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'bm25', 'doc', 'han', 'idf', 'keywords', 'pinyin', 'sentences', 'sentiments', 'sim', 'summary', 'tags', 'tf', 'words']
?
簡繁轉換 = 春節檔的電影,我尤其喜歡吳京主演的電影
?
?
?
?
NLP測試
sentence = u"明天早上舉行2019屆全明星比賽,我會看直播,因為我特別喜歡詹姆斯、韋德、杜蘭特、庫里" print("Sentiment score = {}".format(s.sentiments))sentence = u"明天早上有比賽" print("Sentiment score = {}".format(s.sentiments))sentence = u"明天,上海又要下雨,我特別不喜歡下雨的天氣!" print("Sentiment score = {}".format(s.sentiments))Sentiment score = 0.9713889788637894
Sentiment score = 0.4228962549024792
Sentiment score = 0.031366312726148315
?
?
總結
以上是生活随笔為你收集整理的NLP之TEA:基于SnowNLP实现自然语言处理之对输入文本进行情感分析(分词→词性标注→拼音简繁转换→情感分析→测试)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Py之nltk:nltk包的简介、安装、
- 下一篇: AI之Robot:带你玩转机器人DIY机