def __call__(self, s, negation=True, **kwargs):
        """ Returns a (polarity, subjectivity)-tuple for the given sentence,
            with polarity between -1.0 and 1.0 and subjectivity between 0.0 and 1.0.
            The sentence can be a string, Synset, Text, Sentence, Chunk, Word, Document, Vector.
            An optional weight parameter can be given,
            as a function that takes a list of words and returns a weight.
        """
        def avg(assessments, weighted=lambda w: 1):
            s, n = 0, 0
            for words, score in assessments:
                w = weighted(words)
                s += w * score
                n += w
            return s / float(n or 1)
        # A pattern.en.wordnet.Synset.
        # Sentiment(synsets("horrible", "JJ")[0]) => (-0.6, 1.0)
        if hasattr(s, "gloss"):
            a = [(s.synonyms[0],) + self.synset(s.id, pos=s.pos) + (None,)]
        # A synset id.
        # Sentiment("a-00193480") => horrible => (-0.6, 1.0)   (English WordNet)
        # Sentiment("c_267") => verschrikkelijk => (-0.9, 1.0) (Dutch Cornetto)
        elif isinstance(s, basestring) and RE_SYNSET.match(s):
            a = [(s.synonyms[0],) + self.synset(s.id, pos=s.pos) + (None,)]
        # A string of words.
        # Sentiment("a horrible movie") => (-0.6, 1.0)
        elif isinstance(s, basestring):
            a = self.assessments(((w.lower(), None) for w in " ".join(self.tokenizer(s)).split()), negation)
        # A pattern.en.Text.
        elif hasattr(s, "sentences"):
            a = self.assessments(((w.lemma or w.string.lower(), w.pos[:2]) for w in chain(*s)), negation)
        # A pattern.en.Sentence or pattern.en.Chunk.
        elif hasattr(s, "lemmata"):
            a = self.assessments(((w.lemma or w.string.lower(), w.pos[:2]) for w in s.words), negation)
        # A pattern.en.Word.
        elif hasattr(s, "lemma"):
            a = self.assessments(((s.lemma or s.string.lower(), s.pos[:2]),), negation)
        # A pattern.vector.Document.
        # Average score = weighted average using feature weights.
        # Bag-of words is unordered: inject None between each two words
        # to stop assessments() from scanning for preceding negation & modifiers.
        elif hasattr(s, "terms"):
            a = self.assessments(chain(*(((w, None), (None, None)) for w in s)), negation)
            kwargs.setdefault("weight", lambda w: s.terms[w[0]])
        # A dict of (word, weight)-items.
        elif isinstance(s, dict):
            a = self.assessments(chain(*(((w, None), (None, None)) for w in s)), negation)
            kwargs.setdefault("weight", lambda w: s[w[0]])
        # A list of words.
        elif isinstance(s, list):
            a = self.assessments(((w, None) for w in s), negation)
        else:
            a = []
        weight = kwargs.get("weight", lambda w: 1)
        # Each "w" in "a" is a (words, polarity, subjectivity, label)-tuple.
        return Score(polarity = avg(map(lambda w: (w[0], w[1]), a), weight),
                 subjectivity = avg(map(lambda w: (w[0], w[2]), a), weight),
                  assessments = a)
def __call__ ( self , s , negation = True , ** kwargs ) : def avg ( assessments , weighted = lambda w : 1 ) : s , n = 0 , 0 for words , score in assessments : w = weighted ( words ) s += w * score n += w return s / float ( n or 1 ) if hasattr ( s , "gloss" ) : a = [ ( s . synonyms [ 0 ] , ) + self . synset ( s . id , pos = s . pos ) + ( None , ) ] elif isinstance ( s , basestring ) and RE_SYNSET . match ( s ) : a = [ ( s . synonyms [ 0 ] , ) + self . synset ( s . id , pos = s . pos ) + ( None , ) ] elif isinstance ( s , basestring ) : a = self . assessments ( ( ( w . lower ( ) , None ) for w in " " . join ( self . tokenizer ( s ) ) . split ( ) ) , negation ) elif hasattr ( s , "sentences" ) : a = self . assessments ( ( ( w . lemma or w . string . lower ( ) , w . pos [ : 2 ] ) for w in chain ( * s ) ) , negation ) elif hasattr ( s , "lemmata" ) : a = self . assessments ( ( ( w . lemma or w . string . lower ( ) , w . pos [ : 2 ] ) for w in s . words ) , negation ) elif hasattr ( s , "lemma" ) : a = self . assessments ( ( ( s . lemma or s . string . lower ( ) , s . pos [ : 2 ] ) , ) , negation ) elif hasattr ( s , "terms" ) : a = self . assessments ( chain ( * ( ( ( w , None ) , ( None , None ) ) for w in s ) ) , negation ) kwargs . setdefault ( "weight" , lambda w : s . terms [ w [ 0 ] ] ) elif isinstance ( s , dict ) : a = self . assessments ( chain ( * ( ( ( w , None ) , ( None , None ) ) for w in s ) ) , negation ) kwargs . setdefault ( "weight" , lambda w : s [ w [ 0 ] ] ) elif isinstance ( s , list ) : a = self . assessments ( ( ( w , None ) for w in s ) , negation ) else : a = [ ] weight = kwargs . get ( "weight" , lambda w : 1 ) return Score ( polarity = avg ( map ( lambda w : ( w [ 0 ] , w [ 1 ] ) , a ) , weight ) , subjectivity = avg ( map ( lambda w : ( w [ 0 ] , w [ 2 ] ) , a ) , weight ) , assessments = a )
Returns a (polarity, subjectivity)-tuple for the given sentence,
            with polarity between -1.0 and 1.0 and subjectivity between 0.0 and 1.0.
            The sentence can be a string, Synset, Text, Sentence, Chunk, Word, Document, Vector.
            An optional weight parameter can be given,
            as a function that takes a list of words and returns a weight.