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

Method taxonomy

pattern/graph/commonsense.py:190–203  ·  view source on GitHub ↗

Returns a list of concepts that are descendants of the given concept, using "is-a" relations. Creates a subgraph of "is-a" related concepts up to the given depth, then takes the fringe (i.e., leaves) of the subgraph.

(self, concept, depth=3, fringe=2)

Source from the content-addressed store, hash-verified

188 similar = neighbors = nn = nearest_neighbors
189
190 def taxonomy(self, concept, depth=3, fringe=2):
191 """ Returns a list of concepts that are descendants of the given concept, using "is-a" relations.
192 Creates a subgraph of "is-a" related concepts up to the given depth,
193 then takes the fringe (i.e., leaves) of the subgraph.
194 """
195 def traversable(node, edge):
196 # Follow parent-child edges.
197 return edge.node2 == node and edge.type == "is-a"
198 if not isinstance(concept, Node):
199 concept = self[concept]
200 g = self.copy(nodes=concept.flatten(depth, traversable))
201 g = g.fringe(depth=fringe)
202 g = [self[n.id] for n in g if n != concept]
203 return g
204
205 field = semantic_field = taxonomy
206

Callers

nothing calls this directly

Calls 3

fringeMethod · 0.80
copyMethod · 0.45
flattenMethod · 0.45

Tested by

no test coverage detected