| 110 | return [] |
| 111 | |
| 112 | class Synset(object): |
| 113 | |
| 114 | def __init__(self, synset=None, pos=NOUN): |
| 115 | """ A set of synonyms that share a common meaning. |
| 116 | """ |
| 117 | if isinstance(synset, int): |
| 118 | synset = wn.getSynset({NN: "n", VB: "v", JJ: "adj", RB: "adv"}[pos], synset) |
| 119 | if isinstance(synset, basestring): |
| 120 | synset = synsets(synset, pos)[0]._synset |
| 121 | self._synset = synset |
| 122 | |
| 123 | def __iter__(self): |
| 124 | for s in self._synset.getSenses(): yield s.form |
| 125 | def __len__(self): |
| 126 | return len(self._synset.getSenses()) |
| 127 | def __getitem__(self, i): |
| 128 | return self._synset.getSenses()[i].form |
| 129 | def __eq__(self, synset): |
| 130 | return isinstance(synset, Synset) and self.id == synset.id |
| 131 | def __ne__(self, synset): |
| 132 | return not self.__eq__(synset) |
| 133 | def __repr__(self): |
| 134 | return "Synset(%s)" % repr(self[0]) |
| 135 | |
| 136 | @property |
| 137 | def id(self): |
| 138 | return self._synset.offset |
| 139 | |
| 140 | @property |
| 141 | def pos(self): |
| 142 | """ Yields the part-of-speech tag (NOUN, VERB, ADJECTIVE or ADVERB). |
| 143 | """ |
| 144 | pos = self._synset.pos |
| 145 | if pos == "noun": |
| 146 | return NOUN |
| 147 | if pos == "verb": |
| 148 | return VERB |
| 149 | if pos == "adjective": |
| 150 | return ADJECTIVE |
| 151 | if pos == "adverb": |
| 152 | return ADVERB |
| 153 | |
| 154 | part_of_speech = tag = pos |
| 155 | |
| 156 | @property |
| 157 | def synonyms(self): |
| 158 | """ Yields a list of word forms (i.e. synonyms), for example: |
| 159 | synsets("TV")[0].synonyms => ["television", "telecasting", "TV", "video"] |
| 160 | """ |
| 161 | return [s.form for s in self._synset.getSenses()] |
| 162 | |
| 163 | senses = synonyms # Backwards compatibility; senses = list of Synsets for a word. |
| 164 | |
| 165 | @property |
| 166 | def gloss(self): |
| 167 | """ Yields a descriptive string, for example: |
| 168 | synsets("glass")[0].gloss => "a brittle transparent solid with irregular atomic structure". |
| 169 | """ |
no outgoing calls
no test coverage detected
searching dependent graphs…