The list does not accept attachments, however, I mocked something up.

The OntModel has it's own FileManager for imports in the DocumentManager


or get the FileManager for imports




fileManager.readModel(model, "file://" + source, "TURTLE");

the model does not know it's being read into via the FileManager


On 13/04/18 11:24, r. r. wrote:
Hi Andy
indeed I first posted the question to SO..

here's the code; it's using Jena 3.6.0. I'm attaching the base and imported 
.ttl files as well.
indeed the extension of the mapped file was invalid, but even changing it to 
.ttl didn't help.
note that the query in queryModel() does produce results when the import is not 

package com.jenatest;

import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.util.FileManager;
import org.apache.jena.util.LocationMapper;

public class App {

     public void queryModel(Model model) {
         Query sparql = QueryFactory.create("prefix ab: 
<>\n" +
                 "prefix d:  <>\n" +
                 "\n" +
                 "select ?email ?courseTitle\n" +
                 " { \n" +
                 "    ?d ab:email ?email ;\n" +
                 "       ab:takingCourse ?course .\n" +
                 "    ?course ab:courseTitle ?courseTitle\n" +

     Query query = QueryFactory.create(sparql);
     QueryExecution qe = QueryExecutionFactory.create(query, model);
     ResultSet rs = qe.execSelect();
         while (rs.hasNext()) {
             QuerySolution qs =;
             RDFNode r = qs.get("email");
             System.out.println("email: " + r);

     public void complexLoad() throws FileNotFoundException {
         LocationMapper mapper = new LocationMapper();

         Model model = ModelFactory.createOntologyModel();
         String source = "/Users/tht/workspace/jenatest/test_book.ttl";

        FileManager fileManager = new FileManager(mapper);
         fileManager.readModel(model, "file://" + source, "TURTLE");


     public static void main(String[] args) {
         App app = new App();

         try {
         } catch (FileNotFoundException e) {
             // TODO Auto-generated catch block

  >-------- Оригинално писмо --------

  >От: Andy Seaborne

  >Относно: Re: Jena doesn't use LocationMapper on owl-imports


  >Изпратено на: 13.04.2018 13:02

same as yesterday's

Please provide a complete, minimal, debuggable example, and also say
which version of Jena you are using.


PS redirecting to a file with an extension that does not indicate the
RDF syntax will not work.

On 13/04/18 10:21, r. r. wrote:
I have a ttl file with owl-imports clause like

@prefix xsd:     <>

    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


Thanks for any hints!

Reply via email to