#327 TypeOntologyHandler/TPVersionIRIHandler overwrite ontologyID


The TypeOntologyHandler and the TPVersionIRIHandler combined have some strange behaviour with respect to the current ontology ID when importing an RDF/XML ontology multiple times.

My use case is to be able to import the same ontology multiple times, with the system intelligently modifying the version IRI to be unique each time before the import, but calling the following code twice with the same documentSource fails the second time when the uniqueOWLOntologyID has a different version IRI.

The ontology document in each case is identical, but that should not hamper the ability of the system to store a new version with a unique ontologyID if the ontologyVersionIRI is setup to be unique before the parse occurs. The first time through the code, the ontologyIRI and the ontologyVersionIRI both match the InputStream in the documentSource that is being parsed, while the second time through, the ontologyIRI matches, but the ontologyVersionIRI is setup to be unique. The ontologyManager is created fresh before the test, so it does not contain any other ontologies.

The ontology document (written in RDF/XML, so uses RDFXMLParser and OWLRDFConsumer) contains both ontology IRI in the form "<ontologyIRI> rdf:type owl:Ontology" and ontology version in the form <ontologyIRI> owl:versionIRI <ontologyVersionIRI>" The raw RDF/XML is as follows (if it doesn't get clobbered by SourceForge)

<?xml version="1.0"?>
<rdf:Description rdf:about="http://test.example.org/ontology/0139">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology" />
<owl:versionIRI rdf:resource="http://test.example.org/ontology/0139/version:1" />


The exceptions stack trace, before my patch was applied (using https://github.com/ansell/owlapi/tree/ansellpatches so the line numbers will not match up exactly) is:

OWLOntologyManagerImpl.checkForOntologyIDChange\(OWLOntologyChange\) line: 488  
OWLOntologyManagerImpl.enactChangeApplication\(OWLOntologyChange\) line: 379    
OWLOntologyManagerImpl.applyChanges\(List&lt;OWLOntologyChange&gt;\) line: 398  
OWLOntologyManagerImpl.applyChange\(OWLOntologyChange\) line: 435   
OWLRDFConsumer.applyChange\(OWLOntologyChange\) line: 959   
OWLRDFConsumer.setOntologyID\(OWLOntologyID\) line: 963 
TPVersionIRIHandler.handleTriple\(IRI, IRI, IRI\) line: 68  
OWLRDFConsumer.handle\(IRI, IRI, IRI\) line: 1315   
OWLRDFConsumer$1.handleResourceTriple\(IRI, IRI, IRI\) line: 1454   
OWLRDFConsumer.iterateResourceTriples\(ResourceTripleIterator&lt;E&gt;\) line: 2434 
OWLRDFConsumer.endModel\(\) line: 1452  
RDFXMLParser$1\(RDFParser\).parse\(InputSource, RDFConsumer\) line: 175 
RDFXMLParser.parse\(OWLOntologyDocumentSource, OWLOntology, OWLOntologyLoaderConfiguration\) line: 120  
RDFXMLParser.parse\(OWLOntologyDocumentSource, OWLOntology\) line: 74

The issue seems to have two causes. Firstly, the handleTriple method in TypeOntologyHandler is executed before TPVersionIRIHandler and removes the ontologyVersionIRI, and then the ontologyVersionIRI is also overwritten without verifying that the versionIRI is null in TPVersionIRIHandler anyway, so it looks like it would require both classes to be modified to fix the bug and preserve existing OntologyID's during parsing.

I am attaching a patch that fixed both of these issues for me, including tests to verify the desired behaviour in different scenarios.


  • Matthew Horridge

    Hi Peter,

    Any chance you can regenerate the patch? (Things have shifted about a lot since).



  • Peter Ansell

    Peter Ansell - 2012-08-22

    I have been rebasing the patch along with my other patches on GitHub, so it is still available, but it is behind another series of patches, in particular it is currently on top of the patch for 3521488 right now.

    The current commit URLs (which will change when I next rebase...) are:



    They should be recognisable in the history as I have prefixed their log messages with "3536150"

    I will clean the patches up, as they look quite ugly right now, and then rebase them directly onto the trunk tomorrow and upload them here as attachments. In particular, it looks like the patch currently adds owlapi-impl as a test dependency to owlapi-parsers. I will fix that up so that the tests are in the contract module with the rest of the tests.

  • Peter Ansell

    Peter Ansell - 2012-08-27

    I have updated the code at GitHub so that it is based directly onto the master branch.

    There are three additional patches attached to the branch that I add to make the tests compile and run and to avoid a warning in Eclipse, as some of the tests rely on java-1.6 for interface @Override, and some of the RDF contract tests were failing at runtime as they throw NPE's internally due to the use of mocks. There is also a patch for an unclosed InputStream in AutoIRIMapper that Eclipse gave me a warning for. Not sure if I should open another bug for it.

    You can view the changes at:


    You can download the patch at:


  • Ignazio Palmisano

    • status: open --> closed
  • Ignazio Palmisano

    I have applied this patch and will add the others as feature requests. Thanks for the contribution.

  • Peter Ansell

    Peter Ansell - 2012-10-10

    Was the following chunk of code in the patches that you applied? It is necessary to be able to recognise the version IRI even if it comes before the "ontologyIRI rdf:type owl:Ontology" triple. The comment is misleading, (hopefully that did not put you off!), but the point of switching to checking the predicate against owl:versionIRI in canHandle is to make sure that it comes through even if it is in the document before the rdf:type triple.

    <<<<<<< HEAD
    public boolean canHandle(IRI subject,
    IRI predicate,
    IRI object) {
    return subject.equals(getConsumer().getOntology().getOntologyID().getOntologyIRI());
    public boolean canHandle(IRI subject,
    IRI predicate,
    IRI object) {
    // If a user overrides the ontologyIRI, then they may want to also use this version, even if the ontologyIRI does not match
    return predicate.equals(OWLRDFVocabulary.OWL_VERSION_IRI.getIRI());
    //return subject.equals(getConsumer().getOntology().getOntologyID().getOntologyIRI());
    >>>>>>> 04bd3e9... 3536150 : fix bug with ontologyIRI and versionIRI loading ontology multiple times

  • Peter Ansell

    Peter Ansell - 2012-10-10
    • status: closed --> open
  • Ignazio Palmisano

    I have applied only the patch attached to this bug, didn't manage to look at the others linked yet.

    On a different topic, I need to find a way to get SourceForge to notify me about comments on bugs...

  • Ignazio Palmisano

    • assigned_to: nobody --> ignazio1977
  • Ignazio Palmisano

    I've applied the patches on github

  • Ignazio Palmisano

    • status: open --> closed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks