
    NgR                         d Z ddlZddlZddlZddlmZ ddlZddlm	Z	  G d d          Z
 G d d          Z G d	 d
          ZdS )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)pairwisec                      e Zd ZdZdZdZdZdZh dZi 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dedededei 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d%ed&ed'ed(ei d)ed*ed+ed,ed-ed.ed/ed0ed1ed2ed3ed4ed5ed6ed7ed8ed9eeeeeeeeeeeeeeeed:Z	d;d;d<d=d>d?d=d@Z
 ej        dA ej        ej                   dB          Zg dCZdD ZdKdFZdLdHZdI ZdJS )MVaderConstantsz8
    A class to keep the Vader lists and constants.
    gn?gnҿg~jt?gGz>;   ain'tcan'tdon'tisn'tuh-uhwon'taren'tdidn'thadn'thasn'tshan'twasn'tdaren'tdoesn'thaven'tmustn'tneedn'tweren'tcouldn'tmightn'toughtn'twouldn't	shouldn'tnornotaintcantdontisntnonenopeuhuhwontarentdidnthadnthasntnevershantwasntcannotdarentdoesnthaventmustntneedntrarelyseldomwerentcouldntdespitemightntneithernothingnowhereoughtntwithoutwouldntshouldnt
absolutely	amazinglyawfully
completelyconsiderably	decidedlydeeplyeffing
enormouslyentirely
especiallyexceptionally	extremely
fabulouslyflippingflippinfrickingfrickinfriggingfrigginfullyfuckinggreatlyhellahighlyhugely
incredibly	intenselymajorlymoremostparticularlypurelyquitereally
remarkablysosubstantially
thoroughlytotallytremendouslyuberunbelievably	unusuallyutterlyveryalmostbarelyhardlyzjust enoughzkind of)kindakindofzkind-oflesslittle
marginallyoccasionallypartlyscarcelyslightlysomewhatzsort ofsortasortofzsort-of         ?   g      )zthe shitzthe bombzbad assz
yeah rightzcut the mustardzkiss of deathzhand to mouth[]).!?,;:-'"z!!z!!!z??z???z?!?z!?!z?!?!z!?!?c                     d S N )selfs    P/var/www/html/ai-engine/env/lib/python3.11/site-packages/nltk/sentiment/vader.py__init__zVaderConstants.__init__   s        Tc                    | j         t          fd|D                       rdS |rt          d |D                       rdS t          |          D ]8\  }}|                                dk    r|                                dk    r dS 9dS )z<
        Determine if input contains negation words
        c              3   D   K   | ]}|                                 v V  d S r   lower).0word	neg_wordss     r   	<genexpr>z)VaderConstants.negated.<locals>.<genexpr>   s0      AATtzz||y(AAAAAAr   Tc              3   B   K   | ]}d |                                 v V  dS )zn'tNr   )r   r   s     r   r   z)VaderConstants.negated.<locals>.<genexpr>   s/      AAT5DJJLL(AAAAAAr   leastatF)NEGATEanyr   r   )r   input_words
include_ntfirstsecondr   s        @r   negatedzVaderConstants.negated   s     K	AAAA[AAAAA 	4 	AA[AAAAA t%k22 	 	ME6||~~((U[[]]d-B-Bttur      c                 @    |t          j        ||z  |z             z  }|S )z|
        Normalize the score to be between -1 and 1 using an alpha that
        approximates the max expected value
        )mathsqrt)r   scorealpha
norm_scores       r   	normalizezVaderConstants.normalize   s'    
 TY'>???
r   c                     d}|                                 }|| j        v rI| j        |         }|dk     r|dz  }|                                r|r|dk    r|| j        z  }n
|| j        z  }|S )zh
        Check if the preceding words increase, decrease, or negate/nullify the
        valence
                r   )r   BOOSTER_DICTisupperC_INCR)r   r   valenceis_cap_diffscalar
word_lowers         r   scalar_inc_deczVaderConstants.scalar_inc_dec   s    
 ZZ\\
