Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compound
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cubicweb
cubes
compound
Commits
db7398f9e83b
Commit
db7398f9e83b
authored
9 years ago
by
Denis Laxalde
Browse files
Options
Downloads
Patches
Plain Diff
Drop {topdown,bottomup}_definition methods and use parent_structure instead
parent
12bde733d7b2
No related branches found
Branches containing commit
Tags
0.3.0
centos/0.3.0-1
debian/0.3.0-1
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
entities.py
+2
-44
2 additions, 44 deletions
entities.py
test/test_compound.py
+0
-22
0 additions, 22 deletions
test/test_compound.py
with
2 additions
and
66 deletions
entities.py
+
2
−
44
View file @
db7398f9
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
test/test_compound.py
+
0
−
22
View file @
db7398f9
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment