On 26/07/16 09:53, javed khan wrote:
I have class *Expert*, *Research* and *Student*. Student has Master and Phd subclasses. Expert hasResearch Research, like BernersLee hasResearch Ontologies. Phd Student also have Research like: Khan hasResearch Ontologies.I added a class *StudentExpert* which have no instance but can be created with Jena rules. In Protege, when I give: . SELECT * WHERE { ?sub std:hasResearch ?x } it gives me research of both Phd and Expert. I give then: . SELECT * WHERE { ?sub std:hasResearch ?x . ?sub rdf:type std:Phd } And it filters research for Phd class only. In Jena, after read the file, I gives the rules as: String rule = "[rule1:(?x http://www.semanticweb.org/141#hasResearch ?y) " + "(?x http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type http://www.semanticweb.org/141#Phd)" + "->(?x http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type http://www.semanticweb.org/141#StudentExpert)]"; And query like this: String str= "Prefix std:<http://www.semanticweb.org/ 141#> " + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"+ "PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"+ "Select *" + "where { ?x rdf:type std:StudentExpert }"; I expect it will answer me: instance Khan to be StudentExpert instance but it gives me exception: Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " <PNAME_NS> "http: "" at line 2, column 13. Was expecting: <IRIref> ... at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:87)
So that is telling the syntax of your SPARQL query is wrong, in particular that it has found http:... when it expected <...
The error is at: PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#> which should be PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> Nothing to do with your rules. Dave
