Skip to content

Commit b1768cd

Browse files
Victor Chavezignazio1977
authored andcommitted
Fixed ontology iri parsing when annotation imports same iri
This fix adds a condition to check whether the parsed IRIs are used as subject for the owl#imports. This fixes #1080 for owl api version 5.
1 parent 4c92e01 commit b1768cd

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

parsers/src/main/java/org/semanticweb/owlapi/rdf/rdfxml/parser/OWLRDFConsumer.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ public class OWLRDFConsumer
245245
* IRIs that had a type triple to owl:Ontology
246246
*/
247247
private final Set<IRI> ontologyIRIs = createSet();
248+
/**
249+
* IRIs that represent a subject for predicate owl:imports
250+
*/
251+
private final Set<IRI> ontologySubImportIRIs = createSet();
248252
/**
249253
* IRIs that had a type triple to owl:Restriction
250254
*/
@@ -1467,7 +1471,7 @@ private void chooseAndSetOntologyIRI() {
14671471
// Choose one that isn't the object of an annotation assertion
14681472
Set<IRI> candidateIRIs = createSet(ontologyIRIs);
14691473
ontology.annotations().forEach(a -> a.getValue().asIRI().ifPresent(iri -> {
1470-
if (ontologyIRIs.contains(iri)) {
1474+
if (ontologyIRIs.contains(iri)&& !ontologySubImportIRIs.contains(iri)) {
14711475
candidateIRIs.remove(iri);
14721476
}
14731477
}));
@@ -2212,13 +2216,27 @@ protected void addFirst(IRI subject, OWLLiteral object) {
22122216
* Adds the ontology.
22132217
*
22142218
* @param iri the iri
2219+
* @param owlImportSubject Is the iri used as subject for predicate
2220+
* owl:imports
22152221
*/
2216-
protected void addOntology(IRI iri) {
2222+
protected void addOntology(IRI iri, boolean owlImportSubject) {
22172223
if (ontologyIRIs.isEmpty()) {
22182224
firstOntologyIRI = iri;
22192225
}
2226+
if (owlImportSubject) {
2227+
ontologySubImportIRIs.add(iri);
2228+
}
22202229
ontologyIRIs.add(iri);
22212230
}
2231+
/**
2232+
* Overload method of addOntology with
2233+
* no owl:import subject iri
2234+
*
2235+
* @param iri the iri
2236+
*/
2237+
protected void addOntology(IRI iri) {
2238+
addOntology(iri, false);
2239+
}
22222240

22232241
/**
22242242
* Adds the ontology version.

parsers/src/main/java/org/semanticweb/owlapi/rdf/rdfxml/parser/TripleHandlers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ public boolean canHandleStreaming(IRI s, IRI p, IRI o) {
15461546
@Override
15471547
public void handleTriple(IRI s, IRI p, IRI o) {
15481548
consume(s, p, o);
1549-
consumer.addOntology(s);
1549+
consumer.addOntology(s, true);
15501550
consumer.addOntology(o);
15511551
OWLImportsDeclaration id = df.getOWLImportsDeclaration(o);
15521552
consumer.addImport(id);

0 commit comments

Comments
 (0)