@Override public ValidityReport validate() { return inner.validate(); }
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(); }
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(); }
@Test public void testTicket96() { final OntModel pellet = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); pellet.read(_base + "ticket-96-test-case.rdf"); assertTrue(pellet.validate().isValid()); }
/** * 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()); }
/** * 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 public void testDatatypeProperties() { final String ns = "urn:test:"; final OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); final OntClass Person = model.createClass(ns + "Person"); final Individual john = model.createIndividual(ns + "JohnDoe", Person); final DatatypeProperty email = model.createDatatypeProperty(ns + "email", false); john.addProperty(email, "john.doe@unknown.org"); john.addProperty(email, "jdoe@unknown.org"); assertTrue(model.validate().isValid()); assertIteratorValues(model.listSubjectsWithProperty(email, "john.doe@unknown.org"), new Resource[] { john }); assertTrue(model.contains(null, email, "john.doe@unknown.org")); assertTrue(!model.contains(null, email, john)); assertTrue(model.validate().isValid()); final DatatypeProperty name1 = model.createDatatypeProperty(ns + "name1", true); john.addProperty(name1, "Name", "en"); john.addProperty(name1, "Nom", "fr"); // assertTrue(model.validate().isValid()); // TODO : reactivate in a future version of JENA, when the bug will be fix. final DatatypeProperty name2 = model.createDatatypeProperty(ns + "name2", true); john.addProperty(name2, "Name"); john.addProperty(name2, "Nom"); assertTrue(!model.validate().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()); }
ind.addProperty(p, value); assertFalse(value.getLexicalForm() + " should not belong to " + datatype.getLocalName(), model.validate().isValid()); i++;
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 testBuiltinDatatypesWithValidValues() { final String ns = "urn:test:"; final Object[] datatypes = { XSD.anyURI, "http://www.w3.com", "\nhttp://www.w3.com\r", XSD.xboolean, "true", "1", "\ntrue", XSD.xbyte, "8", "\t\r\n8 ", XSD.date, "2004-03-15", XSD.dateTime, "2003-12-25T08:30:00", "2003-12-25T08:30:00.001", "2003-12-25T08:30:00-05:00", "2003-12-25T08:30:00Z", XSD.decimal, "3.1415292", XSD.xdouble, "3.1415292", "INF", "NaN", XSD.duration, "P8M3DT7H33M2S", "P1Y", "P1M", "P1Y2MT2H", XSD.xfloat, "3.1415292", "-1E4", "12.78e-2", "INF", "NaN", XSD.gDay, "---11", XSD.gMonth, "--02", XSD.gMonthDay, "--02-14", XSD.gYear, "0001", "1999", XSD.gYearMonth, "1972-08", XSD.xint, "77", XSD.integer, "77", XSD.xlong, "214", XSD.negativeInteger, "-123", XSD.nonNegativeInteger, "2", XSD.nonPositiveInteger, "0", XSD.positiveInteger, "500", XSD.xshort, "476", XSD.xstring, "Test", XSD.time, "13:02:00", }; final OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); final Individual ind = model.createIndividual(ns + "test", OWL.Thing); for (int i = 0; i < datatypes.length;) { final Resource datatype = (Resource) datatypes[i++]; final OntProperty p = model.createDatatypeProperty(ns + "prop_" + datatype.getLocalName()); p.addRange(datatype); while (i < datatypes.length && datatypes[i] instanceof String) { final Literal value = model.createTypedLiteral((String) datatypes[i], datatype.getURI()); ind.addProperty(p, value); i++; } } model.prepare(); 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()); }
@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 testSimpleTypeAssertion() { final String ns = "urn:test:"; final OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); // add one instance relation final OntClass cls = model.createClass(ns + "C"); final Individual a = model.createIndividual(ns + "a", cls); // load everything and check consistency assertTrue(model.validate().isValid()); // add a type relation for an existing _individual a.addRDFType(cls); // verify instance relation assertTrue(model.contains(a, RDF.type, cls)); assertIteratorValues(cls.listInstances(false), new Resource[] { a }); // check for direct types to make sure we don't get results from base // graph assertIteratorValues(cls.listInstances(true), new Resource[] { a }); // add a new instance relation to a new _individual final Individual b = model.createIndividual(ns + "b", cls); // verify inference assertTrue(model.contains(b, RDF.type, cls)); assertIteratorValues(cls.listInstances(false), new Resource[] { a, b }); // check for direct types to make sure we don't get results from base // graph assertIteratorValues(cls.listInstances(true), new Resource[] { a, b }); }
@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)); }