The list does not accept attachments, however, I mocked something up.
The OntModel has it's own FileManager for imports in the DocumentManager
model.getDocumentManager().addAltEntry(...)
or get the FileManager for imports
model.getDocumentManager().getFileManager()
---
Note:
fileManager.readModel(model, "file://" + source, "TURTLE");
the model does not know it's being read into via the FileManager
Andy
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
redirected
package com.jenatest;
import java.io.FileNotFoundException;
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:
<http://learningsparql.com/ns/addressbook#>\n" +
"prefix d: <http://learningsparql.com/ns/data#>\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 = rs.next();
RDFNode r = qs.get("email");
System.out.println("email: " + r);
}
}
public void complexLoad() throws FileNotFoundException {
LocationMapper mapper = new LocationMapper();
mapper.addAltEntry("file:///Users/tht/workspace/jenatest/test_course.ttl",
"file:///Users/tht/workspace/jenatest/test_course.redirected.ttl");
Model model = ModelFactory.createOntologyModel();
String source = "/Users/tht/workspace/jenatest/test_book.ttl";
FileManager fileManager = new FileManager(mapper);
fileManager.addLocatorFile();
fileManager.readModel(model, "file://" + source, "TURTLE");
queryModel(model);
}
public static void main(String[] args) {
App app = new App();
try {
app.complexLoad();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
>-------- Оригинално писмо --------
>От: Andy Seaborne [email protected]
>Относно: Re: Jena doesn't use LocationMapper on owl-imports
>До: [email protected]
>Изпратено на: 13.04.2018 13:02
same as yesterday's
https://stackoverflow.com/questions/49801630/jena-doesnt-use-locationmapper-on-owl-imports
Please provide a complete, minimal, debuggable example, and also say
which version of Jena you are using.
Andy
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:
Hello!
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.ttl.redirected")
Thanks for any hints!