The functionality copyOntology(..) does not work correctly in case of cyclic imports and OntologyCopy.SHALLOW
sszuev opened this issue · 2 comments
sszuev commented
The testcase:
public static void main(String ... args) {
OntologyManager m1 = OntManagers.createONT();
Ontology a = m1.createOntology(IRI.create("A"));
Ontology b = m1.createOntology(IRI.create("B"));
a.asGraphModel().addImport(b.asGraphModel());
b.asGraphModel().addImport(a.asGraphModel());
testManager(m1);
OntologyManager m2 = OntManagers.createONT();
m1.ontologies().forEach(x -> m2.copyOntology(x, OntologyCopy.SHALLOW));
testManager(m2);
}
private static void testManager(OntologyManager m) {
Assert.assertEquals(2, m.ontologies().peek(x -> {
System.out.println("TEST: " + x);
Assert.assertEquals(2, Graphs.baseGraphs(((Ontology)x).asGraphModel().getGraph()).count());
}).count());
}
Additional info:
The method copyOntology
with OntologyCopy.SHALLOW
is used in RDF Protege.
The example of ontology with cyclic imports is http://www.w3.org/TR/owl-guide/wine.rdf
sszuev commented
fixed
sszuev commented
Reopen: fix causes an error when the manager contains anonymous ontologies:
java.lang.NullPointerException: Must be named ontology
at java.util.Objects.requireNonNull(Objects.java:228)
at com.github.owlcs.ontapi.jena.utils.OntModels.insert(OntModels.java:91)
at com.github.owlcs.ontapi.OntologyManagerImpl.lambda$syncImports$28(OntologyManagerImpl.java:1142)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.concurrent.ConcurrentHashMap$ValueSpliterator.forEachRemaining(ConcurrentHashMap.java:3566)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at com.github.owlcs.ontapi.OntologyManagerImpl.syncImports(OntologyManagerImpl.java:1142)
at com.github.owlcs.ontapi.OntologyManagerImpl.copyOntology(OntologyManagerImpl.java:1411)