Returns the IC value for the given Synset (trained on the Brown corpus).
(synset)
| 309 | IC_MAX = 0 |
| 310 | |
| 311 | def information_content(synset): |
| 312 | """ Returns the IC value for the given Synset (trained on the Brown corpus). |
| 313 | """ |
| 314 | global IC_MAX |
| 315 | if not IC: |
| 316 | IC[NOUN] = {} |
| 317 | IC[VERB] = {} |
| 318 | for s in open(IC_CORPUS).readlines()[1:]: # Skip the header. |
| 319 | s = s.split() |
| 320 | id, w, pos = ( |
| 321 | int(s[0][:-1]), |
| 322 | float(s[1]), |
| 323 | s[0][-1] == "n" and NOUN or VERB) |
| 324 | if len(s) == 3 and s[2] == "ROOT": |
| 325 | IC[pos][0] = IC[pos].get(0,0) + w |
| 326 | if w != 0: |
| 327 | IC[pos][id] = w |
| 328 | if w > IC_MAX: |
| 329 | IC_MAX = w |
| 330 | return IC.get(synset.pos, {}).get(synset.id, 0.0) |
| 331 | |
| 332 | ### WORDNET3 TO WORDNET2 ########################################################################### |
| 333 | # Map WordNet3 synset id's to WordNet2 synset id's. |