ncbo / owlapi_wrapper

A command line utility that wraps the Java OWL-API to parse RDFS, OWL and OBO ontologies.
5 stars 9 forks source link

Save and copy Ontology IRI of parsed ontologies #17

Closed syphax-bouazzouni closed 2 years ago

syphax-bouazzouni commented 2 years ago

Issue

The issue is that when the owlapi_wrapper parse an ontology doesn't copy the original IRI and just creates anonymous ontology

You can test it using this

String outputRepositoryFolder = "./src/test/resources/repo/output/cno";
ParserInvocation pi = new ParserInvocation("./src/test/resources/repo/input/cno",
outputRepositoryFolder, "cnov0_5.owl", true);
assertTrue(pi.valid());

OntologyParser parser = new OntologyParser(pi);
assertTrue(parser.parse());
assertEquals(1, parser.getLocalOntologies().size());

IRI targetIRI = parser.getTargetOwlOntology().getOntologyID().getOntologyIRI().orNull();
IRI sourceIRI = parser.getParsedOntologies().stream().findFirst().get().getOntologyID().getOntologyIRI().orNull();
assertNotNull(targetIRI);
assertEquals(sourceIRI, targetIRI);

In the original file, we have

 <owl:Ontology rdf:about="http://purl.org/incf/ontology/Computational_Neurosciences/cno_alpha.owl">
        <dc:date rdf:datatype="&xsd;string">13/03/2012</dc:date>
        <dc:subject rdf:datatype="&xsd;string">An ontology to describe the field of Computational Neurosciences</dc:subject>
        <dc:contributor rdf:datatype="&xsd;string">Birgit Kriener</dc:contributor>

The created file contains the following (does not more contain the rdf:about)

<owl:Ontology >
        <dc:contributor rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Alan Ruttenberg</dc:contributor>
        <dc:contributor rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Andrew Spear</dc:contributor>
        <dc:contributor rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Birgit Kriener</dc:contributor>
        <dc:contributor rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Erik De Schutter</dc:contributor>
        <dc:contributor rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Fahim T. Imam</dc:contributor>

Solution

This PR, by just adding these lines

Optional<IRI> ontologyIRI = sourceOnt.getOntologyID().getOntologyIRI();
Optional<IRI> versionIRI =  sourceOnt.getOntologyID().getVersionIRI();
if (ontologyIRI.isPresent()) {
        OWLOntologyID newOntologyID = new OWLOntologyID(ontologyIRI, versionIRI);
    SetOntologyID setOntologyID = new SetOntologyID(targetOwlOntology, newOntologyID);
    this.targetOwlManager.applyChange(setOntologyID);
}

Why do we need the ontology IRI

https://github.com/ncbo/ontologies_linked_data/issues/152

syphax-bouazzouni commented 2 years ago

Hi @jvendetti , thanks for the reviews. I have just answered them.