jenaowlfusekireasoningnamed-graphs

Reasoning when adding new triples in a named graph in Jena Fuseki


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:

  1. Using the following method, OWL inferences are performed when loading the model, and when adding new triplets with SPARQL. On the other hand it is not possible to create a new named graph (if I try to do so, I have an error saying this action is not supported : 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();
  1. Using the following method, OWL realizations are performed when the model is loaded. It is indeed possible to add new triplets in a named graph or in the "base" graph. On the other hand, the new inferences, as described and expected due to the OWL model, are not made when adding new triplets (whether they are added to the base graph or in a named graph).
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 ?


Solution

  • 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)