Returns a list of all semantic types for the given term. If recursive=True, traverses parents up to the root.
(self, term, recursive=False, **kwargs)
| 314 | return v[0] |
| 315 | |
| 316 | def parents(self, term, recursive=False, **kwargs): |
| 317 | """ Returns a list of all semantic types for the given term. |
| 318 | If recursive=True, traverses parents up to the root. |
| 319 | """ |
| 320 | def dfs(term, recursive=False, visited={}, **kwargs): |
| 321 | if term in visited: # Break on cyclic relations. |
| 322 | return [] |
| 323 | visited[term], a = True, [] |
| 324 | if dict.__contains__(self, term): |
| 325 | a = self[term][0].keys() |
| 326 | for classifier in self.classifiers: |
| 327 | a.extend(classifier.parents(term, **kwargs) or []) |
| 328 | if recursive: |
| 329 | for w in a: a += dfs(w, recursive, visited, **kwargs) |
| 330 | return a |
| 331 | return unique(dfs(self._normalize(term), recursive, {}, **kwargs)) |
| 332 | |
| 333 | def children(self, term, recursive=False, **kwargs): |
| 334 | """ Returns all terms of the given semantic type: "quantity" => ["many", "lot", "few", ...] |