sparna-git / Sparnatural

Sparnatural : visual SPARQL query builder for knowledge graphs in the browser, configurable with SHACL
http://sparnatural.eu
GNU Lesser General Public License v3.0
219 stars 41 forks source link

Navigating rdfs:subClassOf hierarchies to find individuals #494

Closed prashydee closed 1 year ago

prashydee commented 1 year ago

Hi @tfrancart,

I would like to be able to use subClassOf hierarchies to drill-down through classes before retrieving the corresponding individuals. The tree-selector seems to be tuned for skos:narrower / skos:broader trees. Could this also work for rdfs:subClassOf hierarchies? Ideally this would be nice to achieve in the selection of the starting class too. Is this yet possible?

Kind Regards, Prashant

Marie-Sparna commented 1 year ago

Hello Prashant,

as we understand your issue, we have two different subjects :

1) It isn't possible for the moment being to drill-down through classes from the selection of the starting class (even if we've already an issue about it here cf https://github.com/sparna-git/Sparnatural/issues/351).

2) But still possible to tune the tree-selector following your structure. You'll find a few indications to do so in the documentation here : https://docs.sparnatural.eu/OWL-based-configuration-datasources.html#your-own-sparql-query-tree. Not sure it matches your need, but do tell us !

Best, Marie

tfrancart commented 1 year ago

TreeWidget can be used to display taxonomy of classes using these datasources:

:tree_root_personClass rdf:type owl:NamedIndividual ,
                                   <http://data.sparna.fr/ontologies/sparnatural-config-datasources#SparqlTreeRootDatasource> ;
                          <http://data.sparna.fr/ontologies/sparnatural-config-datasources#queryString> """PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?uri ?label ?hasChildren
WHERE {
  VALUES ?uri {$domain}
  ?uri rdfs:label ?label .
  FILTER(lang(?label) = '' || lang(?label) = $lang)
  BIND(true AS ?hasChildren)
}""" .

:tree_children_subClassOf rdf:type owl:NamedIndividual ,
                                   <http://data.sparna.fr/ontologies/sparnatural-config-datasources#SparqlTreeRootDatasource> ;
                          <http://data.sparna.fr/ontologies/sparnatural-config-datasources#queryString> """PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>                          
SELECT DISTINCT ?uri ?label ?hasChildren
WHERE {
  ?uri rdfs:subClassOf $node .
  ?uri rdfs:label ?label .  
  FILTER(lang(?label) = '' || lang(?label) = $lang)
  OPTIONAL {
       ?uri ^rdfs:subClassOf ?children .
  }
  BIND(IF(bound(?children),true,false) AS ?hasChildren)
}""" .

this works nice on DBPedia:

image

I will see if I integrate these datasources in the set of datasources provided out of the box by Sparnatural.