Repository navigation
Open
Description
As reported in protegeproject/protege#1226 the imports of some (RDF) ontologies get flattened when loaded by the RDF/XML parser:
- Create an ontology that imports http://purl.org/dc/terms/
- Save it in RDF/XML syntax
- Load the ontology using OWL API
- Observe that the loaded ontology does not have imports
The same does not seem to happen when saving the ontology in functional-style syntax.
To reproduce in OWL API:
- Create two files with the following contents somewhere on the classpath
test.rdf:<?xml version="1.0"?> <rdf:RDF xmlns="http://www.semanticweb.org/demo/ontologies/2024/6/untitled-ontology-136/" xml:base="http://www.semanticweb.org/demo/ontologies/2024/6/untitled-ontology-136/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:dcam="http://purl.org/dc/dcam/" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:terms="http://purl.org/dc/terms/"> <owl:Ontology rdf:about="http://www.semanticweb.org/demo/ontologies/2024/6/untitled-ontology-136"> <owl:imports rdf:resource="http://purl.org/dc/terms/"/> </owl:Ontology> </rdf:RDF>test.ofn:Prefix(:=<http://www.semanticweb.org/demo/ontologies/2024/6/untitled-ontology-136/>) Prefix(owl:=<http://www.w3.org/2002/07/owl#>) Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>) Prefix(xml:=<http://www.w3.org/XML/1998/namespace>) Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>) Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>) Ontology(<http://www.semanticweb.org/demo/ontologies/2024/6/untitled-ontology-136> Import(<http://purl.org/dc/terms/>) )
- Create the following tests:
@Test
public void testImportRDFXML() throws OWLOntologyCreationException {
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
ClassLoader classLoader = getClass().getClassLoader();
File f = new File(classLoader.getResource("test.rdf").getFile());
OWLOntology o = man.loadOntologyFromOntologyDocument(f);
assertEquals(1, o.getImports().size());
}
@Test
public void testImportFS() throws OWLOntologyCreationException {
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
ClassLoader classLoader = getClass().getClassLoader();
File f = new File(classLoader.getResource("test.ofn").getFile());
OWLOntology o = man.loadOntologyFromOntologyDocument(f);
assertEquals(1, o.getImports().size());
}
- Observe that the first test fails on the last line but the second test succeeds.
Stacktrace:
java.lang.AssertionError: expected:<1> but was:<0>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:647)
at org.junit.Assert.assertEquals(Assert.java:633)
at org.semanticweb.owlapi.LoadImportTest.testImportRDFXML(LoadImportTest.java:21)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:757)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Versions:
- OWL API: 4.5.29
- JDK: 11.0.23-zulu
Metadata
Metadata
Assignees
Labels
No labels
Activity
ignazio1977 commentedon Jul 26, 2024
Trying to replicate this, I get something different:
In all cases, attempting to load the ontology throws unloadable ontology error.
I believe Protege is running with missing import strategy set to silent, no exceptions. The DCTerms ontology doesn't look like it can be loaded successfully. The options setup is so that the partial load adds data to the current ontology (same as if the import was from a piece of RDF and not an ontology).
Which perhaps is the case?
ykazakov commentedon Jul 27, 2024
Which version of Java do you use? With Java 8 I also got a 403 error. I think you need to use a more recent Java version.
ignazio1977 commentedon Jul 27, 2024
OWLAPI 4 is required to be compatible with Java 8, though.
Different behaviour with different Java versions is an added headache :-(
Worth noting that adding the import didn't work with any format, in default config, if an ontology with the right IRI was not already in the manager, and worked in all cases otherwise. I need to try with alternate configs, but I believe the root of the behaviour is that we're not dealing with an OWL ontology.
ignazio1977 commentedon Jul 27, 2024
With the manager set like this, the imports directives on file are saved correctly even when the imported file cannot be loaded. I believe that's the standard setup for Protege.
ignazio1977 commentedon Jul 27, 2024
Running on Java 21, I get no exceptions and the tests pass.
The output for different formats:
Functional and OWL/XML include the axioms inline, while none of the others do. Looks like they're ignoring the INCLUDE_GRAPH directive. I'm uncertain if that's a bug or not, given the fact that I don't believe the specs say a lot about it. I'd prefer uniform behaviour, though.
As to why the behaviour is different between Java 8 and Java 21, I'm guessing different exceptions are getting raised :-( On Java 8, the exception is uncaught, while it should have been caught and ignored as per settings.
ignazio1977 commentedon Jul 27, 2024
With the default manager settings, the test fails - the reason being that the import directive cannot be resolved and so gets ignored. I'd argue that the behaviour on Java 8 is best, as it signals something is amiss instead of allowing to load only part of the ontology - the imports directive would be lost once one saves the ontology again, without the user any the wiser.
ykazakov commentedon Jul 28, 2024
Thanks for investigating!
As far as I understand, the 403 error is a separate issue caused by the server blocking requests if it does not like the headers (e.g., coming from Java 8). This could be easily resolved by setting a custom user agent, which is a good idea anyway to ensure consistency across different environments:
(In case you are wondering, I just took the most popular user agent.)
Alternatively, you can use (a different version of) the same ontology from bioportal. Just change the URL
"http://purl.org/dc/terms/"used withintest.ofnandtest.rdfto:For me, both versions of tests (with user agent or with updated URL) work consistently (one test failing the other is not) across all the version of Java I have:
That is strange. As I said, I obtain the same results with all versions of java. Can you tell the exact version of Java and the OS that you use? I run tests from Eclipse 2024-06 (4.32.0) Build id: 20240606-1231 from MacOS 14.5 (23F79)
What do you mean by "adding the import"? Programmatically using OWL API?