String ns = "urn:test:";
OntModel reasoner = ModelFactory.createOntologyModel( PelletReasonerFactory.THE_SPEC );
ObjectProperty p = reasoner.createObjectProperty( ns + "p" );
ObjectProperty subP = reasoner.createObjectProperty( ns + "subP" );
ObjectProperty subSubP = reasoner.createObjectProperty( ns + "subSubP" );
DatatypeProperty q = reasoner.createDatatypeProperty( ns + "q" );
DatatypeProperty subQ = reasoner.createDatatypeProperty( ns + "subQ" );
DatatypeProperty subSubQ = reasoner.createDatatypeProperty( ns + "subSubQ" );
// create assertions in one RDF model
Model assertions = ModelFactory.createDefaultModel();
assertions.add( subP, RDFS.subPropertyOf, p );
assertions.add( subSubP, RDFS.subPropertyOf, subP );
assertions.add( subQ, RDFS.subPropertyOf, q );
assertions.add( subSubQ, RDFS.subPropertyOf, subQ );
// load the assertions to the reasoner
reasoner.add( assertions );
// create the inferences for testing in a separate RDF model
Model inferences = ModelFactory.createDefaultModel();
// all assertions should be inferred
inferences.add( assertions );
// rdfs:subPropertyOf is reflexive
for( Property op : new Property[] { p, subP, subSubP, q, subQ, subSubQ } ) {
inferences.add( op, RDFS.subPropertyOf, op );
}
// All object properties are a sub property of topObjectProperty
for( Property op : new Property[] { p, subP, subSubP, OWL2.topObjectProperty, OWL2.bottomObjectProperty } ) {
inferences.add( op, RDFS.subPropertyOf, OWL2.topObjectProperty );
inferences.add( OWL2.bottomObjectProperty, RDFS.subPropertyOf, op );
}
// All data properties are a sub property of topDataProperty
for( Property dp: new Property[] { q, subQ, subSubQ, OWL2.topDataProperty, OWL2.bottomDataProperty } ) {
inferences.add( dp, RDFS.subPropertyOf, OWL2.topDataProperty );
inferences.add( OWL2.bottomDataProperty, RDFS.subPropertyOf, dp );
}
// the real inferred relations
inferences.add( subSubP, RDFS.subPropertyOf, p );
inferences.add( subSubQ, RDFS.subPropertyOf, q );
// check if all inferences hold
assertPropertyValues( reasoner, RDFS.subPropertyOf, inferences );
// check for direct sub-properties
assertIteratorValues( p.listSubProperties( true ), new RDFNode[] { subP } );
assertIteratorValues( subP.listSuperProperties( true ), new RDFNode[] { p } );
assertIteratorValues( subP.listSubProperties( true ), new RDFNode[] { subSubP } );
assertIteratorValues( subSubP.listSuperProperties( true ), new RDFNode[] { subP } );
assertIteratorValues( q.listSubProperties( true ), new RDFNode[] { subQ } );
assertIteratorValues( subQ.listSuperProperties( true ), new RDFNode[] { q } );
assertIteratorValues( subQ.listSubProperties( true ), new RDFNode[] { subSubQ } );
assertIteratorValues( subSubQ.listSuperProperties( true ), new RDFNode[] { subQ } );