MCPcopy Create free account
hub / github.com/clips/pattern / hyponyms

Method hyponyms

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

Yields a list of semantically more specific synsets, for example: synsets("train")[0].hyponyms() => [Synset("boat train"), Synset("car train"), Synset("freight train"), Synset("hospital train"), Synset("mail train"),

(self, recursive=False, depth=None)

Source from the content-addressed store, hash-verified

204 return [Synset(p.getTarget()) for p in p]
205
206 def hyponyms(self, recursive=False, depth=None):
207 """ Yields a list of semantically more specific synsets, for example:
208 synsets("train")[0].hyponyms() =>
209 [Synset("boat train"),
210 Synset("car train"),
211 Synset("freight train"),
212 Synset("hospital train"),
213 Synset("mail train"),
214 Synset("passenger train"),
215 Synset("streamliner"),
216 Synset("subway train")
217 ]
218 """
219 p = [Synset(p.getTarget()) for p in self._synset.getPointers(wn.HYPONYM)]
220 if depth is None and recursive is False:
221 return p
222 if depth == 0:
223 return []
224 if depth is not None:
225 depth -= 1
226 if depth is None or depth > 0:
227 [p.extend(s.hyponyms(True, depth)) for s in list(p)]
228 return p
229
230 def hypernyms(self, recursive=False, depth=None):
231 """ Yields a list of semantically broader synsets.

Callers 3

_childrenMethod · 0.80
test_synsetMethod · 0.80
06-wordnet.pyFile · 0.80

Calls 4

getTargetMethod · 0.80
SynsetClass · 0.70
getPointersMethod · 0.45
extendMethod · 0.45

Tested by 1

test_synsetMethod · 0.64