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

Conversation

floatingpurr
Copy link

@floatingpurr floatingpurr commented Jul 30, 2019

Hello Michele (a.k.a. @lambdamusic). Please, consider the integration of this PR into Ontospy.

In a nutshell

This PR allows the generation of ontologyClassTrees, ontologyPropTrees, ontologyConceptTrees without repeating redundant sub-entities along the hierarchy. It display a "distinct" taxonomy without repetitions. Multi-inheritance (i.e., a class inheriting from diverse classes) is preserved.

Application

Useful when you need to represent trees of full reasoned ontologies (e.g., when you load the ontology from the SPARQL endpoint of Ontotext's GraphDB with reasoning enabled). In those cases new implicit triples are inferred and added to the knowledge graph (e.g., due to the transitivity of properties like rdfs:subClassOf) but you might not want to visualize all implicit sub-*-classes relations in the ontodocs trees.

Rationale

Rule introduced:

  • add a child c to an entity e iif (i) c is a child of e and (ii) parents of e are not childern of c.

Full story

Let's start from this ontology

@prefix : <http://theRed-beardedOntology#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .


#################################################################
#    Classes
#################################################################


:Mammal rdf:type owl:Class .

:Human rdf:type owl:Class ;
       rdfs:subClassOf :Mammal .

:Red-beardedGuy rdf:type owl:Class ;
                rdfs:subClassOf :Human .

:Mammal is subclassed by :Human that is subclassed by :Red-beardedGuy. If this ontology is reasoned with common rulesets, the following triple is materialized:

:Red-beardedGuy rdfs:subClassOf :Mammal .

Now, if we call the legacy version of ontologyClassTrees, we would get this tree in the ontology doc:

http://theRed-beardedOntology#Mammal
|       http://theRed-beardedOntology#Human
|       |        http://theRed-beardedOntology#Red-beardedGuy
|       http://theRed-beardedOntology#Red-beardedGuy

...and it's perfectly fine. Indeed, :Red-beardedGuy is a sub-class both of :Mammal and of :Human. However, this representation could be pretty redundant for some uses. A kind of "distinct" taxonomy like this one is desirable:

http://theRed-beardedOntology#Mammal
|       http://theRed-beardedOntology#Human
|       |        http://theRed-beardedOntology#Red-beardedGuy

and it makes much more sense to the reader. : )

To get this, I introduced the arg repeatChildren in the tree methods of the class Ontospy (it defaults to True for backward compatibility). It repeatChildren is set to False, you get the non-redundant tree version.

Let me know your reactions as you go through it.

Ciao Michele e grazie per questo bel lavoro che metti a disposizione qui su GitHub!

@lambdamusic
Copy link
Owner

Hello Andrea this looks very useful. I will review a bit more before merging.
PS Massive apologies for the abysmal delay in getting back to you!

@floatingpurr
Copy link
Author

Hey Michele, no worries at all. This is just a little contribution. I really enjoyed working with this library!

@jonassmedegaard
Copy link

Any progress in getting this nice looking PR accepted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants