Skip to content

Commit

Permalink
Fixed ontology iri parsing (version5) 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 fix is based on the PR for version4 owlcs#1117

Signed-off-by: Victor Chavez <[email protected]>
  • Loading branch information
vChavezB authored and mnamici committed Apr 23, 2024
1 parent 0b0a388 commit a46e420
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ public class OWLRDFConsumer
* IRIs that had a type triple to owl:Ontology
*/
private final Set<IRI> ontologyIRIs = createSet();
/** IRIs that represent a subject for predicate owl:imports */
private final Set<IRI> ontologySubImportIRIs = createSet();
/**
* IRIs that had a type triple to owl:Restriction
*/
Expand Down Expand Up @@ -1467,7 +1469,8 @@ private void chooseAndSetOntologyIRI() {
// Choose one that isn't the object of an annotation assertion
Set<IRI> candidateIRIs = createSet(ontologyIRIs);
ontology.annotations().forEach(a -> a.getValue().asIRI().ifPresent(iri -> {
if (ontologyIRIs.contains(iri)) {
if (ontologyIRIs.contains(iri)
&& !ontologySubImportIRIs.contains(iri)) {
candidateIRIs.remove(iri);
}
}));
Expand Down Expand Up @@ -2212,14 +2215,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 @@ -1546,7 +1546,7 @@ public boolean canHandleStreaming(IRI s, IRI p, IRI o) {
@Override
public void handleTriple(IRI s, IRI p, IRI o) {
consume(s, p, o);
consumer.addOntology(s);
consumer.addOntology(s, true);
consumer.addOntology(o);
OWLImportsDeclaration id = df.getOWLImportsDeclaration(o);
consumer.addImport(id);
Expand Down

0 comments on commit a46e420

Please sign in to comment.