def load(self, path=None):
        """ Loads the XML-file (with sentiment annotations) from the given path.
            By default, Sentiment.path is lazily loaded.
        """
        # <word form="great" wordnet_id="a-01123879" pos="JJ" polarity="1.0" subjectivity="1.0" intensity="1.0" />
        # <word form="damnmit" polarity="-0.75" subjectivity="1.0" label="profanity" />
        if not path:
            path = self._path
        if not os.path.exists(path):
            return
        words, synsets, labels = {}, {}, {}
        xml = cElementTree.parse(path)
        xml = xml.getroot()
        for w in xml.findall("word"):
            if self._confidence is None \
            or self._confidence <= float(w.attrib.get("confidence", 0.0)):
                w, pos, p, s, i, label, synset = (
                    w.attrib.get("form"),
                    w.attrib.get("pos"),
                    w.attrib.get("polarity", 0.0),
                    w.attrib.get("subjectivity", 0.0),
                    w.attrib.get("intensity", 1.0),
                    w.attrib.get("label"),
                    w.attrib.get(self._synset) # wordnet_id, cornetto_id, ...
                )
                psi = (float(p), float(s), float(i))
                if w:
                    words.setdefault(w, {}).setdefault(pos, []).append(psi)
                if w and label:
                    labels[w] = label
                if synset:
                    synsets.setdefault(synset, []).append(psi)
        self._language = xml.attrib.get("language", self._language)
        # Average scores of all word senses per part-of-speech tag.
        for w in words:
            words[w] = dict((pos, [avg(each) for each in zip(*psi)]) for pos, psi in words[w].items())
        # Average scores of all part-of-speech tags.
        for w, pos in list(words.items()):
            words[w][None] = [avg(each) for each in zip(*pos.values())]
        # Average scores of all synonyms per synset.
        for id, psi in synsets.items():
            synsets[id] = [avg(each) for each in zip(*psi)]
        dict.update(self, words)
        dict.update(self.labeler, labels)
        dict.update(self._synsets, synsets)
def load ( self , path = None ) : if not path : path = self . _path if not os . path . exists ( path ) : return words , synsets , labels = { } , { } , { } xml = cElementTree . parse ( path ) xml = xml . getroot ( ) for w in xml . findall ( "word" ) : if self . _confidence is None or self . _confidence <= float ( w . attrib . get ( "confidence" , 0.0 ) ) : w , pos , p , s , i , label , synset = ( w . attrib . get ( "form" ) , w . attrib . get ( "pos" ) , w . attrib . get ( "polarity" , 0.0 ) , w . attrib . get ( "subjectivity" , 0.0 ) , w . attrib . get ( "intensity" , 1.0 ) , w . attrib . get ( "label" ) , w . attrib . get ( self . _synset ) ) psi = ( float ( p ) , float ( s ) , float ( i ) ) if w : words . setdefault ( w , { } ) . setdefault ( pos , [ ] ) . append ( psi ) if w and label : labels [ w ] = label if synset : synsets . setdefault ( synset , [ ] ) . append ( psi ) self . _language = xml . attrib . get ( "language" , self . _language ) for w in words : words [ w ] = dict ( ( pos , [ avg ( each ) for each in zip ( * psi ) ] ) for pos , psi in words [ w ] . items ( ) ) for w , pos in list ( words . items ( ) ) : words [ w ] [ None ] = [ avg ( each ) for each in zip ( * pos . values ( ) ) ] for id , psi in synsets . items ( ) : synsets [ id ] = [ avg ( each ) for each in zip ( * psi ) ] dict . update ( self , words ) dict . update ( self . labeler , labels ) dict . update ( self . _synsets , synsets )
Loads the XML-file (with sentiment annotations) from the given path.
            By default, Sentiment.path is lazily loaded.