MCPcopy Index your code
hub / github.com/clips/pattern / load

Method load

pattern/text/__init__.py:1530–1564  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1528 return self._confidence
1529
1530 def load(self):
1531 # <word form="great" wordnet_id="a-01123879" pos="JJ" polarity="1.0" subjectivity="1.0" intensity="1.0" />
1532 if not os.path.exists(self._path):
1533 return
1534 words, synsets = {}, {}
1535 xml = cElementTree.parse(self._path)
1536 xml = xml.getroot()
1537 for w in xml.findall("word"):
1538 if self._confidence is None \
1539 or self._confidence <= float(w.attrib.get("confidence", 0.0)):
1540 w, pos, p, s, i, synset = (
1541 w.attrib.get("form"),
1542 w.attrib.get("pos"),
1543 w.attrib.get("polarity", 0.0),
1544 w.attrib.get("subjectivity", 0.0),
1545 w.attrib.get("intensity", 1.0),
1546 w.attrib.get(self._synset) # wordnet_id, cornetto_id, ...
1547 )
1548 psi = (float(p), float(s), float(i))
1549 if w:
1550 words.setdefault(w, {}).setdefault(pos, []).append(psi)
1551 if synset:
1552 synsets.setdefault(synset, []).append(psi)
1553 self._language = xml.attrib.get("language", self._language)
1554 # Average scores of all word senses per part-of-speech tag.
1555 for w in words:
1556 words[w] = dict((pos, map(avg, zip(*psi))) for pos, psi in words[w].items())
1557 # Average scores of all part-of-speech tags.
1558 for w, pos in words.items():
1559 words[w][None] = map(avg, zip(*pos.values()))
1560 # Average scores of all synonyms per synset.
1561 for id, psi in synsets.items():
1562 synsets[id] = map(avg, zip(*psi))
1563 dict.update(self, words)
1564 dict.update(self._synsets, synsets)
1565
1566 def synset(self, id, pos=ADJECTIVE):
1567 """ Returns a (polarity, subjectivity)-tuple for the given synset id.

Callers 1

synsetMethod · 0.95

Calls 9

zipFunction · 0.85
existsMethod · 0.80
parseMethod · 0.45
getMethod · 0.45
appendMethod · 0.45
setdefaultMethod · 0.45
itemsMethod · 0.45
valuesMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected