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"); } }
/** 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()); } } }
/** 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()); } } }
/** * 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(); }
/** * 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 public void testTicket96() { final OntModel pellet = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); pellet.read(_base + "ticket-96-test-case.rdf"); assertTrue(pellet.validate().isValid()); }
/** * 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()); }
/** * 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()); }
private RDFNode doTestLiteralsInErrorReports(String rules) { GenericRuleReasoner reasoner = new GenericRuleReasoner( Rule.parseRules(rules) ); InfModel im = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel()); ValidityReport validity = im.validate(); assertTrue (! validity.isValid()); ValidityReport.Report report = (validity.getReports().next()); assertTrue( report.getExtension() instanceof RDFNode); return (RDFNode)report.getExtension(); }
/** * 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(); } }
/** * 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(); } }
private RDFNode doTestLiteralsInErrorReports(String rules) { GenericRuleReasoner reasoner = new GenericRuleReasoner( Rule.parseRules(rules) ); InfModel im = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel()); ValidityReport validity = im.validate(); assertTrue (! validity.isValid()); ValidityReport.Report report = (validity.getReports().next()); assertTrue( report.getExtension() instanceof RDFNode); return (RDFNode)report.getExtension(); }
/** * 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()); }
/** * 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()); }
@Test public void testDataPropCard2() { final String ns = "urn:test:"; final OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); final DatatypeProperty prop = model.createDatatypeProperty(ns + "prop"); final OntClass C = model.createClass(ns + "C"); C.addSuperClass(model.createCardinalityRestriction(null, prop, 2)); final Individual x = model.createIndividual(ns + "x", C); x.addProperty(prop, "literal1"); x.addProperty(prop, "literal2"); x.addProperty(prop, "literal3"); assertTrue(!model.validate().isValid()); }
private void doTestDatatypeRangeValidation(RDFDatatype over12Type, OntModelSpec spec) { String NS = "http://jena.hpl.hp.com/example#"; OntModel ont = ModelFactory.createOntologyModel(spec); Resource over12 = ont.createResource( over12Type.getURI() ); DatatypeProperty hasValue = ont.createDatatypeProperty(NS + "hasValue"); hasValue.addRange( over12 ); ont.createResource(NS + "a").addProperty(hasValue, "15", over12Type); ont.createResource(NS + "b").addProperty(hasValue, "16", XSDDatatype.XSDinteger); ont.createResource(NS + "c").addProperty(hasValue, "10", XSDDatatype.XSDinteger); ValidityReport validity = ont.validate(); assertTrue (! validity.isValid()); // Check culprit reporting ValidityReport.Report report = (validity.getReports().next()); Triple culprit = (Triple)report.getExtension(); assertEquals(culprit.getSubject().getURI(), NS + "c"); assertEquals(culprit.getPredicate(), hasValue.asNode()); }
private void doTestDatatypeRangeValidation(RDFDatatype over12Type, OntModelSpec spec) { String NS = "http://jena.hpl.hp.com/example#"; OntModel ont = ModelFactory.createOntologyModel(spec); Resource over12 = ont.createResource( over12Type.getURI() ); DatatypeProperty hasValue = ont.createDatatypeProperty(NS + "hasValue"); hasValue.addRange( over12 ); ont.createResource(NS + "a").addProperty(hasValue, "15", over12Type); ont.createResource(NS + "b").addProperty(hasValue, "16", XSDDatatype.XSDinteger); ont.createResource(NS + "c").addProperty(hasValue, "10", XSDDatatype.XSDinteger); ValidityReport validity = ont.validate(); assertTrue (! validity.isValid()); // Check culprit reporting ValidityReport.Report report = (validity.getReports().next()); Triple culprit = (Triple)report.getExtension(); assertEquals(culprit.getSubject().getURI(), NS + "c"); assertEquals(culprit.getPredicate(), hasValue.asNode()); }
@Test public void testSubDataPropCard() { final String ns = "urn:test:"; final OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); final DatatypeProperty prop = model.createDatatypeProperty(ns + "prop"); final DatatypeProperty sub = model.createDatatypeProperty(ns + "sub"); sub.addSuperProperty(prop); final OntClass C = model.createClass(ns + "C"); C.addSuperClass(model.createCardinalityRestriction(null, prop, 2)); final Individual x = model.createIndividual(ns + "x", C); final Literal val1 = model.createLiteral("val1"); x.addProperty(prop, val1); final Literal val2 = model.createLiteral("val2"); x.addProperty(sub, val2); assertTrue(model.validate().isValid()); assertPropertyValues(model, x, prop, val1, val2); }
@Test public void testUserDefinedFloatDatatypes() { final String ns = "http://www.lancs.ac.uk/ug/dobsong/owl/float_test.owl#"; final OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); model.read(_base + "float_test.owl"); model.prepare(); assertTrue(model.validate().isValid()); final OntClass ThingWithFloatValue = model.getOntClass(ns + "ThingWithFloatValue"); final OntClass ThingWithFloatProbability = model.getOntClass(ns + "ThingWithProbabilityValue"); final Individual exampleThingWithFloatValue = model.getIndividual(ns + "exampleThingWithFloatValue"); final Individual exampleThingWithFloatProbability = model.getIndividual(ns + "exampleThingWithProbabilityValue"); assertTrue(ThingWithFloatValue.hasSubClass(ThingWithFloatProbability)); assertTrue(!ThingWithFloatProbability.hasSubClass(ThingWithFloatValue)); assertTrue(exampleThingWithFloatValue.hasRDFType(ThingWithFloatValue)); assertTrue(!exampleThingWithFloatValue.hasRDFType(ThingWithFloatProbability)); assertTrue(exampleThingWithFloatProbability.hasRDFType(ThingWithFloatValue)); assertTrue(exampleThingWithFloatProbability.hasRDFType(ThingWithFloatProbability)); }
@Test public void testUserDefinedDecimalDatatypes() { final String ns = "http://www.lancs.ac.uk/ug/dobsong/owl/decimal_test.owl#"; final OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); model.read(_base + "decimal_test.owl"); model.prepare(); assertTrue(model.validate().isValid()); final OntClass ThingWithDecimalValue = model.getOntClass(ns + "ThingWithDecimalValue"); final OntClass ThingWithDecimalProbability = model.getOntClass(ns + "ThingWithDecimalProbability"); final OntClass ThingWithIntegerValue = model.getOntClass(ns + "ThingWithIntegerValue"); final Individual exampleThingWithDecimalValue = model.getIndividual(ns + "exampleThingWithDecimalValue"); final Individual exampleThingWithDecimalProbability = model.getIndividual(ns + "exampleThingWithDecimalProbability"); assertTrue(ThingWithDecimalValue.hasSubClass(ThingWithIntegerValue)); assertTrue(ThingWithDecimalValue.hasSubClass(ThingWithDecimalProbability)); assertTrue(exampleThingWithDecimalValue.hasRDFType(ThingWithDecimalValue)); assertTrue(exampleThingWithDecimalProbability.hasRDFType(ThingWithIntegerValue)); assertTrue(exampleThingWithDecimalProbability.hasRDFType(ThingWithDecimalProbability)); assertTrue(exampleThingWithDecimalProbability.hasRDFType(ThingWithDecimalValue)); assertTrue(!ThingWithDecimalValue.hasSuperClass(ThingWithIntegerValue)); assertTrue(!ThingWithIntegerValue.hasSubClass(ThingWithDecimalProbability)); }