User:Manetta/scripts/pattern-sentiment-analysis

From XPUB & Lens-Based wiki
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