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)
| 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. |