xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

資源簡介

用python實現基于情感詞典的情感分析 大數據分析

資源截圖

代碼片段和文件信息

#?-*-?coding:?utf-8?-*-i
#!/usr/bin/python
import?sys
import?json
from?smallseg?import?SEG
seg?=?SEG()
reload(sys)
sys.setdefaultencoding(“utf-8“)

def?loadDict(fileName?score):
wordDict?=?{}
with?open(fileName)?as?fin:
for?line?in?fin:
word?=?line.strip()
wordDict[word]?=?score
return?wordDict

def?appendDict(wordDict?fileName?score):
with?open(fileName)?as?fin:
for?line?in?fin:
word?=?line.strip()
wordDict[word]?=?score

def?loadExtentDict(fileName):
extentDict?=?{}
for?i?in?range(6):
with?open(fileName?+?str(i?+?1)?+?“.txt“)?as?fin?:
for?line?in?fin:
word?=?line.strip()
extentDict[word]?=?i?+?1
return?extentDict

postDict?=?loadDict(u“sentimentDict/正面情感詞語(中文).txt“?1)
appendDict(postDict?u“sentimentDict/正面評價詞語(中文).txt“?1)
appendDict(postDict?u“sentimentDict/正面評價詞語(中文)1.txt“?1)
appendDict(postDict?u“sentimentDict/正面評價詞語(中文)2.txt“?1)
negDict?=?loadDict(u“sentimentDict/負面情感詞語(中文).txt“?-1)
appendDict(negDict?u“sentimentDict/負面評價詞語(中文).txt“?-1)
extentDict?=?loadExtentDict(u“sentimentDict/程度級別詞語(中文)“)
inverseDict?=?loadDict(u“sentimentDict/否定詞語.txt“?-1)
punc?=?loadDict(u“sentimentDict/標點符號.txt“?1)
exclamation?=?{“!“:2?“!“:2}
for?line?in?sys.stdin:
line?=?line.strip()
record?=?json.loads(line[1:-1])
key?=?record[“weiboId“]
content?=?record[“content“]
wordList?=?seg.cut(content)
wordList.reverse()

lastWordPos?=?0
lastPuncPos?=?0
i?=?0
for?word?in?wordList:
word?=?word.encode(“utf-8“)
if?word?in?punc:
lastPuncPos?=?i
if?word?in?postDict:
if?lastWordPos?>?lastPuncPos:
start?=?lastWordPos
else:
start?=?lastPuncPos
score?=?1
#print?“start:?“?+?str(start)
#print?“end:?“?+?str(i)
for?word_before?in?wordList[start:i]:
word_before?=?word_before.encode(“utf-8“)
if?word_before?in?extentDict:
score?=?score?*?extentDict[word_before]
if?word_before?in?inverseDict:
score?=?score?*?-1
for?word_after?in?wordList[i+1:]:
word_after?=?word_after.encode(“utf-8“)
if?word_after?in?punc:
if?word_after?in?exclamation:
score?=?score?+?2
else:
break;
#print?‘%s\t%s\t%s‘?%?(key?word?score)
print?‘%s\t%s‘?%?(key?score)
lastWordPos?=?i
elif?word?in?negDict:
if?lastWordPos?>?lastPuncPos:
start?=?lastWordPos
else:
start?=?lastPuncPos
score?=?-1
#print?“start:?“?+?str(start)
#print?“end:?“?+?str(i)
for?word_before?in?wordList[start:i]:
word_before?=?word_before.encode(“utf-8“)
if?word_before?in?extentDict:
score?=?score?*?extentDict[word_before]
if?word_before?in?inverseDict:
score?=?score?*?-1
for?word_after?in?wordList[i+1:]:
word_after?=?word_after.encode(“utf-8“)
if?word_after?in?punc:
if?word_after?in?exclamation:
score?=?score?-?2
else:
break;
#print?‘%s\t%s\t%s‘?%?(key?word?score)
print?‘%s\t%s‘?%?(key?score)
lastWordPo

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件?????207606??2015-12-24?22:37??基于情感詞典進行情感分析\10000+運行結果.txt

?????文件???????3184??2015-12-24?00:01??基于情感詞典進行情感分析\mapper.py

?????文件????????391??2015-12-24?00:01??基于情感詞典進行情感分析\reducer.py

?????文件????????289??2015-12-19?21:52??基于情感詞典進行情感分析\情感詞典\主張詞語(中文).txt

?????文件????????140??2015-12-19?22:14??基于情感詞典進行情感分析\情感詞典\否定詞語.txt

?????文件??????????5??2015-12-22?19:24??基于情感詞典進行情感分析\情感詞典\感嘆號.txt

?????文件???????6252??2015-12-19?21:51??基于情感詞典進行情感分析\情感詞典\正面情感詞語(中文).txt

?????文件??????30384??2015-12-19?21:51??基于情感詞典進行情感分析\情感詞典\正面評價詞語(中文).txt

?????文件??????15905??2015-12-19?21:51??基于情感詞典進行情感分析\情感詞典\正面評價詞語(中文)1.txt

?????文件??????14973??2015-12-19?21:51??基于情感詞典進行情感分析\情感詞典\正面評價詞語(中文)2.txt

?????文件?????????72??2015-12-19?21:49??基于情感詞典進行情感分析\情感詞典\程度級別1詞語(中文).txt

?????文件????????174??2015-12-19?21:49??基于情感詞典進行情感分析\情感詞典\程度級別2詞語(中文).txt

?????文件????????224??2015-12-19?21:50??基于情感詞典進行情感分析\情感詞典\程度級別3詞語(中文).txt

?????文件????????218??2015-12-19?21:50??基于情感詞典進行情感分析\情感詞典\程度級別4詞語(中文).txt

?????文件????????170??2015-12-19?21:50??基于情感詞典進行情感分析\情感詞典\程度級別5詞語(中文).txt

?????文件????????430??2015-12-19?21:50??基于情感詞典進行情感分析\情感詞典\程度級別6詞語(中文).txt

?????文件???????9927??2015-12-19?21:51??基于情感詞典進行情感分析\情感詞典\負面情感詞語(中文).txt

?????文件??????26076??2015-12-19?21:51??基于情感詞典進行情感分析\情感詞典\負面評價詞語(中文).txt

?????文件?????????88??2015-12-24?23:10??基于情感詞典進行情感分析\結果匯總.txt

?????目錄??????????0??2016-01-11?23:38??基于情感詞典進行情感分析\情感詞典

?????目錄??????????0??2016-01-11?23:39??基于情感詞典進行情感分析

-----------?---------??----------?-----??----

???????????????316508????????????????????21


評論

共有 條評論