Skip to content

Commit

Permalink
Fixed ontology iri parsing when annotation imports same iri
Browse files Browse the repository at this point in the history
This fix adds a condition to check wether the parsed IRIs
are used as subject for the owl#imports. This fixes #1080
for owl api version 4.

Signed-off-by: Victor Chavez <chavez-bermudez@fh-aachen.de>
  • Loading branch information
Victor Chavez authored and ignazio1977 committed Mar 10, 2024
1 parent c5c2bd2 commit fff1319
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ public class OWLRDFConsumer
private final Map<IRI, IRI> ontologyVersions = new HashMap<>();
/** IRIs that had a type triple to owl:Ontology */
private final Set<IRI> ontologyIRIs;
/** IRIs that represent a subject for predicate owl:imports */
private final Set<IRI> ontologySubImportIRIs;
/** IRIs that had a type triple to owl:Restriction */
private final Set<IRI> restrictionIRIs;
/** Maps rdf:next triple subjects to objects */
Expand Down Expand Up @@ -294,6 +296,7 @@ public OWLRDFConsumer(@Nonnull OWLOntology ontology, @Nonnull AnonymousNodeCheck
propertyIRIs = CollectionFactory.createSet();
restrictionIRIs = CollectionFactory.createSet();
ontologyIRIs = CollectionFactory.createSet();
ontologySubImportIRIs = CollectionFactory.createSet();
listFirstLiteralTripleMap = CollectionFactory.createMap();
listFirstResourceTripleMap = CollectionFactory.createMap();
listRestTripleMap = CollectionFactory.createMap();
Expand Down Expand Up @@ -1467,7 +1470,8 @@ private void chooseAndSetOntologyIRI() {
for (OWLAnnotation anno : ontology.getAnnotations()) {
if (anno.getValue() instanceof IRI) {
IRI iri = (IRI) anno.getValue();
if (ontologyIRIs.contains(iri)) {
if (ontologyIRIs.contains(iri)
&& !ontologySubImportIRIs.contains(iri)) {
candidateIRIs.remove(iri);
}
}
Expand Down Expand Up @@ -2285,15 +2289,29 @@ protected void addFirst(IRI subject, OWLLiteral object) {

/**
* Adds the ontology.
*
*
* @param iri the iri
* @param owlImportSubject Is the iri used as subject for predicate
* owl:imports
*/
protected void addOntology(IRI iri) {
protected void addOntology(IRI iri, boolean owlImportSubject) {
if (ontologyIRIs.isEmpty()) {
firstOntologyIRI = iri;
}
if (owlImportSubject) {
ontologySubImportIRIs.add(iri);
}
ontologyIRIs.add(iri);
}
/**
* Overload method of addOntology with
* no owl:import subject iri
*
* @param iri the iri
*/
protected void addOntology(IRI iri) {
addOntology(iri, false);
}

/**
* Adds the ontology version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
@Override
public void handleTriple(IRI subject, IRI predicate, IRI object) {
consumeTriple(subject, predicate, object);
consumer.addOntology(subject);
consumer.addOntology(subject, true);
consumer.addOntology(object);
OWLImportsDeclaration importsDeclaration = df.getOWLImportsDeclaration(object);
consumer.addImport(importsDeclaration);
Expand Down

0 comments on commit fff1319

Please sign in to comment.