I have created an Ontology which i want use for validating instances, following is the test setup i have, couldnt get validation report one of uid is zero. which is xsd:minExclusive "0"^^xsd:unsignedLong.
Can anyone help m eunderstand best practice to use Jena, i am inteding to sue default model to recieve an input validating aginast ontModel and the merging in TDB backed model.
:Book rdf:type owl:Class ;
rdfs:subClassOf Model .
and data Property
:uid rdf:type owl:DatatypeProperty ,
owl:FunctionalProperty ;
rdfs:domain :Model ;
rdfs:range [ rdf:type rdfs:Datatype ;
owl:onDatatype xsd:unsignedLong ;
owl:withRestrictions ( [ xsd:minExclusive "0"^^xsd:unsignedLong
]
)
] .
Trying to use this ontology to validate data
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
ontModel.read(getClass().getClassLoader().getResource("model.owl").toExternalForm(), NS);
// ontModel.write(System.out);
Reasoner reasoner = ontModel.getReasoner().bindSchema(ontModel);
Model data = createTestData();
//data.write(System.out);
InfModel infModel = ModelFactory.createInfModel(reasoner, data);
ValidityReport report = infModel.validate();
if (report.isValid())
System.out.println("valid");
and in the following code //(index - 1) ensure at least one id of 0
public static Model createTestData() {
Model instances = ModelFactory.createDefaultModel();
instances.setNsPrefix("rdfs", RDFS.getURI());
instances.setNsPrefix("rdf", RDF.getURI());
instances.setNsPrefix("a", NS);
instances.setNsPrefix("", NS + "#");
Property UID_PROPERTY = ResourceFactory.createProperty(NS + "#uid");
IntStream.of(1, 2, 3).forEach(index -> {
Resource r = instances.createResource(NS + "/item/" + (index - 1));
r.addProperty(UID_PROPERTY, ResourceFactory.createTypedLiteral((index - 1)));
});
return instances;
}