Search code examples
sparqljenaowl

jena doesn't use LocationMapper on owl-imports


I have a ttl file with owl-imports clause like

@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> 

<http://test/data.ttl>
  a       owl:Ontology ;
  owl:imports <file:///Users/tht/workspace/jenatest/test_course.ttl> ;
  owl:versionInfo "tht testing owl:imports"^^xsd:string .

When test_course.ttl file exists, FileManager.get().readModel loads the model, the other ttl is imported and sparql queries work fine. But if i remove the file and use FileManager.get().setLocationMapper().addAltEntry() to redirect to another existing file, the model is not what i expect and the sparql queries return no results.

So owl-imports works fine, but it seems like jena is not using LocationMapper when importing? or could it be my mapping uris are incorrect? I'm using something like

mapper.addAltEntry("file:///Users/tht/workspace/jenatest/test_course.ttl",
"file:///Users/tht/workspace/jenatest/test_course.redirected.ttl")

Solution

  • OntModels have their own FileManager for handling owl:imports.

    This, and the LocationMapper, are accessed via the OntModel's DocumentManager:

    model.getDocumentManager().addAltEntry(..., ...)
    

    and other APIs calls.