diff --git a/entities.py b/entities.py index 12bde733d7b204c2c8384bb97883ed55e5cb3eec_ZW50aXRpZXMucHk=..db7398f9e83b5554a6b88d55e0f6706eaae7a90d_ZW50aXRpZXMucHk= 100644 --- a/entities.py +++ b/entities.py @@ -138,49 +138,6 @@ update_structure(left, relation, right) return structure - def topdown_definition(self, parent): - """Return the container definition of the composite graph from - `parent` entity. - - This "definition" is a dictionary mapping entity types of the - composite graph reachable from `parent` entity type to a set of - `(rtype, role)` where `role` refers to the upstream entity type in - `rtype` relation walking towards the top-level `parent` entity type. - """ - return self._definition(parent, True) - - def bottomup_definition(self, parent): - """Return the container definition of the composite graph from - `parent` entity. - - This "definition" is a dictionary mapping entity types of the - composite graph reachable from `parent` entity type to a set of - `(rtype, role)` where `role` refers to the downstream entity type in - `rtype` relation walking downwards from the top-level `parent` entity - type. - """ - return self._definition(parent, False) - - def _definition(self, parent, topdown, _visited=None): - """Return a dict {etype: [(rtype, role)]} with structural relations of - the composite graph starting from `parent` entity type and walking the - graph either downstream or upstream depending on `topdown` being True - or False. - """ - if _visited is None: - _visited = set() - defn = {} - for (rtype, role), children in self.child_relations(parent): - for child in sorted(children): - defn.setdefault(child, set()).add((rtype, role if topdown else neg_role(role))) - if child in _visited: - continue - _visited.add(child) - for etype, relations in self._definition( - child, topdown, _visited=_visited).iteritems(): - defn.setdefault(etype, set()).update(relations) - return defn - def parent_related(self, entity): """Yield information items on entities related to `entity` through composite relations walking the graph upstream from `entity`. @@ -397,7 +354,8 @@ parent (which may be the container or a contained). """ graph = CompositeGraph(schema, skiprtypes=skiprtypes, skipetypes=skipetypes) - return graph.bottomup_definition(etype) + return dict((child, set(relinfo)) + for child, relinfo in graph.parent_structure(etype).iteritems()) @skip_meta diff --git a/test/test_compound.py b/test/test_compound.py index 12bde733d7b204c2c8384bb97883ed55e5cb3eec_dGVzdC90ZXN0X2NvbXBvdW5kLnB5..db7398f9e83b5554a6b88d55e0f6706eaae7a90d_dGVzdC90ZXN0X2NvbXBvdW5kLnB5 100644 --- a/test/test_compound.py +++ b/test/test_compound.py @@ -92,28 +92,6 @@ structure = graph.parent_structure('OnlineAccount') self.assertEqual(structure, {}) - def test_topdown_definition(self): - graph = CompositeGraph(self.schema) - defn = sort_keys(graph.topdown_definition('Agent')) - expected = { - 'OnlineAccount': [('account', 'subject')], - 'Biography': [('biography', 'subject')], - 'Event': [('event', 'subject'), ('relates', 'subject')], - 'Anecdote': [('event', 'subject'), ('narrated_by', 'object')], - } - self.assertEqual(defn, expected) - - def test_bottomup_definition(self): - graph = CompositeGraph(self.schema) - defn = sort_keys(graph.bottomup_definition('Agent')) - expected = { - 'OnlineAccount': [('account', 'object')], - 'Biography': [('biography', 'object')], - 'Event': [('event', 'object'), ('relates', 'object')], - 'Anecdote': [('event', 'object'), ('narrated_by', 'subject')], - } - self.assertEqual(defn, expected) - def test_parent_related_singleton(self): graph = CompositeGraph(self.schema) with self.admin_access.repo_cnx() as cnx: