public static void main(String[] args) { FileManager.get().addLocatorClassLoader(ExampleONT_02.class.getClassLoader()); Model tbox = FileManager.get().loadModel("data/inference/tbox.owl", null, "RDF/XML"); // http://en.wikipedia.org/wiki/Tbox Reasoner reasoner = ReasonerRegistry.getOWLReasoner().bindSchema(tbox.getGraph()); Model abox = FileManager.get().loadModel("data/inference/abox.owl", null, "RDF/XML"); // http://en.wikipedia.org/wiki/Abox InfModel inf = ModelFactory.createInfModel(reasoner, abox); ValidityReport validityReport = inf.validate(); if ( !validityReport.isValid() ) { System.out.println("Inconsistent"); Iterator<Report> iter = validityReport.getReports(); while ( iter.hasNext() ) { Report report = iter.next(); System.out.println(report); } } else { System.out.println("Valid"); } }
@Override public void runTest() { ValidityReport report = testResults(); switch (expected) { case INCONSISTENT: assertTrue("expected inconsistent", !report.isValid()); break; case WARNINGS: assertTrue("expected just warnings but reports not valid", report .isValid()); assertFalse("expected warnings but reports clean", report.isClean()); break; case CLEAN: assertTrue("expected clean", report.isClean()); } if (culprit != null) { boolean foundit = false; for (Iterator<Report> i = report.getReports(); i.hasNext();) { ValidityReport.Report r = i.next(); if (r.getExtension() != null && r.getExtension().equals(culprit)) { foundit = true; break; } } if (!foundit) { assertTrue("Expcted to find a culprint " + culprit, false); } } }
@Test public void testTicket96() { final OntModel pellet = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); pellet.read(_base + "ticket-96-test-case.rdf"); assertTrue(pellet.validate().isValid()); }
JenaReasoner.printIterator(model.validate().getReports(), "Validation Results"); JenaReasoner.printIterator(model.validate().getReports(), "Validation Results"); JenaReasoner.printIterator(model.validate().getReports(), "Validation Results");
/** * Layering one reasoner on another leads to exposed functors which * used to trip up validation */ public void testLayeredValidation() { Model ont = FileManager.get().loadModel("testing/reasoners/bugs/layeredValidation.owl"); InfModel infModel = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), ont); OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, infModel); ValidityReport validity = model.validate(); assertTrue(validity.isClean()); }
/** * Test change of RDF specs to allow plain literals w/o lang and XSD string to be the same. */ public void testLiteralBug() { Model model = FileManager.get().loadModel("file:testing/reasoners/bugs/dtValidation.owl"); // Model m = ModelFactory.createDefaultModel(); Reasoner r = ReasonerRegistry.getOWLReasoner(); InfModel infmodel = ModelFactory.createInfModel(r, model); ValidityReport validity = infmodel.validate(); assertTrue (validity.isValid()); }
JenaReasoner.printIterator(model.validate().getReports(), "Validation Results"); JenaReasoner.printIterator(model.validate().getReports(), "Validation Results"); JenaReasoner.printIterator(model.validate().getReports(), "Validation Results");
/** * Layering one reasoner on another leads to exposed functors which * used to trip up validation */ public void testLayeredValidation() { Model ont = FileManager.get().loadModel("testing/reasoners/bugs/layeredValidation.owl"); InfModel infModel = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), ont); OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, infModel); ValidityReport validity = model.validate(); assertTrue(validity.isClean()); }
/** illustrate validation */ public void test2(String fname) { System.out.println("Testing " + fname); Model data = FileManager.get().loadModel(fname); InfModel infmodel = ModelFactory.createRDFSModel(data); ValidityReport validity = infmodel.validate(); if (validity.isValid()) { System.out.println("OK"); } else { System.out.println("Conflicts"); for (Iterator<Report> i = validity.getReports(); i.hasNext(); ) { ValidityReport.Report report = i.next(); System.out.println(" - " + report); // System.out.println(" - " + i.next()); } } }
/** * Test change of RDF specs to allow plain literals w/o lang and XSD string to be the same. */ public void testLiteralBug() { Model model = FileManager.get().loadModel("file:testing/reasoners/bugs/dtValidation.owl"); // Model m = ModelFactory.createDefaultModel(); Reasoner r = ReasonerRegistry.getOWLReasoner(); InfModel infmodel = ModelFactory.createInfModel(r, model); ValidityReport validity = infmodel.validate(); assertTrue (validity.isValid()); }
@Override public void runTest() { ValidityReport report = testResults(); switch (expected) { case INCONSISTENT: assertTrue("expected inconsistent", !report.isValid()); break; case WARNINGS: assertTrue("expected just warnings but reports not valid", report .isValid()); assertFalse("expected warnings but reports clean", report.isClean()); break; case CLEAN: assertTrue("expected clean", report.isClean()); } if (culprit != null) { boolean foundit = false; for (Iterator<Report> i = report.getReports(); i.hasNext();) { ValidityReport.Report r = i.next(); if (r.getExtension() != null && r.getExtension().equals(culprit)) { foundit = true; break; } } if (!foundit) { assertTrue("Expcted to find a culprint " + culprit, false); } } }
public static void usageWithOntModel() { System.out.println("Results with OntModel"); 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 an empty ontology model using Pellet spec final OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); // read the file model.read(ont); // print validation report final ValidityReport report = model.validate(); printIterator(report.getReports(), "Validation Results"); // print superclasses using the utility function final OntClass c = model.getOntClass(ns + "MaleStudentWith3Daughters"); printIterator(c.listSuperClasses(), "All super classes of " + c.getLocalName()); // OntClass provides function to print *only* the direct subclasses printIterator(c.listSuperClasses(true), "Direct superclasses of " + c.getLocalName()); System.out.println(); }
/** illustrate validation */ public void test2(String fname) { System.out.println("Testing " + fname); Model data = FileManager.get().loadModel(fname); InfModel infmodel = ModelFactory.createRDFSModel(data); ValidityReport validity = infmodel.validate(); if (validity.isValid()) { System.out.println("OK"); } else { System.out.println("Conflicts"); for (Iterator<Report> i = validity.getReports(); i.hasNext(); ) { ValidityReport.Report report = i.next(); System.out.println(" - " + report); // System.out.println(" - " + i.next()); } } }
/** * Run a single consistency test on the given data file. */ private boolean doTestOn(String dataFile) { // System.out.println("Test: " + dataFile); Model data = FileManager.get().loadModel(dataFile); InfModel infmodel = ModelFactory.createInfModel(makeReasoner(), data); ValidityReport reportList = infmodel.validate(); /* Debug only if (reportList.isValid()) { System.out.println("No reported problems"); } else { for (Iterator i = reportList.getReports(); i.hasNext(); ) { ValidityReport.Report report = (ValidityReport.Report)i.next(); System.out.println("- " + report); } } */ return reportList.isValid(); } }
public static void usageWithOntModel() { System.out.println("Results with OntModel"); 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 an empty ontology model using Pellet spec final OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); // read the file model.read(ont); // print validation report final ValidityReport report = model.validate(); printIterator(report.getReports(), "Validation Results"); // print superclasses using the utility function final OntClass c = model.getOntClass(ns + "MaleStudentWith3Daughters"); printIterator(c.listSuperClasses(), "All super classes of " + c.getLocalName()); // OntClass provides function to print *only* the direct subclasses printIterator(c.listSuperClasses(true), "Direct superclasses of " + c.getLocalName()); System.out.println(); }
/** * Helper for dt range testing - loads a file, validates it using RDFS/DT * and returns error status of the result */ private boolean doTestRDFSDTRange(String file, ReasonerFactory rf) throws IOException { String langType = "RDF/XML"; if (file.endsWith(".nt")) { langType = "N-TRIPLE"; } else if (file.endsWith("n3")) { langType = "N3"; } Model m = ModelFactory.createDefaultModel(); Reader reader = new BufferedReader(new FileReader("testing/reasoners/rdfs/"+file)); m.read(reader, WGReasonerTester.BASE_URI + file, langType); InfGraph g = rf.create(null).bind(m.getGraph()); ValidityReport report = g.validate(); if (!report.isValid()) { logger.debug("Validation error report:"); for (Iterator<Report> i = report.getReports(); i.hasNext(); ) { logger.debug(i.next().toString()); } } return report.isValid(); }
/** * Run a single consistency test on the given data file. */ private boolean doTestOn(String dataFile) { // System.out.println("Test: " + dataFile); Model data = FileManager.get().loadModel(dataFile); InfModel infmodel = ModelFactory.createInfModel(makeReasoner(), data); ValidityReport reportList = infmodel.validate(); /* Debug only if (reportList.isValid()) { System.out.println("No reported problems"); } else { for (Iterator i = reportList.getReports(); i.hasNext(); ) { ValidityReport.Report report = (ValidityReport.Report)i.next(); System.out.println("- " + report); } } */ return reportList.isValid(); } }
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(); }
/** * Helper for dt range testing - loads a file, validates it using RDFS/DT * and returns error status of the result */ private boolean doTestRDFSDTRange(String file, ReasonerFactory rf) throws IOException { String langType = "RDF/XML"; if (file.endsWith(".nt")) { langType = "N-TRIPLE"; } else if (file.endsWith("n3")) { langType = "N3"; } Model m = ModelFactory.createDefaultModel(); Reader reader = new BufferedReader(new FileReader("testing/reasoners/rdfs/"+file)); m.read(reader, WGReasonerTester.BASE_URI + file, langType); InfGraph g = rf.create(null).bind(m.getGraph()); ValidityReport report = g.validate(); if (!report.isValid()) { logger.debug("Validation error report:"); for (Iterator<Report> i = report.getReports(); i.hasNext(); ) { logger.debug(i.next().toString()); } } return report.isValid(); }
/** * Test problem with bindSchema not interacting properly with validation. */ public void testBindSchemaValidate() { Reasoner reasoner = ReasonerRegistry.getOWLReasoner(); Model schema = FileManager.get().loadModel("file:testing/reasoners/bugs/sbug.owl"); Model data = FileManager.get().loadModel("file:testing/reasoners/bugs/sbug.rdf"); // Union version InfModel infu = ModelFactory.createInfModel(reasoner, data.union(schema)); ValidityReport validity = infu.validate(); assertTrue( ! validity.isValid()); // debug print // for (Iterator i = validity.getReports(); i.hasNext(); ) { // System.out.println(" - " + i.next()); // } // bindSchema version InfModel inf = ModelFactory.createInfModel(reasoner.bindSchema(schema), data); validity = inf.validate(); assertTrue( ! validity.isValid()); }