From dbde37a0779f7d7012cb6a97d9d455404b515987 Mon Sep 17 00:00:00 2001 From: Victor Chavez Date: Sun, 26 Nov 2023 02:24:42 +0100 Subject: [PATCH] Fixed ontology iri parsing when annotation imports same iri 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 --- .../rdf/rdfxml/parser/OWLRDFConsumer.java | 24 ++++++++++++++++--- .../rdf/rdfxml/parser/TripleHandlers.java | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/parsers/src/main/java/org/semanticweb/owlapi/rdf/rdfxml/parser/OWLRDFConsumer.java b/parsers/src/main/java/org/semanticweb/owlapi/rdf/rdfxml/parser/OWLRDFConsumer.java index 7b4925a1f6..f85b7dcd51 100644 --- a/parsers/src/main/java/org/semanticweb/owlapi/rdf/rdfxml/parser/OWLRDFConsumer.java +++ b/parsers/src/main/java/org/semanticweb/owlapi/rdf/rdfxml/parser/OWLRDFConsumer.java @@ -190,6 +190,8 @@ public class OWLRDFConsumer private final Map ontologyVersions = new HashMap<>(); /** IRIs that had a type triple to owl:Ontology */ private final Set ontologyIRIs; + /** IRIs that represent a subject for predicate owl:imports */ + private final Set ontologySubImportIRIs; /** IRIs that had a type triple to owl:Restriction */ private final Set restrictionIRIs; /** Maps rdf:next triple subjects to objects */ @@ -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(); @@ -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); } } @@ -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. diff --git a/parsers/src/main/java/org/semanticweb/owlapi/rdf/rdfxml/parser/TripleHandlers.java b/parsers/src/main/java/org/semanticweb/owlapi/rdf/rdfxml/parser/TripleHandlers.java index 94172c3eef..5d948e2784 100644 --- a/parsers/src/main/java/org/semanticweb/owlapi/rdf/rdfxml/parser/TripleHandlers.java +++ b/parsers/src/main/java/org/semanticweb/owlapi/rdf/rdfxml/parser/TripleHandlers.java @@ -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);