Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am getting all members of Student .i use the following code but i getting result only ind my query is correct . when i run that query in protege 4.3 they give correct result but problem in java code.i dont understand what i do wrong .please suggest what i wrong in my java class.
Java
class sparql1
    {  public static void main(String[] args) {

            String filename="modified2.owl";
            Model model=ModelFactory.createDefaultModel();
            OntModel model1=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);

            try
            {
                File file=new File(filename);
                FileInputStream reader=new FileInputStream(file);
                model.read(reader,null);

                String query1=" PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX my: <http://www.semanticweb.org/rohit/ontologies/2014/4/untitled-ontology-10#> SELECT  ?ind WHERE { ?ind rdf:type my:Student .}";

                com.hp.hpl.jena.query.Query query=QueryFactory.create(query1);
                QueryExecution exe=QueryExecutionFactory.create(query, model1);
                ResultSet RES=exe.execSelect();
                ResultSetFormatter.out(System.out, RES, query);
            }catch(Exception e)
            {
                e.printStackTrace();
            }
        }
    }


ontology code
XML
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
    <!ENTITY untitled-ontology-10 "http://www.semanticweb.org/rohit/ontologies/2014/4/untitled-ontology-10#" >
]>
<rdf:RDF xmlns="http://www.semanticweb.org/rohit/ontologies/2014/4/untitled-ontology-10#"
     xml:base="http://www.semanticweb.org/rohit/ontologies/2014/4/untitled-ontology-10"
     xmlns:untitled-ontology-10="http://www.semanticweb.org/rohit/ontologies/2014/4/untitled-ontology-10#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <owl:Ontology rdf:about="http://www.semanticweb.org/rohit/ontologies/2014/4/untitled-ontology-10"/>
     <!-- http://www.semanticweb.org/rohit/ontologies/2014/4/untitled-ontology-10#hasAddress -->

    <owl:DatatypeProperty rdf:about="&untitled-ontology-10;hasAddress"/><!-- http://www.semanticweb.org/rohit/ontologies/2014/4/untitled-ontology-10#hasEmail -->
<owl:DatatypeProperty rdf:about="&untitled-ontology-10;hasEmail"/>
   <owl:Class rdf:about="&untitled-ontology-10;Student"/>
    <!-- http://www.semanticweb.org/rohit/ontologies/2014/4/untitled-ontology-10#Student2 --> <owl:NamedIndividual rdf:about="&untitled-ontology-10;Student2">
        <rdf:type rdf:resource="&untitled-ontology-10;Student"/>
        <hasEmail rdf:datatype="&xsd;string">asd</hasEmail>
        <hasAddress rdf:datatype="&xsd;string">sdsad</hasAddress>
    </owl:NamedIndividual>
<!-- http://www.semanticweb.org/rohit/ontologies/2014/4/untitled-ontology-10#student1 -->
<owl:NamedIndividual rdf:about="&untitled-ontology-10;student1">
        <rdf:type rdf:resource="&untitled-ontology-10;Student"/>
        <hasEmail rdf:datatype="&xsd;string">fhgchg</hasEmail>
        <hasAddress rdf:datatype="&xsd;string">me</hasAddress>
    </owl:NamedIndividual>
    <!-- http://www.semanticweb.org/rohit/ontologies/2014/4/untitled-ontology-10#student3 -->
<owl:NamedIndividual rdf:about="&untitled-ontology-10;student3">
        <rdf:type rdf:resource="&untitled-ontology-10;Student"/>
        <hasEmail rdf:datatype="&xsd;string">dsfdsf</hasEmail>
        <hasAddress rdf:datatype="&xsd;string">sdfds</hasAddress>
    </owl:NamedIndividual>
</rdf:RDF>
Posted
Updated 18-Feb-20 4:40am
v4
Comments
baliram bhande 8-May-14 2:11am    
Please reply me as possible as i am in trouble
baliram bhande 8-May-14 10:23am    
any one have knows the ontology concepts in this forum

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900