public static void usageWithDefaultModel() { System.out.println("Results with plain RDF Model"); System.out.println("----------------------------"); System.out.println(); // ontology that will be used final String ont = "http://protege.cim3.net/file/pub/ontologies/koala/koala.owl#"; final String ns = "http://protege.stanford.edu/plugins/owl/owl-library/koala.owl#"; // create Pellet reasoner final Reasoner reasoner = PelletReasonerFactory.theInstance().create(); // create an empty model final Model emptyModel = ModelFactory.createDefaultModel(); // create an inferencing model using Pellet reasoner final InfModel model = ModelFactory.createInfModel(reasoner, emptyModel); // read the file model.read(ont); // print validation report final ValidityReport report = model.validate(); printIterator(report.getReports(), "Validation Results"); // print superclasses final Resource c = model.getResource(ns + "MaleStudentWith3Daughters"); printIterator(model.listObjectsOfProperty(c, RDFS.subClassOf), "All super classes of " + c.getLocalName()); System.out.println(); }
public static void usageWithDefaultModel() { System.out.println("Results with plain RDF Model"); System.out.println("----------------------------"); System.out.println(); // ontology that will be used final String ont = "http://protege.cim3.net/file/pub/ontologies/koala/koala.owl#"; final String ns = "http://protege.stanford.edu/plugins/owl/owl-library/koala.owl#"; // create Pellet reasoner final Reasoner reasoner = PelletReasonerFactory.theInstance().create(); // create an empty model final Model emptyModel = ModelFactory.createDefaultModel(); // create an inferencing model using Pellet reasoner final InfModel model = ModelFactory.createInfModel(reasoner, emptyModel); // read the file model.read(ont); // print validation report final ValidityReport report = model.validate(); printIterator(report.getReports(), "Validation Results"); // print superclasses final Resource c = model.getResource(ns + "MaleStudentWith3Daughters"); printIterator(model.listObjectsOfProperty(c, RDFS.subClassOf), "All super classes of " + c.getLocalName()); System.out.println(); }
/** * Test problems with inferring equivalence of some simple class definitions, * reported by Jeffrey Hau. */ public void testEquivalentClass1() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/equivalentClassTest.owl"); InfModel test = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), base); String NAMESPACE = "urn:foo#"; Resource A = test.getResource(NAMESPACE + "A"); Resource B = test.getResource(NAMESPACE + "B"); assertTrue("hasValue equiv deduction", test.contains(A, OWL.equivalentClass, B)); }
/** * Report of problems with cardinality v. maxCardinality usage in classification, * from Hugh Winkler. */ public void testCardinality1() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/cardFPTest.owl"); InfModel test = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), base); String NAMESPACE = "urn:foo#"; Resource aDocument = test.getResource(NAMESPACE + "aDocument"); Resource documentType = test.getResource(NAMESPACE + "Document"); assertTrue("Cardinality-based classification", test.contains(aDocument, RDF.type, documentType)); }
/** * Test problems with inferring equivalence of some simple class definitions, * reported by Jeffrey Hau. */ public void testEquivalentClass1() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/equivalentClassTest.owl"); InfModel test = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), base); String NAMESPACE = "urn:foo#"; Resource A = test.getResource(NAMESPACE + "A"); Resource B = test.getResource(NAMESPACE + "B"); assertTrue("hasValue equiv deduction", test.contains(A, OWL.equivalentClass, B)); }
/** * Report of problems with cardinality v. maxCardinality usage in classification, * from Hugh Winkler. */ public void testCardinality1() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/cardFPTest.owl"); InfModel test = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), base); String NAMESPACE = "urn:foo#"; Resource aDocument = test.getResource(NAMESPACE + "aDocument"); Resource documentType = test.getResource(NAMESPACE + "Document"); assertTrue("Cardinality-based classification", test.contains(aDocument, RDF.type, documentType)); }
((FBRuleInfGraph)infmodel.getGraph()).setTraceOn(true); String baseURI = "http://jena.hpl.hp.com/eg#"; Resource C = infmodel.getResource(baseURI + "C"); Resource I = infmodel.getResource(baseURI + "i"); Property R = infmodel.getProperty(baseURI, "R");
((FBRuleInfGraph)infmodel.getGraph()).setTraceOn(true); String baseURI = "http://jena.hpl.hp.com/eg#"; Resource C = infmodel.getResource(baseURI + "C"); Resource I = infmodel.getResource(baseURI + "i"); Property R = infmodel.getProperty(baseURI, "R");
Resource i = conclusions.getResource("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#i"); Property p = conclusions.getProperty("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#p"); Resource c = conclusions.getResource("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#c"); Resource r = conclusions.getResource("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#r"); Resource v = (Resource)i.getRequiredProperty(p).getObject(); System.out.println("Value of i.p = " + v);
Resource i = conclusions.getResource("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#i"); Property p = conclusions.getProperty("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#p"); Resource c = conclusions.getResource("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#c"); Resource r = conclusions.getResource("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#r"); Resource v = (Resource)i.getRequiredProperty(p).getObject(); System.out.println("Value of i.p = " + v);
/** * Test closure of grounded choice points */ public void testGroundClosure2() { Flag myFlag = new Flag(); BuiltinRegistry.theRegistry.register(myFlag); List<Rule> rules = Rule.rulesFromURL("file:testing/reasoners/bugs/groundClosure2.rules"); GenericRuleReasoner reasoner = new GenericRuleReasoner( rules ); InfModel inf = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel()); String NS = "http://jena.hpl.hp.com/example#"; Resource Phil = inf.getResource(NS + "Phil"); Resource Paul = inf.getResource(NS + "Paul"); Property parent = inf.getProperty(NS + "parent"); assertTrue ( inf.contains(Paul, parent, Phil) ); assertTrue( ! myFlag.fired ); }
/** * Test the @prefix and @include extensions to the rule parser */ public void testExtendedRuleParser() { List<Rule> rules = Rule.rulesFromURL("file:testing/reasoners/ruleParserTest1.rules"); GenericRuleReasoner reasoner = new GenericRuleReasoner(rules); reasoner.setTransitiveClosureCaching(true); Model base = ModelFactory.createDefaultModel(); InfModel m = ModelFactory.createInfModel(reasoner, base); // Check prefix case String NS1 = "http://jena.hpl.hp.com/newprefix#"; String NS2 = "http://jena.hpl.hp.com/newprefix2#"; String NS3 = "http://jena.hpl.hp.com/newprefix3#"; Resource A = m.getResource(NS1 + "A"); Resource C = m.getResource(NS1 + "C"); Property p = m.getProperty(NS2 + "p"); Property a = m.getProperty(NS3 + "a"); Resource foo = m.getResource(NS1 + "foo"); assertTrue("@prefix test", m.contains(A, p, foo)); // Check RDFS rule inclusion assertTrue("@include RDFS test", m.contains(A, RDFS.subClassOf, C)); assertTrue("@include test", m.contains(a,a,a)); }
/** * Test closure of grounded choice points */ public void testGroundClosure2() { Flag myFlag = new Flag(); BuiltinRegistry.theRegistry.register(myFlag); List<Rule> rules = Rule.rulesFromURL("file:testing/reasoners/bugs/groundClosure2.rules"); GenericRuleReasoner reasoner = new GenericRuleReasoner( rules ); InfModel inf = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel()); String NS = "http://jena.hpl.hp.com/example#"; Resource Phil = inf.getResource(NS + "Phil"); Resource Paul = inf.getResource(NS + "Paul"); Property parent = inf.getProperty(NS + "parent"); assertTrue ( inf.contains(Paul, parent, Phil) ); assertTrue( ! myFlag.fired ); }
/** * Test the @prefix and @include extensions to the rule parser */ public void testExtendedRuleParser() { List<Rule> rules = Rule.rulesFromURL("file:testing/reasoners/ruleParserTest1.rules"); GenericRuleReasoner reasoner = new GenericRuleReasoner(rules); reasoner.setTransitiveClosureCaching(true); Model base = ModelFactory.createDefaultModel(); InfModel m = ModelFactory.createInfModel(reasoner, base); // Check prefix case String NS1 = "http://jena.hpl.hp.com/newprefix#"; String NS2 = "http://jena.hpl.hp.com/newprefix2#"; String NS3 = "http://jena.hpl.hp.com/newprefix3#"; Resource A = m.getResource(NS1 + "A"); Resource C = m.getResource(NS1 + "C"); Property p = m.getProperty(NS2 + "p"); Property a = m.getProperty(NS3 + "a"); Resource foo = m.getResource(NS1 + "foo"); assertTrue("@prefix test", m.contains(A, p, foo)); // Check RDFS rule inclusion assertTrue("@include RDFS test", m.contains(A, RDFS.subClassOf, C)); assertTrue("@include test", m.contains(a,a,a)); }
/** * Test bug with leaking variables which results in an incorrect "range = Nothing" deduction. */ public void testRangeBug() { Model model = FileManager.get().loadModel("file:testing/reasoners/bugs/rangeBug.owl"); // Model m = ModelFactory.createDefaultModel(); Reasoner r = ReasonerRegistry.getOWLReasoner(); InfModel omodel = ModelFactory.createInfModel(r, model); String baseuri = "http://decsai.ugr.es/~ontoserver/bacarex2.owl#"; // Resource js = omodel.getResource(baseuri + "JS"); Resource surname = omodel.getResource(baseuri + "surname"); Statement s = omodel.createStatement(surname, RDFS.range, OWL.Nothing); assertTrue(! omodel.contains(s)); }
/** * Test bug with leaking variables which results in an incorrect "range = Nothing" deduction. */ public void testRangeBug() { Model model = FileManager.get().loadModel("file:testing/reasoners/bugs/rangeBug.owl"); // Model m = ModelFactory.createDefaultModel(); Reasoner r = ReasonerRegistry.getOWLReasoner(); InfModel omodel = ModelFactory.createInfModel(r, model); String baseuri = "http://decsai.ugr.es/~ontoserver/bacarex2.owl#"; // Resource js = omodel.getResource(baseuri + "JS"); Resource surname = omodel.getResource(baseuri + "surname"); Statement s = omodel.createStatement(surname, RDFS.range, OWL.Nothing); assertTrue(! omodel.contains(s)); }
/** Illustrate different ways of finding a reasoner */ public void test1() { String NS = "urn:x-hp-jena:eg/"; // Build a trivial example data set Model rdfsExample = ModelFactory.createDefaultModel(); Property p = rdfsExample.createProperty(NS, "p"); Property q = rdfsExample.createProperty(NS, "q"); rdfsExample.add(p, RDFS.subPropertyOf, q); rdfsExample.createResource(NS+"a") .addProperty(p, "foo"); // Create an RDFS inference model the easy way // InfModel inf = ModelFactory.createRDFSModel(rdfsExample); // Create an RDFS inference model the hard way Resource config = ModelFactory.createDefaultModel() .createResource() .addProperty(ReasonerVocabulary.PROPsetRDFSLevel, "simple"); Reasoner reasoner = RDFSRuleReasonerFactory.theInstance().create(config); // Set the parameter the easier way // reasoner.setParameter(ReasonerVocabulary.PROPsetRDFSLevel, // ReasonerVocabulary.RDFS_SIMPLE); InfModel inf = ModelFactory.createInfModel(reasoner, rdfsExample); Resource a = inf.getResource(NS+"a"); Statement s = a.getProperty(q); System.out.println("Statement: " + s); }
/** Illustrate different ways of finding a reasoner */ public void test1() { String NS = "urn:x-hp-jena:eg/"; // Build a trivial example data set Model rdfsExample = ModelFactory.createDefaultModel(); Property p = rdfsExample.createProperty(NS, "p"); Property q = rdfsExample.createProperty(NS, "q"); rdfsExample.add(p, RDFS.subPropertyOf, q); rdfsExample.createResource(NS+"a") .addProperty(p, "foo"); // Create an RDFS inference model the easy way // InfModel inf = ModelFactory.createRDFSModel(rdfsExample); // Create an RDFS inference model the hard way Resource config = ModelFactory.createDefaultModel() .createResource() .addProperty(ReasonerVocabulary.PROPsetRDFSLevel, "simple"); Reasoner reasoner = RDFSRuleReasonerFactory.theInstance().create(config); // Set the parameter the easier way // reasoner.setParameter(ReasonerVocabulary.PROPsetRDFSLevel, // ReasonerVocabulary.RDFS_SIMPLE); InfModel inf = ModelFactory.createInfModel(reasoner, rdfsExample); Resource a = inf.getResource(NS+"a"); Statement s = a.getProperty(q); System.out.println("Statement: " + s); }
@Test public void test253() { final String aOnt = "file:" + PelletTestSuite.base + "misc/longitude2.ttl"; final PelletReasoner aReasoner = PelletReasonerFactory.theInstance().create(); final InfModel aModel = ModelFactory.createInfModel(aReasoner, ModelFactory.createDefaultModel()); aModel.read(aOnt, "N3"); final String aQuery = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n" + "PREFIX mon: <http://www.semwebtech.org/mondial/10/meta#>\n" + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX : <foo://bla/>\n" + "SELECT ?v0 WHERE\n" + "{ ?v0 rdf:type :EasternHemispherePlace. }\n"; final QueryExecution qe = SparqlDLExecutionFactory.create(QueryFactory.create(aQuery), aModel); final Resource berlin = aModel.getResource("foo://bla/Berlin"); final ResultSet results = qe.execSelect(); assertTrue(results.hasNext()); assertTrue(berlin.equals(results.next().getResource("v0"))); assertFalse(results.hasNext()); }
@Ignore("According to latest OWL 2 spec onDatatype property can only point to named datatypes so the input " + "ontology for this test is not valid anymore") @Test public void test306() { final String aOnt = "file:" + PelletTestSuite.base + "misc/longitude.ttl"; final PelletReasoner aReasoner = PelletReasonerFactory.theInstance().create(); final InfModel aModel = ModelFactory.createInfModel(aReasoner, ModelFactory.createDefaultModel()); aModel.read(aOnt, "N3"); final String aQuery = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n" + "PREFIX mon: <http://www.semwebtech.org/mondial/10/meta#>\n" + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX : <foo://bla/>\n" + "SELECT ?v0 WHERE\n" + "{ ?v0 rdf:type :EasternHemispherePlace. }\n"; final QueryExecution qe = SparqlDLExecutionFactory.create(QueryFactory.create(aQuery), aModel); final Resource berlin = aModel.getResource("foo://bla/Berlin"); final ResultSet results = qe.execSelect(); assertTrue(results.hasNext()); assertTrue(berlin.equals(results.next().getResource("v0"))); assertFalse(results.hasNext()); }