I'm trying to use Jena Fuseki's API to create a FusekiServer
using an OWL model, wrapped in a Dataset
.
I would like to make OWL inferences happen when adding new triplets to this Dataset
(using SPARQL) while still being able to create named graphs.
In both of my next examples the model is opened as follow :
final Model m = ModelFactory.createOntologyModel(OntModelSpec.OWL_LITE_MEM_RULES_INF);
m.read(SparqlOwl.class.getResourceAsStream("/test_schema.ttl"), null, FileUtils.langTurtle);
m.read(SparqlOwl.class.getResourceAsStream("/test_data.ttl"), null, FileUtils.langTurtle);
What I've tried:
java.lang.UnsupportedOperationException: DatasetGraphOne.add(named graph)
which I understand from the way the Dataset
was created.).final Dataset ds = DatasetFactory.wrap(m);
FusekiServer server = FusekiServer.create()
.add("/ds", ds, true)
.build();
server.start();
final Dataset ds = DatasetFactory.create();
ds.setDefaultModel(m);
FusekiServer server = FusekiServer.create()
.add("/ds", ds, true)
.build();
server.start();
The two files loaded in the example are simple model and some example individuals as follow :
test_schema.ttl:
@prefix ex: <http://example.com/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://example.com> .
ex:Person a owl:Class .
ex:hasChild a owl:ObjectProperty ;
rdfs:domain ex:Person ;
rdfs:range ex:Person .
ex:hasParent a owl:ObjectProperty ;
owl:inverseOf ex:hasChild .
test_data.ttl
@prefix ex: <http://example.com/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@base <http://example.com> .
ex:John a owl:NamedIndividual .
ex:Marie a ex:Person ;
ex:hasChild ex:John .
The triples I'm inserting, using SPARQL, in order to test if the inferences are done are simply stuffs like :
ex:Alice ex:hasParent ex:Bob
in order to see if they both get infered the fact that they are ex:Person
.
I've seen Reasoning with Fuseki, TDB and named graphs? but the question is more about Fuseki TDB and Fuseki's "assembler" interface. I think the problem is partly related but it doesn't provide an answer to my problem (which seems more "elementary"). I've also seen the thread Persisting named graphs in TDB with jena-fuseki on Jena mailing-list which partially speaks about this issue but is more oriented towards the persistence of named graphs in TDB.
To sum up: how to create a SPARQL endpoint with Jena Fuseki programmatic API, allowing to use the base graph and named graph concepts while allowing OWL inferences to occur at runtime when adding new triplets? Is it possible ? Am I missing something ?
As strange as it may sound, the solution seems to be simply to replace
final Dataset ds = DatasetFactory.create();
ds.setDefaultModel(m);
with
final Dataset ds = DatasetFactory.create(m);
By doing this, I get what I wanted, namely I can add new triples to the default graph and the new OWL realizations are correctly done ; and I can successfully create new named graphs on this dataset.
I find the difference in behaviour between the two ways of creating the Dataset a bit confusing but I hope this answer will be useful to other Jena / Fuseki users.
(tested using Jena 3.14)