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

Method parents

pattern/text/search.py:316–331  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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", ...]

Callers 7

removeMethod · 0.95
test_taxonomyMethod · 0.95
__contains__Method · 0.80
classifyMethod · 0.80
dfsMethod · 0.80
matchMethod · 0.80
04-taxonomy.pyFile · 0.80

Calls 2

_normalizeMethod · 0.95
uniqueFunction · 0.70

Tested by 1

test_taxonomyMethod · 0.76