***&z2F{{"||~~ *+ *Q;;dk)FFdk)Fr   N)T)r   )__name__
__module____qualname____doc__B_INCRB_DECRr   N_SCALARr   r   SPECIAL_CASE_IDIOMSrecompileescapestringpunctuationREGEX_REMOVE_PUNCTUATION	PUNC_LISTr   r   r   r   r   r   r   r   r   !   s         FF FH< < <FBCfCVC 	6C 	f	C
 	C 	VC 	&C 	&C 	fC 	FC 	fC 	C 	VC 	fC 	FC  	6!C" 	F#C C$ 	6%C& 	F'C( 	6)C* 	+C, 	6-C. 	6/C0 	1C2 	&3C4 	&5C6 	f7C8 	V9C: 	6;C< 	=C> 	?C@ 	ACB 	&CCD 	EC C CF 	&GCH 	fICJ 	fKCL 	MCN 	fOCP 	6QCR 	SCT 	UCV 	WCX 	VYCZ 	6[C\ 	]C^ 	&_C` 	&aCb 	&cCd 	veCf 	6gC Ch EC C CLN    *rz*Nibi8J.K.K*N*N*NOO  I(            r   r   c                   *    e Zd ZdZd Zd Zd Zd ZdS )	SentiTextzL
    Identify sentiment-relevant string-level properties of input text.
    c                    t          |t                    s"t          |                    d                    }|| _        || _        || _        |                                 | _        |                     | j                  | _	        d S )Nzutf-8)

isinstancestrencodetextr   r   _words_and_emoticonswords_and_emoticonsallcap_differentialr   )r   r   	punc_listregex_remove_punctuations       r   r   zSentiText.__init__  sx    $$$ 	-t{{7++,,D	"(@%#'#<#<#>#>   33D4LMMr   c                 0   | j                             d| j                  }|                                }d |D             }d t	          | j        |          D             }d t	          || j                  D             }|}|                    |           |S )zt
        Returns mapping of form:
        {
            'cat,': 'cat',
            ',cat': 'cat',
        }
         c                 8    h | ]}t          |          d k    |S    len)r   ws     r   	<setcomp>z-SentiText._words_plus_punc.<locals>.<setcomp>#  s#    :::As1vvzzazzzr   c                 F    i | ]}d                      |          |d         S )r   r   joinr   ps     r   
<dictcomp>z.SentiText._words_plus_punc.<locals>.<dictcomp>%  s(    UUUArwwqzz1Q4UUUr   c                 F    i | ]}d                      |          |d         S )r   r   r   r   s     r   r   z.SentiText._words_plus_punc.<locals>.<dictcomp>&  s(    TTT1bggajj!A$TTTr   )r   subr   splitr   r   update)r   no_punc_text
words_onlypunc_before
punc_afterwords_punc_dicts         r   _words_plus_punczSentiText._words_plus_punc  s     488TYGG!''))
:::::
UU1T1TUUUTT
DN0S0STTT
%z***r   c                     | j                                         }|                                 }d |D             }t          |          D ]\  }}||v r||         ||<   |S )z
        Removes leading and trailing puncutation
        Leaves contractions and most emoticons
            Does not preserve punc-plus-letter emoticons (e.g. :D)
        c                 8    g | ]}t          |          d k    |S r   r   )r   wes     r   
<listcomp>z2SentiText._words_and_emoticons.<locals>.<listcomp>3  s#    ///b3r77Q;;r;;;r   )r   r   r   	enumerate)r   wesr   ir   s        r   r   zSentiText._words_and_emoticons+  sq     ioo//11//C///s^^ 	- 	-EAr_$$(,A
r   c                     d}d}|D ]}|                                 r|dz  }t          |          |z
  }d|cxk     rt          |          k     rn nd}|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
        Fr   r   T)r   r   )r   wordsis_differentallcap_wordsr   cap_differentials         r   r   zSentiText.allcap_differential9  s}      	" 	"D||~~ "!u::4,,,,#e**,,,,,Lr   N)r   r   r   r   r   r   r   r   r   r   r   r   r     s]         	N 	N 	N  (      r   r   c                   d    e Zd ZdZ	 ddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd ZdS )SentimentIntensityAnalyzerz8
    Give a sentiment intensity score to sentences.
    ;sentiment/vader_lexicon.zip/vader_lexicon/vader_lexicon.txtc                     t           j                            |          | _        |                                 | _        t                      | _        d S r   )nltkdataloadlexicon_filemake_lex_dictlexiconr   	constants)r   r  s     r   r   z#SentimentIntensityAnalyzer.__init__P  s>     !INN<88))++'))r   c                     i }| j                             d          D ]F}|                                                    d          dd         \  }}t          |          ||<   G|S )z6
        Convert lexicon file to a dictionary
        
	r   r   )r  r   stripfloat)r   lex_dictliner   measures        r   r  z(SentimentIntensityAnalyzer.make_lex_dictX  sg     %++D11 	, 	,D"jjll0066qs;OT7"7^^HTNNr   c                 *   t          || j        j        | j        j                  }g }|j        }|D ]}d}|                    |          }|t          |          dz
  k     r9|                                dk    r!||dz                                            dk    s |                                | j        j        v r|	                    |           | 
                    |||||          }|                     ||          }|                     ||          S )a  
        Return a float for sentiment strength based on the input text.
        Positive values are positive valence, negative value are negative
        valence.

        :note: Hashtags are not taken into consideration (e.g. #BAD is neutral). If you
            are interested in processing the text in the hashtags too, then we recommend
            preprocessing your data to remove the #, after which the hashtag text may be
            matched as if it was a normal word in the sentence.
        r   r   kindof)r   r  r   r   r   indexr   r   r   appendsentiment_valence
