Search code examples
javajenaontologyprotege

Apache Jena automatically merge object properties together


I am very new in using Apache Jena. I am facing a problem here.

I designed an RDF file using Protege. Basically, I have three object properties which are ASSOCIATION, AGGREGATION, & COMPOSITION. Both AGGREGATION & COMPOSITION are sub property of ASSOCIATION. As you can here from Protege these three objects are generated nicely together.

However when I use Jena with Java (below is my code), the output generated is different from the expected outcome.

Model m = ModelFactory.createDefaultModel(); String NS = "http://example.com/test/";

  OntModel ontoModel = >ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);     

  ObjectProperty ASSOCIATION = ontoModel.createObjectProperty(NS + >"ASSOCIATION");
  ObjectProperty AGGREGATION = ontoModel.createObjectProperty(NS + >"AGGREGATION");
  AGGREGATION.addProperty(RDFS.subPropertyOf, ASSOCIATION);
  ObjectProperty COMPOSITION = ontoModel.createObjectProperty(NS + >"COMPOSITION");
  COMPOSITION.addProperty(RDFS.subPropertyOf, ASSOCIATION);

As you can see in the output generated:

1) The ASSOCIATION object property is nested below the AGGREGATION & COMPOSITION.

2) The way sub property of AGGREGATION & COMPOSITION is generated is different.

Any help here is very much appreciated.

Expected output generated from Protege & output generated with Jena


Solution

  • The two RDF files you're showing are semantically equivalent. What you're seeing is a difference in ordering of the axioms. OWL does not define an order for the axiom serialization, so each library makes its own choices in this respect.

    Protege relies on OWL API for writing out the ontology, and OWL API sorts the axioms first by type and then by their content - in this case the IRI of the subproperty in the axioms first.

    Unless you're using some non-RDF-aware tool, or you're storing the ontologies in a version control system (where differences in ordering can cause large, unnecessary, diffs), you can ignore these differences. The code you're using is working as expected.