Returns all terms of the given semantic type: "quantity" => ["many", "lot", "few", ...] If recursive=True, traverses children down to the leaves.
(self, term, recursive=False, **kwargs)
| 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", ...] |
| 335 | If recursive=True, traverses children down to the leaves. |
| 336 | """ |
| 337 | def dfs(term, recursive=False, visited={}, **kwargs): |
| 338 | if term in visited: # Break on cyclic relations. |
| 339 | return [] |
| 340 | visited[term], a = True, [] |
| 341 | if dict.__contains__(self, term): |
| 342 | a = self[term][1].keys() |
| 343 | for classifier in self.classifiers: |
| 344 | a.extend(classifier.children(term, **kwargs) or []) |
| 345 | if recursive: |
| 346 | for w in a: a += dfs(w, recursive, visited, **kwargs) |
| 347 | return a |
| 348 | return unique(dfs(self._normalize(term), recursive, {}, **kwargs)) |
| 349 | |
| 350 | def value(self, term, **kwargs): |
| 351 | """ Returns the value of the given term ("many" => "50-200") |