`L idZddlmZddlZddlmZmZmZddlm Z ddl m Z ddl mZGdd eZd ZGd d eZy) z=Sentiment analysis implementations. .. versionadded:: 0.5.0 ) namedtupleN) CONTINUOUSDISCRETEBaseSentimentAnalyzer)requires_nltk_corpus) sentiment) word_tokenizec2eZdZdZeZedddgZddZy)PatternAnalyzera&Sentiment analyzer that uses the same implementation as the pattern library. Returns results as a named tuple of the form: ``Sentiment(polarity, subjectivity, [assessments])`` where [assessments] is a list of the assessed tokens and their polarity and subjectivity scores Sentimentpolarity subjectivityc|r;tdgd}t|j}t|\}}||||Stdddg}|t|S)zyReturn the sentiment as a named tuple of the form: ``Sentiment(polarity, subjectivity, [assessments])``. r )r r assessmentsr r)rpattern_sentimentr)selftextkeep_assessmentsr rr rs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/textblob/en/sentiments.pyanalyzezPatternAnalyzer.analyzesk "HI,D1==K%6t%< "HlX|[A A#;^0LMI/56 6N)F) __name__ __module__ __qualname____doc__rkindr RETURN_TYPErrrr r s& D[:~*FGK7rr c&td|DS)z5Default feature extractor for the NaiveBayesAnalyzer.c3$K|]}|df yw)TNr).0words r z-_default_feature_extractor..2s/t /s)dict)wordss r_default_feature_extractorr&0s // //rc^eZdZdZeZedgdZeffd Z e fdZ fdZ xZ S)NaiveBayesAnalyzera!Naive Bayes analyzer that is trained on a dataset of movie reviews. Returns results as a named tuple of the form: ``Sentiment(classification, p_pos, p_neg)`` :param callable feature_extractor: Function that returns a dictionary of features, given a list of words. r classificationp_posp_negc>t|d|_||_y)N)super__init__ _classifierfeature_extractor)rr1 __class__s rr/zNaiveBayesAnalyzer.__init__Bs !2rcdt|tjjj d}tjjj d}|Dcgc]>}|j tjjj|gdf@}}|Dcgc]>}|j tjjj|gdf@}}||z}tjjj||_ ycc}wcc}w)z.es =!Q1AGGI=s++r5r4r)) r.rr r1r0 prob_classifyrmaxprob)rrtokensfilteredfeats prob_distr2s rrzNaiveBayesAnalyzer.analyze^s t%8=v=&&x0$$2259 $==?..'..'   r)rrrrrrrrr&r/rr7r __classcell__)r2s@rr(r(5sD D[*NOK)C3 PP,  rr()r collectionsrr8 textblob.baserrrtextblob.decoratorsr textblob.enrrtextblob.tokenizersr r r&r(rrrrWsA# EE46-7+7B0 7 .7 r