Returns a list of Synset objects, one for each word sense. Each word can be understood in different "senses", each of which is part of a set of synonyms (= Synset).
(word, pos=NOUN)
| 88 | "NN", "VB", "JJ", "RB" |
| 89 | |
| 90 | def synsets(word, pos=NOUN): |
| 91 | """ Returns a list of Synset objects, one for each word sense. |
| 92 | Each word can be understood in different "senses", |
| 93 | each of which is part of a set of synonyms (= Synset). |
| 94 | """ |
| 95 | word, pos = normalize(word), pos.lower() |
| 96 | try: |
| 97 | if pos.startswith(NOUN.lower()): # "NNS" or "nn" will also pass. |
| 98 | w = wn.N[word] |
| 99 | elif pos.startswith(VERB.lower()): |
| 100 | w = wn.V[word] |
| 101 | elif pos.startswith(ADJECTIVE.lower()): |
| 102 | w = wn.ADJ[word] |
| 103 | elif pos.startswith(ADVERB.lower()): |
| 104 | w = wn.ADV[word] |
| 105 | else: |
| 106 | raise TypeError, "part of speech must be NOUN, VERB, ADJECTIVE or ADVERB, not %s" % repr(pos) |
| 107 | return [Synset(s.synset) for i, s in enumerate(w)] |
| 108 | except KeyError: |
| 109 | return [] |
| 110 | return [] |
| 111 | |
| 112 | class Synset(object): |
| 113 |