Search code examples
sparqlrdfontologyprotege

SPARQL Query the triples created using Protégé ontological approach for distinct classes with object properties


I have a question about querying the object properties that can be defined between classes.I have created triples using the protege ontological approach where,I have created two classes named "A" and "B" with instances A1, A2, A3, and B1, B2, and B3 respectively.

I have added an object property "aToB". Now I want to write a Query that can query the instances under each class using the object property.for which I have written the following QUERY

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX  : <http://www.semanticweb.org/arash>
SELECT ?x ?y
    WHERE { ?x :AtoB ?y}

however, upon doing this procedure nothing is returned can you tell me what is the issue?

Defining classes in Protoge Defing the object property between Class A and B SPARQL query written enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

I am adding the TTL code:

@prefix : <http://www.semanticweb.org/arash#> .
@prefix ab: <http://www.semanticweb.org/arash#> .
@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 <http://www.semanticweb.org/arash> .

<http://www.semanticweb.org/arash> rdf:type owl:Ontology .

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

###  http://www.semanticweb.org/arash#aToB
ab:aToB rdf:type owl:ObjectProperty ;
        owl:inverseOf ab:bToA ;
        rdfs:domain ab:A ;
        rdfs:range ab:B .


###  http://www.semanticweb.org/arash#bToA
ab:bToA rdf:type owl:ObjectProperty .


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

###  http://www.semanticweb.org/arash#A
ab:A rdf:type owl:Class .


###  http://www.semanticweb.org/arash#B
ab:B rdf:type owl:Class .


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

###  http://www.semanticweb.org/arash#A1
ab:A1 rdf:type owl:NamedIndividual ,
               ab:A ;
      ab:aToB ab:A1 .


###  http://www.semanticweb.org/arash#A2
ab:A2 rdf:type owl:NamedIndividual ,
               ab:A ;
      ab:aToB ab:B2 .


###  http://www.semanticweb.org/arash#A3
ab:A3 rdf:type owl:NamedIndividual ,
               ab:A .


###  http://www.semanticweb.org/arash#B1
ab:B1 rdf:type owl:NamedIndividual ,
               ab:B ;
      ab:aToB ab:A1 .


###  http://www.semanticweb.org/arash#B2
ab:B2 rdf:type owl:NamedIndividual ,
               ab:B .


###  http://www.semanticweb.org/arash#B3
ab:B3 rdf:type owl:NamedIndividual ,
               ab:B ;
      ab:aToB ab:A3 ;
      owl:topDataProperty "" .


[ ab:aToB ab:A1
] .

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

Solution

  • The prefix in your query is missing the closing #.