On Tue, Mar 5, 2013 at 3:20 AM, Vegard Vaage <vegard.va...@tv2.no> wrote: > I'm trying to verify instance data against an ontology using Jenas OWL > reasoner. Right now I'm just trying to verify that the input literals are of > the correct types and ranges, but later on I'll need more advanced > verification against the ontology. > I've been following the Jena OWL Reasoner example and come up with this: > > Reasoner reasoner = ReasonerRegistry.getOWLReasoner(); > Resource resource = IndividualMapper.mapResource(dataModel, data, uri); > InfModel infModel = ModelFactory.createInfModel(reasoner, schema, dataModel); > Resource clazz = infModel.getResource(uri); > if (infModel.contains(resource, RDF.type, clazz)) { > return true; > } > return false; > > But no matter how I define instance data I always get true as a return value. > The ontology is basically a single class using owl:restriction on a > datatypeProperty: > > <owl:DatatypeProperty rdf:about="http://snipped/#Id"> > <rdf:type rdf:resource="&owl;FunctionalProperty"/> > </owl:DatatypeProperty> > > <owl:Class rdf:about="http://snipped/#MyClass"> > <rdfs:label xml:lang="en">MyClass</rdfs:label> > <rdfs:subClassOf> > <owl:Restriction> > <owl:onProperty rdf:resource="http://snipped/#Id"/> > <owl:someValuesFrom rdf:resource="&xsd;long"/> > </owl:Restriction> > </rdfs:subClassOf> > </owl:Class> > > What am I doing wrong? See below for source code for the non-Jena stuff:
What sort of instance data are you providing? What result are you expecting that you aren't seeing? What result aren't you expecting that you are seeing? What exactly do you mean by validation? You said that you're trying to check that the "input literals are of the correct type and ranges". However, it looks like check that you're performing is to see whether individuals have a particular RDF type. Based on your ontology, I don't see any way to infer that something is a member of MyClass except through explicit assertion, although there are ways that you could infer that something *isn't* a MyClass, e.g., if it has a value for Id that's not a long. Here's some working code that recreates your ontology in an OntModel, adds some instance data containing some instances of MyClass and some individuals that are not known to be instances of MyClass, and displays the results. I don't think this is the solution to your problem, yet, but I think it will elicit the information about the problem that you're running into that will help a solution be found. import com.hp.hpl.jena.ontology.FunctionalProperty; import com.hp.hpl.jena.ontology.Individual; import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDF; public class Validation { public static void main( String[] args ) { // Create an ontology model like the one described String NS = "http://snipped/#"; OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM_RULE_INF ); OntClass myClass = model.createClass( NS+"myClass" ); FunctionalProperty id = model.createDatatypeProperty( NS+"Id" ).convertToFunctionalProperty(); Resource xsdLong = model.createResource( "http://www.w3.org/2001/XMLSchema#long" ); myClass.addSuperClass( model.createSomeValuesFromRestriction( null, id, xsdLong ) ); System.out.println( "===" ); model.write( System.out, "RDF/XML-ABBREV" ); // Create some instance data in another model Individual a = model.createIndividual( NS+"a", OWL.Thing ); Individual b = model.createIndividual( NS+"b", myClass ); Individual c = model.createIndividual( NS+"c", OWL.Thing ); Individual d = model.createIndividual( NS+"d", myClass ); System.out.println( "===" ); model.write( System.out, "RDF/XML-ABBREV" ); // Check some types System.out.println( "===" ); for ( Individual i : new Individual[]{ a, b, c, d } ) { System.out.println( i+" is"+(!model.contains( i, RDF.type, myClass )?" not":"")+" a member of "+myClass ); } } } //JT -- Joshua Taylor, http://www.cs.rpi.edu/~tayloj/