Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-redundant-tree logic for ontodocs #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions ontospy/core/ontospy.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ def nextConcept(self, concepturi):
flag = True
return None

def ontologyClassTree(self):
def ontologyClassTree(self, repeatChildren=True):
"""
Returns a dict representing the ontology tree
Top level = {0:[top classes]}
Expand All @@ -960,12 +960,20 @@ def ontologyClassTree(self):
if self.all_classes:
treedict[0] = self.toplayer_classes
for element in self.all_classes:
if element.children():
treedict[element] = element.children()
if repeatChildren:
if element.children():
treedict[element] = element.children()
else:
treedict[element] = list()
children_set = set(element.children())
for e in element.children():
parents_set = set(e.parents())
if not children_set.intersection(parents_set):
treedict[element].append(e)
return treedict
return treedict

def ontologyPropTree(self):
def ontologyPropTree(self, repeatChildren=True):
"""
Returns a dict representing the ontology tree
Top level = {0:[top properties]}
Expand All @@ -975,12 +983,20 @@ def ontologyPropTree(self):
if self.all_properties:
treedict[0] = self.toplayer_properties
for element in self.all_properties:
if element.children():
treedict[element] = element.children()
if repeatChildren:
if element.children():
treedict[element] = element.children()
else:
treedict[element] = list()
children_set = set(element.children())
for e in element.children():
parents_set = set(e.parents())
if not children_set.intersection(parents_set):
treedict[element].append(e)
return treedict
return treedict

def ontologyConceptTree(self):
def ontologyConceptTree(self, repeatChildren=True):
"""
Returns a dict representing the skos tree
Top level = {0:[top concepts]}
Expand All @@ -990,8 +1006,16 @@ def ontologyConceptTree(self):
if self.all_skos_concepts:
treedict[0] = self.toplayer_skos
for element in self.all_skos_concepts:
if element.children():
treedict[element] = element.children()
if repeatChildren:
if element.children():
treedict[element] = element.children()
else:
treedict[element] = list()
children_set = set(element.children())
for e in element.children():
parents_set = set(e.parents())
if not children_set.intersection(parents_set):
treedict[element].append(e)
return treedict
return treedict

Expand Down