title: SPARQL for querying object property and its annotations
body: <p>I am trying to learn about semantic web technology to see if it can replace the current Relational model in an application. I am using protege to design the ontology and Jena for the application which will be hosted on Apache TomEE.</p>
  
  <p>I have created a simplified ontology to explain the query I am having. In people.owl (turtle below) there is only one class People. The object property hasChild links a person individual to his children who are also Person. Now I want to know the order of the children for a person.
  For example, individual john has two children, with anne being first and jack being second. So to the hasChild object property of john I have added sequence annotation. The sequence is a number which tells the order in which the child was born for that person. So hasChild anne has sequence 1 and hasChild jack has sequnce 2. Similarly jane's hasChild jack has sequence 1.</p>
  
  <p>The SPARQL I have to write is to get all the children of a given Person's name in the order they were born. So if I query children of "John Doe", I should get</p>
  
  <h2>|sequence | childname|</h2>
  
  <p>|   1     | Anne Doe |</p>
  
  <p>|   2     | Jack Doe |</p>
  
  <p>Below is the Ontology in turtle format.</p>
  
  <pre><code>@prefix : &lt;http://www.semanticweb.org/abhishek/ontologies/people#&gt; .
  @prefix owl: &lt;http://www.w3.org/2002/07/owl#&gt; .
  @prefix rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
  @prefix xml: &lt;http://www.w3.org/XML/1998/namespace&gt; .
  @prefix xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt; .
  @prefix rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; .
  @prefix people: &lt;http://www.semanticweb.org/abhishek/ontologies/people#&gt; .
  @base &lt;http://www.semanticweb.org/abhishek/ontologies/people&gt; .
  
  &lt;http://www.semanticweb.org/abhishek/ontologies/people&gt; rdf:type owl:Ontology .
  
  ###  http://www.semanticweb.org/abhishek/ontologies/people#sequence
  people:sequence rdf:type owl:AnnotationProperty .
  
  
  ###  http://www.semanticweb.org/abhishek/ontologies/people#hasChild
  people:hasChild rdf:type owl:ObjectProperty .
  
  
  ###  http://www.semanticweb.org/abhishek/ontologies/people#hasParent
  people:hasParent rdf:type owl:ObjectProperty .
  
  
  ###  http://www.semanticweb.org/abhishek/ontologies/people#hasSpouse
  people:hasSpouse rdf:type owl:ObjectProperty .
  
  
  ###  http://www.semanticweb.org/abhishek/ontologies/people#name
  people:name rdf:type owl:DatatypeProperty .
  
  ###  http://www.semanticweb.org/abhishek/ontologies/people#Person
  people:Person rdf:type owl:Class .
  
  ###  http://www.semanticweb.org/abhishek/ontologies/people#anne
  people:anne rdf:type owl:NamedIndividual ,
                       people:Person ;
              people:name "Anne Doe"^^xsd:string .
  
  
  ###  http://www.semanticweb.org/abhishek/ontologies/people#jack
  people:jack rdf:type owl:NamedIndividual ,
                       people:Person ;
              people:name "Jack Doe"^^xsd:string .
  
  
  ###  http://www.semanticweb.org/abhishek/ontologies/people#jane
  people:jane rdf:type owl:NamedIndividual ,
                       people:Person ;
              people:hasChild people:jack ;
              people:hasSpouse people:john ;
              people:name "Jane Doe"^^xsd:string .
  
  [ rdf:type owl:Axiom ;
     owl:annotatedSource people:jane ;
     owl:annotatedProperty people:hasChild ;
     owl:annotatedTarget people:jack ;
     people:sequence "1"^^xsd:int
   ] .
  
  
  ###  http://www.semanticweb.org/abhishek/ontologies/people#john
  people:john rdf:type owl:NamedIndividual ,
                       people:Person ;
              people:hasChild people:anne ,
                              people:jack ;
              people:hasSpouse people:jane ;
              people:name "John Doe"^^xsd:string .
  
  [ rdf:type owl:Axiom ;
     owl:annotatedSource people:john ;
     owl:annotatedProperty people:hasChild ;
     owl:annotatedTarget people:anne ;
     people:sequence "1"^^xsd:int
   ] .
  
  [ rdf:type owl:Axiom ;
     owl:annotatedSource people:john ;
     owl:annotatedProperty people:hasChild ;
     owl:annotatedTarget people:jack ;
     people:sequence "2"^^xsd:int
   ] .
  
  
  ###  Generated by the OWL API (version 4.2.6.20160910-2108) https://github.com/owlcs/owlapi
  </code></pre>
  
  <p>I have the query till now:</p>
  
  <pre><code>PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
  PREFIX owl: &lt;http://www.w3.org/2002/07/owl#&gt;
  PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt;
  PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;
  PREFIX ppl: &lt;http://www.semanticweb.org/abhishek/ontologies/people#&gt;
  SELECT ?sequence ?childname 
      WHERE { ?person rdf:type ppl:Person .
          ?person ppl:name ?name .
          ?person ppl:hasChild ?child .
          #Get the ?sequence  for the current child. sequence is annotated to hasChild.
          ?child ppl:name ?childname .
          FILTER regex(?name, "John Doe") }
  </code></pre>
  
  <p>So I have two questions:</p>
  
  <ul>
  <li><p>Should I change the ontology design to assign the sequence number to a child?</p></li>
  <li><p>If the above approach is correct, how do I get the sequence for a child?</p></li>
  </ul>
  
  <p>I posted the same question on Jena user list and got the recommendation to use RDF Collections. But from google search I found collections don't work with OWL (and hence Protege).</p>
  
  <p>Thanks,
  Abhishek</p>