0

Using the Snap SPARQL Query view I do not find a way to query the transitive closure e.g. of the property ex:myontology#isPartOf so that I can infer that, since A isPartOf AB which isPartOf ABC which isPartOf ABCD then A isPartOf ABC and ABCD.

Any Help???

I tried SELECT ?x ?y WHERE { x <ex:myontology#isPartOf>+ ?y }

but it is an invalid syntax. My example ontology is the following:

@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <ex:myontology> .

<ex:myontology> rdf:type owl:Ontology ;
                 owl:versionIRI <ex:myontology/0.1/> .

#################################################################
#    Object Properties
#################################################################

###  ex:myontology#hasPart
:hasPart rdf:type owl:ObjectProperty ;
         owl:inverseOf :isPartOf .


###  ex:myontology#isPartOf
:isPartOf rdf:type owl:ObjectProperty .


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

###  ex:myontology#concept
:concept rdf:type owl:Class .


#################################################################
#    Individuals
#################################################################

###  ex:myontology#A
:A rdf:type owl:NamedIndividual ,
            :concept ;
   :isPartOf :AB .


###  ex:myontology#AB
:AB rdf:type owl:NamedIndividual ,
             :concept ;
    :isPartOf :ABC .


###  ex:myontology#ABC
:ABC rdf:type owl:NamedIndividual ,
              :concept ;
     :isPartOf :ABCD .


###  ex:myontology#ABCD
:ABCD rdf:type owl:NamedIndividual ,
               :concept .


###  ex:myontology#B
:B rdf:type owl:NamedIndividual ,
            :concept ;
   :isPartOf :AB .


###  ex:myontology#C
:C rdf:type owl:NamedIndividual ,
            :concept ;
   :isPartOf :ABC .


###  ex:myontology#D
:D rdf:type owl:NamedIndividual ,
            :concept ;
   :isPartOf :ABCD .


###  Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi```

Also how can I get results in their successive order (and not descending or ascending) using the transitive closure of isPartOf in SPARQL? i.e. 

SELECT ?x ?y
WHERE {?x isPartOf+ ?y}

ORDER BY ?x (this part I am asking)

A isPartOf AB
A isPartOf ABC
A isPartOf ABCD
  

Thanks a lot
Nikos
nik
  • 1
  • 1
  • Snap SPARQL plugin doesn't support full SPARQL 1.1. Given that Snap SPARQL does make use of a reasoner during initialization, my suggestion would be to add the transitive property axiom to the ontology. That should be enough. – UninformedUser Jul 05 '23 at 12:22
  • Otherwise, you'd have to live with the standard SPARQL query view, which doesn't support inference. That's all Protege can do for you. Anything beyond, use a proper triple store with reasoning support. – UninformedUser Jul 05 '23 at 12:22
  • Please could you please also take a look at the addition in last part of my question??? – nik Jul 06 '23 at 07:17
  • what you'rte asking somewhere hidden in the code tag now is to order by the length of the path. SPARQL in general isn't the best path query language to be honest, but there have been some nice workarounds (with limitations) suggested here: https://stackoverflow.com/questions/18024413/finding-all-steps-in-property-path - this should be the way to go, then you could order by subject and step number – UninformedUser Jul 06 '23 at 10:08
  • Thanks for your comments! and the information – nik Jul 07 '23 at 04:13

0 Answers0