'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 __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, u'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 u'    '.join(self.tokenizer(s)).split()), negation)
    elif hasattr(s, u'sentences'):
        a = self.assessments((((w.lemma or w.string.lower()), w.pos[:2]) for w in chain(*s)), negation)
    elif hasattr(s, u'lemmata'):
        a = self.assessments((((w.lemma or w.string.lower()), w.pos[:2]) for w in s.words), negation)
    elif hasattr(s, u'lemma'):
        a = self.assessments((((s.lemma or s.string.lower()), s.pos[:2]),), negation)
    elif hasattr(s, u'terms'):
        a = self.assessments(chain(*(((w, None), (None, None)) for w in s)), negation)
        kwargs.setdefault(u'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(u'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(u'weight', (lambda w: 1))
    return Score(polarity=avg([(w, p) for (w, p, s, x) in a], weight), subjectivity=avg([(w, s) for (w, p, s, x) in a], weight), assessments=a)
