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

Method children

pattern/text/search.py:333–348  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 4

test_taxonomyMethod · 0.95
__contains__Method · 0.45
dfsMethod · 0.45

Calls 2

_normalizeMethod · 0.95
uniqueFunction · 0.70

Tested by 2

test_taxonomyMethod · 0.76