Discussion:
SPARQL for querying object property and its annotations
Abhishek Kumar
2016-11-13 08:12:01 UTC
Permalink
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
Martynas Jusevičius
2016-11-13 08:20:23 UTC
Permalink
You probably want to use rdf:List here:
https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#collections
Post by Abhishek Kumar
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 |
-------------------------------
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") }
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
Claude Warren
2016-11-13 09:07:22 UTC
Permalink
If you want to list the children in sequence order you will probably need
to add a ORDER BY (sequence) to your sparql query.
Post by Abhishek Kumar
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 |
-------------------------------
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") }
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
Abhishek Kumar
2016-11-13 12:29:08 UTC
Permalink
Hi,

@Martynas - Something like RDF collections is what I should be using. But I
am looking to use OWL instead of RDF. From search it looks like OWL (and
hence Protege) does not support RDF Collections.
http://protege-project.136.n4.nabble.com/rdf-collections-td4664415.html

@Claude - Yes that was my intent once I got the annotation within SPARQL.

Thanks.
Abhishek
Post by Claude Warren
If you want to list the children in sequence order you will probably need
to add a ORDER BY (sequence) to your sparql query.
Post by Abhishek Kumar
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
Post by Abhishek Kumar
to design the ontology (RDF/XML) and Jena for the application which will
be
Post by Abhishek Kumar
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
Post by Abhishek Kumar
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 |
-------------------------------
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") }
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?
Post by Abhishek Kumar
Thanks,
Abhishek
--
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren
Loading...