Question

I am trying sparql and the use of entailment.

As a example i used http://www.w3.org/TR/2010/WD-sparql11-entailment-20100126/#t112

i try to put them in jena.

     OntClass book1= model.createClass(NS+"book1");
     OntClass book2=model.createClass(NS+"book2");
     OntClass book3=model.createClass(NS+"book3");
     OntClass publication=model.createClass(NS+"publication");
     OntClass article=model.createClass(NS+"article");
     OntClass mit=model.createClass(NS+"MIT");

     ObjectProperty a = model.createObjectProperty(NS+"a");
     ObjectProperty publishes = model.createObjectProperty(NS+"publishes");

     book1.addProperty(a, publication);
     book2.addProperty(a, article);
     publication.addSubClass(article);

     publishes.addRange(publication);
     mit.addProperty(publishes, book3);

where model is type OntModel.

and i used the query similar to the problem

     "PREFIX table: "I have correct namespace here"+
     "SELECT *"+
    "WHERE"+
    "{"+
    " ?x ?y table:publication  ."+
    "}";

The model was created like this. Hope OntModelSpec is ok.

OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF, null);

i get as results from query


 x                                                           y               
| http://www.example.com/ontologies/sample.owl#publishes   | rdfs:range                                       |
| http://www.example.com/ontologies/sample.owl#article     | rdfs:subClassOf                                  |
| http://www.example.com/ontologies/sample.owl#book1       | http://www.example.com/ontologies/sample.owl#a |
| http://www.example.com/ontologies/sample.owl#publication | rdfs:subClassOf                                  |
| http://www.example.com/ontologies/sample.owl#book3       | rdf:type                                         |   

Can anyone give me a example, with and without entailment, so a cant try code, can get the results right.

Was it helpful?

Solution

Your ontology looks a bit fishy.

book1, book2, book3 and mit are not classes, they are individuals. You should use model.createIndividual(NS + "bookX", publication) for the books, and create a class for “organization” or similar, and then create mit as an individual of that class. Note that createIndividual already takes care of assigning the type to the individual, so you don't need to mess around with your “a” property. You should fix these things first and then try again and update your question.

About entailment: Look at the last line of your query result. You didn't say anywhere that book3 is a book, but the statement is there anyways. That's because it was entailed by the other statements, and that's why the RDFS inference engine makes the statement visible when you query the model. The statement is entailed because of the range on publishes: Everything that's being published is entailed to be of type publication.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top