hiDaDeng/cnsenti: 中文情感分析库(Chinese Sentiment))可对 ...

文章推薦指數: 80 %
投票人數:10人

... the number of different emotional words in the text - GitHub - hiDaDeng/cnsenti: 中文情感分析库(Chinese Sentiment))可对文本进行情绪分析、正负情感分析。

Skiptocontent {{message}} hiDaDeng / cnsenti Public Notifications Fork 61 Star 321 中文情感分析库(ChineseSentiment))可对文本进行情绪分析、正负情感分析。

Chinesesentimentanalysislibrary,whichsupportscountingthenumberofdifferentemotionalwordsinthetext License MITlicense 321 stars 61 forks Star Notifications Code Issues 4 Pullrequests 0 Actions Projects 0 Wiki Security Insights More Code Issues Pullrequests Actions Projects Wiki Security Insights hiDaDeng/cnsenti Thiscommitdoesnotbelongtoanybranchonthisrepository,andmaybelongtoaforkoutsideoftherepository. master Branches Tags Couldnotloadbranches Nothingtoshow {{refName}} default Couldnotloadtags Nothingtoshow {{refName}} default 1 branch 0 tags Code Latestcommit   Gitstats 38 commits Files Permalink Failedtoloadlatestcommitinformation. Type Name Latestcommitmessage Committime cnsenti     img     test     .gitignore     LICENSE     README.md     chinese_readme.md     setup.py     大邓和他的Python.png     Viewcode cnsenti Features Notes Installation method1 method2 QuickStart Documents 3.1emotion_count(text) 3.2sentiment_count(text) 3.3sentiment_calculate(text) 3.4customdictionary 3.4.1theformatofcustomdictionary 3.4.2Sentimentcustomdictionaryparameters 3.4.3Customdictionaryusecase README.md Nowcnsentihasbeenintegratedintocntext,welcometostar! cnsenti 中文文档 Thecnsentilibrarycanperformsentimentanalysisemotionanalysisonchinesetexts. Features defaultsentimentdictionaryisHownet defaultemotiondicitonaryisDLUTemotiondictionary,support7categoryemotion,suchashappy/sad/hate...etc/ supportimportingcustomtxtsentimentdictionaries(posandneg) Notes TheemotionalontologylibraryofDalianUniversityofTechnologyusedforsentimentanalysisinthecode.Ifyoupublishapaper,pleasepayattentiontotheuserlicenseagreement TheemotionalvocabularyontologyisindependentlyorganizedandmarkedbytheInformationRetrievalLaboratoryofDalianUniversityofTechnology,andcanbeusedbyuniversities,researchinstitutesandindividualsathomeandabroadforacademicresearchpurposes. Ifanyinstituteorindividualneedstouseitforcommercialpurposes,[email protected]. Ifyoufindanyerrorsorimproprietiesinthisresourceduringuse,usersarewelcometosendyourvaluablecommentstothemailboxirlab@dlut.edu.cn,andwewillsolvethemasquicklyaspossible. Ifusersusethisresourcetopublishpapersorobtainscientificresearchresults,pleaseaddwordssuchas"usingtheemotionalvocabularyontologyoftheInformationRetrievalLaboratoryofDalianUniversityofTechnology"tothepapertodeclare. Addthecitation"徐琳宏,林鸿飞,潘宇,等.情感词汇本体的构造[J].情报学报,2008,27(2):180-185." Anyuserwhoobtainstheresourcethroughcopyingorotherinformaldownloadsshouldalsoabidebythelicenseagreement.TheInformationRetrievalLaboratoryofDalianUniversityofTechnologyhasthefinalrighttointerpretandmodifythelicenseagreement. Installation method1 pipinstallcnsenti method2 pipinstallcnsenti-ihttps://pypi.tuna.tsinghua.edu.cn/simple/ QuickStart CountthenumberofpositiveandnegativeemotionalwordsinChinesetext fromcnsentiimportSentiment senti=Sentiment() test_text='我好开心啊,非常非常非常高兴!今天我得了一百分,我很兴奋开心,愉快,开心' result=senti.sentiment_count(test_text) print(result) Run {'words':24, 'sentences':2, 'pos':4, 'neg':0} CountthenumberofwordswithdifferentemotionsinChinesetext fromcnsentiimportEmotion emotion=Emotion() test_text='我好开心啊,非常非常非常高兴!今天我得了一百分,我很兴奋开心,愉快,开心' result=emotion.emotion_count(test_text) print(result) Run {'words':22, 'sentences':2, '好':0, '乐':4, '哀':0, '怒':0, '惧':0, '恶':0, '惊':0} Documents cnsentiincludestwoclasstype:EmotionclassandSentimentclass Emotionclassincludeemotion_count(text)method Sentimentclassincludesmethod,suchas**sentiment_count(text)**and**sentiment_calculate(text)** 3.1emotion_count(text) emotion_count(text)isusedtocountthenumberofwordsthatappearinvariousemotionaladjectivesinthetext.UseDalianUniversityofTechnologyEmotionOntologyDatabaseDictionarytosupport7emotionstatistics(好good,乐happy,哀sad,怒angry,惧fear,恶disgust,惊shock) fromcnsentiimportEmotion emotion=Emotion() test_text='我好开心啊,非常非常非常高兴!今天我得了一百分,我很兴奋开心,愉快,开心' result=emotion.emotion_count(test_text) print(result) Run {'words':22, 'sentences':2, '好':0, '乐':4, '哀':0, '怒':0, '惧':0, '恶':0, '惊':0} detail words:thewordsnumberofthechinesetext sentences:thesentencenumberofthechinesetext 好good,乐happy,哀sad,怒angry,惧fear,恶disgust,惊shockthewordsnumberofdifferentemotion 3.2sentiment_count(text) 隶属于Sentiment类,可对文本text中的正、负面词进行统计。

默认使用Hownet词典,后面会讲到如何导入自定义正、负情感txt词典文件。

这里以默认hownet词典进行统计。

sentiment_count(text)belongstotheSentimentclassandcancountthepositiveandnegativewordsnumberofthechinesetext.TheHownetdictionaryisusedbydefault,andSentimentclasssupportcustompositiveandnegativeemotiondictionarytxtfiles. Hereweusethedefaulthownetdictionarytocountthewordnumberofchinesetext. fromcnsentiimportSentiment senti=Sentiment() test_text='我好开心啊,非常非常非常高兴!今天我得了一百分,我很兴奋开心,愉快,开心' result=senti.sentiment_count(test_text) print(result) Run {'words':24, 'sentences':2, 'pos':4, 'neg':0} Detail words:thewordsnumberofthechinesetext sentences:thesentencenumberofthechinesetext pos:thepositivewordsnumberoftextchinesetext neg:thepositivewordsnumberoftextchinesetext 3.3sentiment_calculate(text) 隶属于Sentiment类,可更加精准的计算文本的情感信息。

相比于sentiment_count只统计文本正负情感词个数,sentiment_calculate还考虑了 sentiment_calculate(text)belongstotheSentimentclass,whichcancalculatetheemotionalinformationofthechinesetextmoreaccurately.Comparedwithsentiment_countonlycountsthenumberofpositiveandnegativesentimentwordsinthetext,sentiment_calculatealsoconsiders Isthereamodifierofstrengthadverbsbeforeemotionalwords Isthereanemotionalsemanticreversaleffectofnegativewordsbeforeemotionalwords? forexamples: fromcnsentiimportSentiment senti=Sentiment() test_text='我好开心啊,非常非常非常高兴!今天我得了一百分,我很兴奋开心,愉快,开心' result1=senti.sentiment_count(test_text) result2=senti.sentiment_calculate(test_text) print('sentiment_count',result1) print('sentiment_calculate',result2) Run sentiment_count {'words':22, 'sentences':2, 'pos':4, 'neg':0} sentiment_calculate {'sentences':2, 'words':22, 'pos':27.0, 'neg':0.0} 3.4customdictionary Let'sfirstlookatthesentencethatcontainsemotionalinformationbutwithoutemotionaladjectives fromcnsentiimportSentiment senti=Sentiment()#两txt均为utf-8编码 test_text='这家公司是行业的引领者,是中流砥柱。

