Skip to content
Snippets Groups Projects
Commit db7398f9e83b authored by Denis Laxalde's avatar Denis Laxalde
Browse files

Drop {topdown,bottomup}_definition methods and use parent_structure instead

parent 12bde733d7b2
No related branches found
Tags 0.3.0 centos/0.3.0-1 debian/0.3.0-1
No related merge requests found
......@@ -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
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment