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

Class Synset

pattern/text/en/wordnet/__init__.py:112–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110 return []
111
112class 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 """

Callers 8

synsetsFunction · 0.70
antonymMethod · 0.70
meronymsMethod · 0.70
holonymsMethod · 0.70
hyponymsMethod · 0.70
hypernymsMethod · 0.70
hypernymMethod · 0.70
similarMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…