Skip to content

Ontology imports not preserved by RDF/XML parser #1147

@ykazakov

Description

@ykazakov

As reported in protegeproject/protege#1226 the imports of some (RDF) ontologies get flattened when loaded by the RDF/XML parser:

  1. Create an ontology that imports http://purl.org/dc/terms/
  2. Save it in RDF/XML syntax
  3. Load the ontology using OWL API
  4. 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:

  1. Create two files with the following contents somewhere on the classpath
    1. 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>
      
    2. 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/>)
      
      )
      
  2. 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());
}
  1. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions