^L ig 8 dZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z dZ dZdZd Zgd Zid e d e d e de de de de de de de de de de de de de de ide de de de d e d!e d"e d#e d$e d%e d&e d'e d(e d)e d*e d+e d,e id-e d.e d/e d0e d1e d2e d3e d4e d5e d6e d7e d8e d9e d:e d;e de d?e d@e dAe dBe dCe dDe dEe dFe dGedHedIedJedKedLedMedNeidOedPedQedRedSedTedUedVedWedXedYedZed[ed\ed]ed^eZd_d`d`d`d`dad_d_d_d`d_d`db Zdcdcddddded`dfdcdgdh ZddiZddjZdkZdlZGdmdneZGdodpeZedqk(rgdrZeZedsedteduedvedwedxedyedzed{ed|ed}ed~edeD]1Z ejCe Z"edjGe e$e"3edsededededsgdZ%edsededede%D]1Z ejCe Z"edjGe e$e"3edsedseddZ&edjGe&edddl'm(Z(e(jRe&Z*deZ+e*D]<Z ejCe Z"edjGe e$e"de+e"dz Z+>ede$e,e+e-e*z dzedsedsedgdZ.deZ/e.D]<Z0ejCe0Z"edjGe0e$e"de/e"dz Z/>ede$e,e/e-e.z dzedgdZ.deZ/e.D]<Z0ejCe0Z"edjGe0e$e"de/e"dz Z/>ede$e,e/e-e.z dzedse1dZ2e2jgjijkdrddl6Z6ededededgdZ7gdZ8gdZ9e9D]Z dZ:e8e9jwe ZnVdjGe eejCe=Z"edjGe7e9jwe e e$e"de>edsedyy)a If you use the VADER sentiment analysis tools, please cite: Hutto, C.J. & Gilbert, E.E. (2014). VADER: A Parsimonious Rule-based Model for Sentiment Analysis of Social Media Text. Eighth International Conference on Weblogs and Social Media (ICWSM-14). Ann Arbor, MI, June 2014. N)product) getsourcefile)opengn?gnҿg~jt?gGz);aintarentcannotcantcouldntdarentdidntdoesntzain'tzaren'tzcan'tzcouldn'tzdaren'tzdidn'tzdoesn'tdonthadnthasnthaventisntmightntmustntneitherzdon'tzhadn'tzhasn'tzhaven'tzisn'tzmightn'tzmustn'tneedntzneedn'tnevernonenopenornotnothingnowhereoughtntshantshouldntuhuhwasntwerentzoughtn'tzshan'tz shouldn'tzuh-uhzwasn'tzweren'twithoutwontwouldntzwon'tzwouldn'trarelyseldomdespite absolutely amazinglyawfully completely considerable considerably decidedlydeeplyeffingenormous enormouslyentirely especially exceptional exceptionallyextreme extremely fabulouslyflippingflippinfrackinfrackingfrickingfrickinfriggingfrigginfullyfuckinfuckingfugginfugginggreatlyhellahighlyhugely incredible incredibly intenselymajormajorlymoremost particularlypurelyquitereally remarkablyso substantially thoroughlytotaltotally tremendous tremendouslyuber unbelievably unusuallyutterutterlyveryalmostbarelyhardlyz just enoughzkind ofkindakindofzkind-oflesslittlemarginal marginally occasional occasionallypartlyscarcescarcelyslightslightlysomewhatzsort ofsortasortofzsort-of) zcut the mustardz hand to mouthz back handedz blow smokez blowing smokez upper handz break a legzcooking with gasz in the blackz in the redz on the ballzunder the weather?gg @) zthe shitzthe bombzbad assbadasszbus stopz yeah rightz kiss of deathz to die forz beating heartc|Dcgc]}t|j}}g}|jt|D]}||vsy|r |D]}d|vsy ycc}w)z4 Determine if input contains negation words Tzn'tF)strlowerextendNEGATE) input_words include_ntw neg_wordswords c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/vaderSentiment/vaderSentiment.pynegatedrTs{,77a3q6<<>7K7I V ;  D}  8s AcZ|tj||z|zz }|dkry|dkDry|S)zp Normalize the score to be between -1 and 1 using an alpha that approximates the max expected value gg?)mathsqrt)scorealpha norm_scores r normalizeris< EEMU#:;;JD c cd}d}|D]}|js|dz }t||z }d|cxkrt|krn|Sd}|S)z Check whether just some words in the input are ALL CAPS :param list words: The words to inspect :returns: `True` if some but not all items in `words` are ALL CAPS Frr{T)isupperlen)words is_different allcap_wordsrcap_differentials rallcap_differentialrwsf LL <<> A L5zL0 (c%j(  rcd}|j}|tvr>t|}|dkr|dz}|jr|r|dkDr |tz }|S|tz}|S)z\ Check if the preceding words increase, decrease, or negate/nullify the valence r~r)r BOOSTER_DICTrC_INCR)rvalence is_cap_diffscalar word_lowers rscalar_inc_decrsj FJ\!j) Q; bLF <<>k{&  M&  Mrc,eZdZdZdZedZdZy) SentiTextzL Identify sentiment-relevant string-level properties of input text. ct|tst|jd}||_|j |_t |j |_y)Nutf-8) isinstancerencodetext_words_and_emoticonswords_and_emoticonsrr)selfrs r__init__zSentiText.__init__sM$$t9##G,D #'#<#<#> /t/G/GHrcd|jtj}t|dkr|S|S)z Removes all trailing and leading punctuation If the resulting string has two or fewer characters, then it was likely an emoticon, so return original string (ie ":)" stripped would be "", so just return ":)" ry)stripstring punctuationr)tokenstrippeds r_strip_punc_if_wordzSentiText._strip_punc_if_words.;;v112 x=A Lrcx|jj}tt|j|}|S)z Removes leading and trailing puncutation Leaves contractions and most emoticons Does not preserve punc-plus-letter emoticons (e.g. :D) )rsplitlistmapr)rwesrs rrzSentiText._words_and_emoticonss0 iiooD44c:;rN)__name__ __module__ __qualname____doc__r staticmethodrrrrrrs&I  rrceZdZdZddZdZdZdZdZdZ e dZ e d Z e d Z e d Zd Ze d Ze dZe dZdZy)SentimentIntensityAnalyzerz8 Give a sentiment intensity score to sentences. ctjjtd}tjj tjj ||}t j|d5}|j|_ ddd|j|_ tjj tjj ||}t j|d5}|j|_ ddd|j|_y#1swYxYw#1swY+xYw)NcyNrrrrrz5SentimentIntensityAnalyzer.__init__..srr)encoding)ospathabspathrjoindirnamecodecsrreadlexicon_full_filepath make_lex_dictlexiconemoji_full_filepathmake_emoji_dictemojis)r lexicon_file emoji_lexicon_this_module_file_path_rfrs rrz#SentimentIntensityAnalyzer.__init__s"$''//- 2J"K " RWW__=T-UWc d [[. A 2Q)*D & 2))+  ggll277??;R+SUbc [[,w ? 01'(vvxD $ 0**,  2 2  0 0s>D9E9EEci}|jjdjdD]8}|s|jjddd\}}t |||<:|S)z6 Convert lexicon file to a dictionary   rry)rrstriprrfloat)rlex_dictlinermeasures rrz(SentimentIntensityAnalyzer.make_lex_dictso..55d;AA$G ,D"jjl006q;OT7"7^HTN  , rci}|jjdjdD],}|jjddd\}}|||<.|S)z< Convert emoji lexicon file to a dictionary rrrry)rrrr)r emoji_dictremoji descriptions rrz*SentimentIntensityAnalyzer.make_emoji_dictsh ,,33D9??E ,D#'::<#5#5d#;Aa#@ UK +Ju  ,rcdd}d}|D]8}||jvr|j|}|s|dz }||z }d}/||z }|dk(}:|j}t|}g}|j}t |D]\} } d} | j t vr|j| 0| t|dz kr>| j dk(r+|| dzj dk(r|j| |j| || | |}|j||}|j||} | S) z Return a float for sentiment strength based on the input text. Positive values are positive valence, negative value are negative valence. T Frr{kindof) rrrr enumeraterrappendrsentiment_valence _but_check score_valence) rr text_no_emoji prev_spacechrr sentitext sentimentsriitemr valence_dicts rpolarity_scoresz*SentimentIntensityAnalyzer.polarity_scoress]   (Cdkk!"kk#. !!S(M, " $  CZ  (""$dO  ';; !45 YGAtGzz||+!!'*C+,q00TZZ\V5K'A.446$>!!'*//D!ZXJ Y__%8*E ))*d; rc|j}|j}|j}||jvr|j|}|dk(r5|t |dz k7r$||dzj|jvrd}|dkDr||dz jdk(sT|dkDr||dz jdk(s6|dkDrG||dz jdk(r.||dz jdvr|j|t z}|j r|r|dkDr |tz }n |tz}tddD]} || kDs ||| dzz j|jvs/t||| dzz ||} | dk(r | dk7r| dz} | dk(r | dk7r| d z} || z}|j||| |}| dk(s|j|||}|j|||}|j||S) Nnor{r~rryr|)orrgffffff?g?)rrrrrN_SCALARrrranger_negation_check_special_idioms_check _least_checkr) rrrrrrrritem_lowercasestart_iss rrz,SentimentIntensityAnalyzer.sentiment_valencesE++ ';; T\\ )ll>2G%!s3F/G/I*INabcfgbgNhNnNnNptxuAuAOAA-a!e4::<Dq50Q7==?4Gq50Q7==?4GL_`ade`eLfLlLlLnrL,,~6A||~+Q;v%Gv%G A; ^w;#6qGaK7H#I#O#O#QY]YeYe#e&':1! ;L'MwXcdA!|QH!|QG%kG"227QRSVWRW>X>^>^>`dj>j!H,U*1q51779M'A.446'A(Grcf|Dcgc]}t|j}}d|vr|jd}|D]k}|j|}||kr'|j||j ||dz@||kDsF|j||j ||dzm|Scc}w)Nbutg?r})rrindexpopinsert)rrrwords_and_emoticons_lowerbi sentimentsis rrz%SentimentIntensityAnalyzer._but_checkKs>Q$QSV\\^$Q!$Q - -*007B' ; %%i07NN2&%%b)c/:"WNN2&%%b)c/: ;%Rs B.c$|Dcgc]}t|j}}dj||dz ||}dj||dz ||dz ||}dj||dz ||dz }dj||dz ||dz ||dz }dj||dz ||dz } ||||| g} | D]} | tvs t| }nt |dz |kDr,dj||||dz} | tvr t| }t |dz |dzkDr3dj||||dz||dz} | tvr t| }|| |g}|D]}|t vs |t |z}|Scc}w)Nz{0} {1}r{z {0} {1} {2}ryr|)rrformat SPECIAL_CASESrr)rrrrr onezero twoonezerotwoone threetwoonethreetwo sequencesseqzeroone zeroonetwon_gramsn_grams rrz0SentimentIntensityAnalyzer._special_idioms_check[s"=P$QSV\\^$Q!$Q""#-a!e4?!3A14EFGH!H, a<(Q/7:.q1u5=AZ[\_`[`AaekAk.q1u5=AZ[\_`[`AaekAk!D.  +1q51Y>.q1u5@D]^_bc^cDdhoDo!3A14EFGH!H,1%Rs D5cT|j|}|j|}||z}|S)N) _amplify_ep _amplify_qm)rr ep_amplifier qm_amplifierpunct_emph_amplifiers r_punctuation_emphasisz0SentimentIntensityAnalyzer._punctuation_emphasiss3''- ''- +l:##rc@|jd}|dkDrd}|dz}|S)N!g㥛 ?count)rep_countr,s rr*z&SentimentIntensityAnalyzer._amplify_eps/::c? a<H %' rcR|jd}d}|dkDr|dkr|dz}|Sd}|S)N?rr{r|g ףp= ?gQ?r3)rqm_countr-s rr+z&SentimentIntensityAnalyzer._amplify_qmsD::c? a<1} ($  $ rcd}d}d}|D]9}|dkDr|t|dzz }|dkr|t|dz z }|dk(s5|dz };|||fS)Nr~rr{)r)rpos_sumneg_sum neu_countsentiment_scores r_sift_sentiment_scoresz1SentimentIntensityAnalyzer._sift_sentiment_scoressz ) O"E/2Q67"E/2Q67!#Q  **rcj|rtt|}|j|}|dkDr||z }n |dkr||z}t|}|j |\}}}|t j |kDr||z }n|t j |kr||z}|t j |z|z} t j || z } t j || z } t j || z } nd}d} d} d} t| dt| dt| dt|dd} | S)Nrr~r|r2)negneuposcompound)rr!r/rr>rfabsround)rrrsum_sr.rCr:r;r<r\rBr@rAsentiment_dicts rrz(SentimentIntensityAnalyzer.score_valences? #j/*E#'#=#=d#C qy---- 'H*.*E*Ej*Q 'GWi7++//499W--//dii009rrrrrrs - +Z)V   $$L  6$   + +$rr__main__)z$VADER is smart, handsome, and funny.z$VADER is smart, handsome, and funny!z)VADER is very smart, handsome, and funny.z)VADER is VERY SMART, handsome, and FUNNY.z+VADER is VERY SMART, handsome, and FUNNY!!!z8VADER is VERY SMART, uber handsome, and FRIGGIN FUNNY!!!z(VADER is not smart, handsome, nor funny.zThe book was good.z"At least it isn't a horrible book.zThe book was only kind of good.zSThe plot was good, but the characters are uncompelling and the dialog is not great.z Today SUX!z*Today only kinda sux! But I'll get by, lolzMake sure you :) or :D today!u0Catch utf-8 emoji such as 💘 and 💋 and 😁zNot bad at allz4----------------------------------------------------z8 - Analyze typical example cases, including handling of:z -- negationsz0 -- punctuation emphasis & punctuation floodingz7 -- word-shape as emphasis (capitalization difference)zS -- degree modifiers (intensifiers such as 'very' and dampeners such as 'kind of')zD -- slang words as modifiers such as 'uber' or 'friggin' or 'kinda'zg -- contrastive conjunction 'but' indicating a shift in sentiment; sentiment of later text is dominantz% -- use of contractions as negationsz0 -- sentiment laden emoticons such as :) and :Du8 -- utf-8 encoded emojis such as 💘 and 💋 and 😁z. -- sentiment laden slang words (e.g., 'sux')zD -- sentiment laden initialisms and acronyms (for example: 'lol') z {:-<65} {}z - About the scoring: a -- The 'compound' score is computed by summing the valence scores of each word in the lexicon, adjusted according to the rules, and then normalized to be between -1 (most extreme negative) and +1 (most extreme positive). This is the most useful metric if you want a single unidimensional measure of sentiment for a given sentence. Calling it a 'normalized, weighted composite score' is accurate.a( -- The 'pos', 'neu', and 'neg' scores are ratios for proportions of text that fall in each category (so these should all add up to be 1... or close to it with float operation). These are the most useful metrics if you want multidimensional measures of sentiment for a given sentence.) z'Sentiment analysis has never been good.z,Sentiment analysis has never been this good!z1Most automated sentiment analysis tools are shit.z+With VADER, sentiment analysis is the shit!z0Other sentiment analysis tools can be quite bad.z)On the other hand, VADER is quite bad asszVADER is such a badass!z Without a doubt, excellent idea.zDRoger Dodger is one of the most compelling variations on this theme.z@Roger Dodger is at least compelling as a variation on the theme.zERoger Dodger is one of the least compelling variations on this theme.zNot such a badass after all.z#Without a doubt, an excellent idea.z] - Analyze examples of tricky sentences that cause trouble to other sentiment analysis tools.zZ -- special case idioms - e.g., 'never good' vs 'never this good', or 'bad' vs 'bad ass'.z< -- special uses of 'least' as negation versus comparison z {:-<69} {}zs - VADER works best when analysis is done at the sentence level (but it can work on single words or entire novels).zIt was one of the worst movies I've seen, despite good reviews. Unbelievably bad acting!! Poor direction. VERY poor production. The movie was bad. Very bad movie. VERY BAD movie!z\ -- For example, given the following paragraph text from a hypothetical movie review: '{}'z -- You could use NLTK to break the paragraph into sentence tokens for VADER, then average the results for the paragraph like this: )tokenizerCz"AVERAGE SENTIMENT FOR PARAGRAPH: r2zW - Analyze sentiment of IMAGES/VIDEO data based on annotation 'tags' or image labels. )balloonscakecandleszhappy birthdayfriendslaughingsmilingpartyz {:-<15} {}z#AVERAGE SENTIMENT OF TAGS/LABELS: r)riotfirefightbloodmobwarpoliceztear gasz Would you like to run VADER demo examples with NON-ENGLISH text? (Note: requires Internet access and uses the 'requests' library) Type 'y' or 'n', then press Enter: yz5 ----------------------------------------------------z7 - Analyze sentiment of NON ENGLISH text...for example:zl -- French, German, Spanish, Italian, Russian, Japanese, Arabic, Chinese(Simplified) , Chinese(Traditional)z& -- many other languages supported. ) EnglishFrenchGermanSpanishItalianRussianJapaneseArabiczChinese(Simplified)zChinese(Traditional)) enfrdeesitrujaarzzh-CNzzh-TW) z9I'm surprised to see just how amazingly helpful VADER is!z@Je suis surpris de voir comment VADER est incroyablement utile !uBIch bin überrascht zu sehen, nur wie erstaunlich nützlich VADER!u9Me sorprende ver sólo cómo increíblemente útil VADER!uASono sorpreso di vedere solo come incredibilmente utile VADER è!ulЯ удивлен увидеть, как раз как удивительно полезно ВЕЙДЕРА!ua私はちょうどどのように驚くほど役に立つベイダーを見て驚いています!uUأنا مندهش لرؤية فقط كيف مثير للدهشة فيدر فائدة!u*我很惊讶地看到VADER是如此有用!u*我很驚訝地看到VADER是如此有用!razen-USzNo translation neededz:http://mymemory.translated.net/api/get?q={}&langpair={}|{}zhMozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11z?text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8zISO-8859-1,utf-8;q=0.7,*;q=0.3rzen-US,en;q=0.8z keep-alive)z User-AgentAcceptzAccept-CharsetzAccept-EncodingzAccept-Language Connection)headers responseDatatranslatedTextzMemoryNet Translation Servicez- {: <8}: {: <69} {} ({})z Demo Done!)T))Frrrerrrjson itertoolsrinspectriorB_INCRB_DECRrrrrrrrrrrobjectrrr sentencesanalyzerr sentencervsrrtricky_sentences paragraphnltkrI sent_tokenize sentence_listparagraphSentimentsrEr conceptListconceptSentimentsconceptinput do_translaterlstrip __contains__requests languageslanguage_codesnonEnglish_sentencesto_langr  from_lang translationtranslator_nameapi_urlhdrsgetresponseloadsr response_jsonrrrrs5   !    WN\6N;N 6N6N)6N3A6N&N"FN,4fN>H&NR^`fNN&vN0=fNGVW]N N$V N 6 N &v N 09& N CLV N V`ag N  N #F N -7 N AJ6 N T[\b NvN!&N+3FN=FvNN N*26NH)N(R\]c)N*+N* +N**26+N*?@R ^+, 03u=NQTU`Qa=acd7e3f fg $KXK,  % %g . l!!'3r*~+>?@R ^+, 03u=NQTU`Qa=acd7e3f fg @A xyL""$11#6 FG GH |} 78Z [ "- ^HG&';'A'A('KLIT!yG';& "9W]]^fhq^eg#M_&F'-'7". 0(8<<> * 8== 9 +N;7JO] ^- ^0 DE [r