flexible export with selection based on parent concepts
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3605 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
c78bef8ec0
commit
3b08ca8346
1 changed files with 24 additions and 35 deletions
59
external/base.py
vendored
59
external/base.py
vendored
|
@ -152,47 +152,36 @@ class Extractor(Base):
|
||||||
|
|
||||||
def extractForParents(self, parents, predicates=None,
|
def extractForParents(self, parents, predicates=None,
|
||||||
includeSubconcepts=False, includeResources=False):
|
includeSubconcepts=False, includeResources=False):
|
||||||
checked = set()
|
concepts = set(parents)
|
||||||
children = set()
|
|
||||||
resources = set()
|
|
||||||
for p in parents:
|
for p in parents:
|
||||||
yield self.getConceptElement(getName(p), p)
|
self.collectConcepts(p, predicates, includeSubconcepts, concepts)
|
||||||
for elem in self._extractForParents(parents, predicates,
|
conceptList = sorted(concepts, key=lambda x:
|
||||||
includeSubconcepts, includeResources,
|
(x.conceptType != self.typeConcept, getName(x)))
|
||||||
checked, children, resources):
|
for c in conceptList:
|
||||||
yield elem
|
yield self.getConceptElement(getName(c), c)
|
||||||
allConcepts = checked.union(children)
|
for c in conceptList:
|
||||||
for c in allConcepts:
|
|
||||||
for r in c.getChildRelations(predicates):
|
for r in c.getChildRelations(predicates):
|
||||||
if r.predicate != self.typePredicate and r.second in children:
|
if r.predicate != self.typePredicate and r.second in concepts:
|
||||||
yield self.getChildElement(r)
|
yield self.getChildElement(r)
|
||||||
for c in allConcepts:
|
if includeResources:
|
||||||
for r in c.getResourceRelations(predicates):
|
resources = set()
|
||||||
if r.predicate != self.typePredicate and r.second in resources:
|
for c in conceptList:
|
||||||
yield self.getResourceRelationElement(r)
|
for obj in c.getResources(predicates):
|
||||||
|
|
||||||
def _extractForParents(self, parents, predicates,
|
|
||||||
includeSubconcepts, includeResources,
|
|
||||||
checked, children, resources):
|
|
||||||
for p in parents:
|
|
||||||
if p in checked:
|
|
||||||
continue
|
|
||||||
checked.add(p)
|
|
||||||
ch = p.getChildren(predicates)
|
|
||||||
for obj in ch:
|
|
||||||
if obj not in children:
|
|
||||||
children.add(obj)
|
|
||||||
yield self.getConceptElement(getName(obj), obj)
|
|
||||||
if includeSubconcepts:
|
|
||||||
for elem in self._extractForParents(ch, predicates,
|
|
||||||
includeSubconcepts, includeResources,
|
|
||||||
checked, children, resources):
|
|
||||||
yield elem
|
|
||||||
if includeResources:
|
|
||||||
for obj in p.getResources(predicates):
|
|
||||||
if obj not in resources:
|
if obj not in resources:
|
||||||
resources.add(obj)
|
resources.add(obj)
|
||||||
yield self.getResourceElement(getName(obj), obj)
|
yield self.getResourceElement(getName(obj), obj)
|
||||||
|
for c in conceptList:
|
||||||
|
for r in c.getResourceRelations(predicates):
|
||||||
|
if r.predicate != self.typePredicate and r.second in resources:
|
||||||
|
yield self.getResourceRelationElement(r)
|
||||||
|
|
||||||
|
def collectConcepts(self, concept, predicates, includeSubconcepts, concepts):
|
||||||
|
for obj in concept.getChildren(predicates):
|
||||||
|
if obj not in concepts:
|
||||||
|
concepts.add(obj)
|
||||||
|
if includeSubconcepts:
|
||||||
|
self.collectConcepts(obj, predicates, includeSubconcepts,
|
||||||
|
concepts)
|
||||||
|
|
||||||
# helper methods
|
# helper methods
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue