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

Improve relation definitions walk algorithm in CompositeGraph.iter_schema()

Properly walk through relation definitions accounting for parent role and
entity type in iter_schema. Better use Yams API in passing.
parent 338c932c8562
No related branches found
No related tags found
No related merge requests found
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
def iter_schema(self, parent, topdown=True): def iter_schema(self, parent, topdown=True):
"""Yield `(rtype, role), children` values corresponding to arcs of the """Yield `(rtype, role), children` values corresponding to arcs of the
graph of compositely-related entity types reachable from an `parent` graph of compositely-related entity types reachable from an `parent`
entity type. `children` is a set of possible entity types reachable entity type. `children` is a list of possible entity types reachable
through `(rtype, role)` relation. through `(rtype, role)` relation.
By default, the schema is walked from the container level to the By default, the schema is walked from the container level to the
...@@ -80,6 +80,6 @@ ...@@ -80,6 +80,6 @@
eschema = self.schema[parent] eschema = self.schema[parent]
except KeyError: except KeyError:
return return
for rschema, _, role in eschema.relation_definitions(): for rschema, teschemas, role in eschema.relation_definitions():
if rschema.meta or rschema in self.skiprtypes: if rschema.meta or rschema in self.skiprtypes:
continue continue
...@@ -84,4 +84,3 @@ ...@@ -84,4 +84,3 @@
if rschema.meta or rschema in self.skiprtypes: if rschema.meta or rschema in self.skiprtypes:
continue continue
target_role = neg_role(role)
composite_role = role if topdown else neg_role(role) composite_role = role if topdown else neg_role(role)
...@@ -87,5 +86,8 @@ ...@@ -87,5 +86,8 @@
composite_role = role if topdown else neg_role(role) composite_role = role if topdown else neg_role(role)
relation, children = (rschema.type, role), set() relation, children = (rschema.type, role), []
for rdef in rschema.rdefs.itervalues(): for target in teschemas:
if target in self.skipetypes:
continue
rdef = rschema.role_rdef(eschema, target, role)
if rdef.composite != composite_role: if rdef.composite != composite_role:
continue continue
...@@ -90,10 +92,8 @@ ...@@ -90,10 +92,8 @@
if rdef.composite != composite_role: if rdef.composite != composite_role:
continue continue
child = getattr(rdef, target_role).type children.append(target.type)
if child in self.skipetypes: if children:
continue yield relation, children
children.add(child)
yield relation, children
def structure(self, parent, **kwargs): def structure(self, parent, **kwargs):
"""Return a nested-dict structure obtained from walking the graph of """Return a nested-dict structure obtained from walking the graph of
...@@ -112,12 +112,11 @@ ...@@ -112,12 +112,11 @@
An "arc" is a tuple `(child entity, (rtype, role), parent entity)`. An "arc" is a tuple `(child entity, (rtype, role), parent entity)`.
""" """
for (rtype, role), children in self.iter_schema(parent.cw_etype): for (rtype, role), children in self.iter_schema(parent.cw_etype):
for child_etype in children: rset = parent.related(rtype, role=role, targettypes=children)
rset = parent.related(rtype, role=role, targettypes=[child_etype]) for child in rset.entities():
for child in rset.entities(): yield child, (rtype, neg_role(role)), parent
yield child, (rtype, neg_role(role)), parent for x in self.iter_entities(child):
for x in self.iter_entities(child): yield x
yield x
def copy_entity(original, **attributes): def copy_entity(original, **attributes):
......
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