If you want to list the children in sequence order you will probably need to add a ORDER BY (sequence) to your sparql query.
On Sun, Nov 13, 2016 at 8:12 AM, Abhishek Kumar <akvk....@gmail.com> wrote: > Hi, > > 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 (RDF/XML) and Jena for the application which will be > hosted on Apache TomEE. The question I ask is specific to SPARQL and not > related to Jena. > > I have created a simplified ontology to explain the query I am having. In > people.owl 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 seqeunce 2. Similarly jane's hasChild jack has > sequence 1. > > 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 > > -------------------------------- > sequence | childname| > --------------------------------- > 1 | Anne Doe | > 2 | Jack Doe | > ------------------------------- > > I have the query till now: > 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 ppl: <http://www.semanticweb.org/abhishek/ontologies/people#> > 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") } > > So I have two questions: > 1. Should I change the ontology design to assign the sequence number to a > child? > 2. If the above approach is correct, how do I get the sequence for a child? > > Thanks, > Abhishek > -- I like: Like Like - The likeliest place on the web <http://like-like.xenei.com> LinkedIn: http://www.linkedin.com/in/claudewarren