tags:

views:

151

answers:

1

I have created some sample ontology in protege.According to my ontology there is a class called person and which has sub class called Student.There are some student individuals(john,paul,marry,...). I have defined some data property called "email" and assigned their email addresses.

Following query which is resulting all the individuals in ontology.But I want to get each individual and their email address.

String queryStr =
    "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#&gt; "+
    "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;  "+
    "select   ?ind "+
    "where { "+
    "?ind  rdf:type <http://www.semanticweb.org/ontologies/2010/5/Ontology1275975684120.owl#Student&gt; ;"+

"}\n ";

Above query was tested on jena in eclipse IDE.

any idea..?

Thank in advance!

+1  A: 

To get the email addresses you need to 1) add a variable for them to the SELECT line, and 2) bind that variable in the WHERE pattern. And you'll probably want to add a prefix for your own ontology, since you'll now need to refer to it twice. Something like:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#&gt;
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX my: <http://www.semanticweb.org/ontologies/2010/5/Ontology1275975684120.owl#&gt;

SELECT ?ind ?email
WHERE {
  ?ind rdf:type my:Student .
  ?ind my:Email ?email
}
glenn mcdonald
:: I got the result based on your answer! Have a great day!Thank you very much!
udayalkonline