_but_checkscore_valence)r   r   	sentitext
sentimentsr   itemr   r   s           r   polarity_scoresz*SentimentIntensityAnalyzer.polarity_scoresb  s    $.*DN,S
 
	 
';' 	Y 	YDG#))$//AC+,,q000JJLLF**'A.4466$>>!<<<!!'***//D!ZXXJJ__%8*EE
!!*d333r   c                    |j         }|j        }|                                }|| j        v r#| j        |         }|                                r'|r%|dk    r|| j        j        z  }n|| j        j        z  }t          dd          D ]}	||	k    r|||	dz   z
                                           | j        vr| j                            |||	dz   z
           ||          }
|	dk    r|
dk    r|
dz  }
|	dk    r|
dk    r|
dz  }
||
z   }| 	                    |||	|          }|	dk    r| 
                    |||          }|                     |||          }|                    |           |S )Nr   r   r   gffffff?r   g?)r   r   r   r  r   r  r   ranger   _never_check_idioms_check_least_checkr  )r   r   r  r  r   r  r   r   item_lowercasestart_iss              r   r  z,SentimentIntensityAnalyzer.sentiment_valence  s   +';T\))l>2G ||~~ 5+ 5Q;;t~44GGt~44G A;; V VKK+A1,=>DDFF<( ( 55+A1,=> A !||QH!||QG%kG"//!4gq G !||"&"4"4W>QST"U"U ''1DaHHG'"""r   c                    |dk    r||dz
                                            | j        vrs||dz
                                            dk    rR||dz
                                            dk    r0||dz
                                            dk    r|| j        j        z  }nZ|dk    rT||dz
                                            | j        vr0||dz
                                            dk    r|| j        j        z  }|S )Nr   r   r   r   ro   r   )r   r  r  r   )r   r   r   r   s       r   r  z'SentimentIntensityAnalyzer._least_check  s     EE#AE*0022$,FF#AE*0022g== $AE*0022d::'A.4466&@@!DN$;;EE#AE*0022$,FF#AE*0022g== 77Gr   c                 
   d |D             }dht          |          z  }|ra|                    t          t          |                              }t	          |          D ]"\  }}||k     r	|dz  ||<   ||k    r|dz  ||<   #|S )Nc                 6    g | ]}|                                 S r   r   )r   w_es     r   r   z9SentimentIntensityAnalyzer._but_check.<locals>.<listcomp>  s     JJJssyy{{JJJr   butg      ?r   )setr  nextiterr   )r   r   r  r%  bisidx	sentiments          r   r  z%SentimentIntensityAnalyzer._but_check  s    JJ6IJJJg/000 	7$**4S		??;;B#,Z#8#8 7 7i"99'03Jt$$BYY'03Jt$r   c                    ||dz
            d||          }d                     ||dz
           ||dz
           ||                   }||dz
            d||dz
            }d                     ||dz
           ||dz
           ||dz
                     }d                     ||dz
           ||dz
                     }|||||g}	|	D ]$}
|
| j        j        v r| j        j        |
         } n%t          |          dz
  |k    r6||          d||dz             }|| j        j        v r| j        j        |         }t          |          dz
  |dz   k    rOd                     ||         ||dz            ||dz                      }|| j        j        v r| j        j        |         }|| j        j        v s|| j        j        v r|| j        j        z   }|S )Nr    z{} {} {}r   r   z{} {})formatr  r   r   r   r   )r   r   r   r   onezero
twoonezerotwoonethreetwoonethreetwo	sequencesseqzeroone
zeroonetwos                r   r  z(SentimentIntensityAnalyzer._idioms_check  s6   (Q/JJ2Ea2HJJ&&A&A&"
 

 (A.MM1DQU1KMM ''A&A&A&
 
 >>A&(;AE(B
 
 j&+xH	 	 	Cdn888.<SA 9 "##a'!++,Q/NN2Ea!e2LNNG$.<<<.<WE"##a'!a%//#**#A&#AE*#AE* J
 T^???.<ZH 333444 55Gr   c                 p   |dk    r3| j                             ||dz
           g          r|| j         j        z  }|dk    ri||dz
           dk    r$||dz
           dk    s||dz
           dk    r|dz  }n6| j                             |||dz   z
           g          r|| j         j        z  }|dk    r||dz
           dk    r||dz
           dk    s-||dz
           dk    s||dz
           dk    s||dz
           dk    r|d	z  }n6| j                             |||dz   z
           g          r|| j         j        z  }|S )
Nr   r   r   r,   rf   thisr   r   g      ?)r  r   r   )r   r   r   r  r   s        r   r  z'SentimentIntensityAnalyzer._never_check  s   a<<~%%':1q5'A&BCC <!DN$;;a<<"1q5)W44#AE*d22&q1u-77!C-'')<Q'A+=N)O(PQQ <!DN$;;a<<#AE*g55'A.$66*1q51V;; (A.$66*1q51V;; "D.'')<Q'A+=N)O(PQQ <!DN$;;r   c                 d    |                      |          }|                     |          }||z   }|S r   )_amplify_ep_amplify_qm)r   sum_sr   ep_amplifierqm_amplifierpunct_emph_amplifiers         r   _punctuation_emphasisz0SentimentIntensityAnalyzer._punctuation_emphasis$  s9    ''--''--+l:##r   c                 J    |                     d          }|dk    rd}|dz  }|S )Nr      g㥛 ?count)r   r   ep_countr>  s       r   r;  z&SentimentIntensityAnalyzer._amplify_ep+  s1    ::c??a<<H  %'r   c                 \    |                     d          }d}|dk    r|dk    r|dz  }nd}|S )Nr   r   r   r   g
ףp=
?gQ?rD  )r   r   qm_countr?  s       r   r<  z&SentimentIntensityAnalyzer._amplify_qm5  s@    ::c??a<<1}}  ($#r   c                     d}d}d}|D ]C}|dk    r|t          |          dz   z  }|dk     r|t          |          dz
  z  }|dk    r|dz  }D|||fS )Nr   r   r   )r	  )r   r  pos_sumneg_sum	neu_countsentiment_scores         r   _sift_sentiment_scoresz1SentimentIntensityAnalyzer._sift_sentiment_scoresB  s    	) 
	 
	O""/**Q. ""/**Q. !##Q	**r   c                    |rt          t          |                    }|                     ||          }|dk    r||z  }n|dk     r||z  }| j                            |          }|                     |          \  }}}|t          j        |          k    r||z  }n|t          j        |          k     r||z  }|t          j        |          z   |z   }	t          j        ||	z            }
t          j        ||	z            }t          j        ||	z            }nd}d}
d}d}t          |d          t          |d          t          |
d          t          |d          d}|S )Nr   r   r   rC  )negneuposcompound)	r	  sumrA  r  r   rN  r   fabsround)r   r  r   r=  r@  rS  rJ  rK  rL  totalrR  rP  rQ  sentiment_dicts                 r   r  z(SentimentIntensityAnalyzer.score_valenceT  s}    	#j//**E#'#=#=eT#J#J qyy----~//66H*.*E*Ej*Q*Q'GWi7++++//49W----//di0009<E)GeO,,C)GeO,,C)I-..CC HCCC a==a==a==h**	
 
 r   N)r   )r   r   r   r   r   r  r  r  r  r  r  r  rA  r;  r<  rN  r  r   r   r   r   r   K  s          S* * * *   4  4  4D0 0 0d  (
 
 
/ / /b  :$ $ $    + + +$% % % % %r   r   )r   r   r   r   	itertoolsr   	nltk.datar   	nltk.utilr   r   r   r   r   r   r   <module>r\     s       				                 c c c c c c c cLA A A A A A A AHn n n n n n n n n nr   