' result1=senti.sentiment_count(test_text) result2=senti.sentiment_calculate(test_text) print('sentiment_count',result1) print('sentiment_calculate',result2) Run sentiment_count{'words':10,'sentences':1,'pos':0,'neg':0} sentiment_calculate{'sentences':1,'words':10,'pos':0,'neg':0} Asexpected,althoughthesentenceispositive,becausecnsenti'sownsentimentdictionary(Hownet)isonlyanadjectivesentimentdictionary,formanyscenarios,theapplicabilityislimited,sopos=0. 3.4.1theformatofcustomdictionary cnsentisupportsimportingcustomdictionaries,butcurrentlyonlySentimentsupportsimportingcustompositiveandnegativeemotiondictionaries,customdictionariesneedtomeet Mustbeatxtfile Inprinciple,encodingisrecommendedtobeutf-8 onlyonewordperlineintxtfile 3.4.2Sentimentcustomdictionaryparameters senti=Sentiment(pos='正面词自定义.txt', neg='负面词自定义.txt', merge=True, encoding='utf-8') posPositivesentimentdictionarytxtfilepath negNegativesentimentdictionarytxtfilepath mergeBoolean;merge=True,cnsentiwillmergethecustomdictionarywithcnsenti'sowndictionary;merge=False,cnsentiwillonlyusethecustomdictionary encodingBothposandnegtxtareutf-8encoding 3.4.3Customdictionaryusecase Iputthispartinthetestfolder,thecodeandthecustomdictionaryareinthetest,soIusetherelativepathtosetthepathofthecustomdictionary |test |---代码.py#code |---正面词自定义.txt#poscustomdictionarytxt |---负面词自定义.txt#negcustomdictionarytxt 正面词自定义.txtposcustomdictionarytxt 中流砥柱 引领者 fromcnsentiimportSentiment senti=Sentiment(pos='正面词自定义.txt',#正面词典txt文件相对路径 neg='负面词自定义.txt',#负面词典txt文件相对路径 merge=True,#融合cnsenti自带词典和用户导入的自定义词典 encoding='utf-8')#两txt均为utf-8编码 test_text='这家公司是行业的引领者,是中流砥柱。

今年的业绩非常好。

' result1=senti.sentiment_count(test_text) result2=senti.sentiment_calculate(test_text) print('sentiment_count',result1) print('sentiment_calculate',result2) Run sentiment_count{'words':16,'sentences':2,'pos':2,'neg':0} sentiment_calculate{'sentences':2,'words':16,'pos':5,'neg':0} Fortheaboveparameters,wepassedinthepositivecustomdictionaryandthenegativecustomdictionary,andusedthefusionmode(merge=True).Youcanusethecnsenti'sowndictionaryandthenewlyimportedcustomdictionaryforsentimentcalculation. notes: ThelibraryIdesignedcurrentlyonlysupportstwotypes(forexampleposandneg).Ifyourresearchquestionistwoclassificationproblems,suchasgoodandbad,beautifulandugly,friendlyandhostileetc.,youcandefinetwotxtfiles,respectivelyassignvaluestoposandneg,afterthissetting,youcanusethecnsentilibrarytosolveyourresearchquesiton. About 中文情感分析库(ChineseSentiment))可对文本进行情绪分析、正负情感分析。

Chinesesentimentanalysislibrary,whichsupportscountingthenumberofdifferentemotionalwordsinthetext Resources Readme License MITlicense Stars 321 stars Watchers 5 watching Forks 61 forks Releases Noreleasespublished Packages0 Nopackagespublished Languages Python 100.0% Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?