User:Manetta/scripts/pattern-sentiment-analysis

From XPUB & Lens-Based wiki
< User:Manetta
Revision as of 11:00, 24 March 2015 by Manetta (talk | contribs) (Created page with "<source lang="python"> from pattern.en import sentiment from pattern.en import parse, Sentence, parse from pattern.en import modality, mood txt = "Julie thought that she had...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
from pattern.en import sentiment
from pattern.en import parse, Sentence, parse
from pattern.en import modality, mood

txt = "Julie thought that she had some chocolate and she is standing next to me. I wish i had chocolate too!"

print "polarity + subjectivity: ",sentiment(txt)
# returns polarity, subjectivity
# polarity is the average of the adjectives in the txt
# polarity ???

print "individual polarity + subjectivity + label: ",sentiment(txt).assessments 
# returns polarity, subjectivity, label (WordNet?)
# of the individual words in txt

txt = parse(txt, lemmata=True)
txt = Sentence(txt)

print "mood: ",mood(txt)
# returns INDICATIVE | IMPERATIVE | CONDITIONAL | SUBJUNCTIVE

print "certainty: ",modality(txt)
# returns the degree of certainty, in values between -1.0 => +1.0
# values > +0.5 represent facts


polarity + subjectivity:  (0.0, 0.0)
individual polarity + subjectivity + label:  [(['next', '!'], 0.0, 0.0, None)]
mood:  subjunctive
certainty:  0.15