Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ontology iri fix for owl api version 4 #1117

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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