简体   繁体   中英

Reasoning in Apache Jena Fuseki: "Reload" dataset or "trigger" inference

We have an Apache-Fuseki Server running with the following configuration:

@prefix :      <http://base/#> .
@prefix tdb:   <http://jena.hpl.hp.com/2008/tdb#> .
@prefix tdb2:  <http://jena.apache.org/2016/tdb#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ja:    <http://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix fuseki: <http://jena.apache.org/fuseki#> .

# TDB
tdb2:DatasetTDB  rdfs:subClassOf  ja:RDFDataset .
tdb2:GraphTDB    rdfs:subClassOf  ja:Model .

# Service 1: Dataset endpoint (no reasoning)
:dataService a fuseki:Service ;
  fuseki:name           "wotTdb" ;
  fuseki:serviceQuery   "sparql", "query" ;
  fuseki:serviceUpdate  "update" ;
  fuseki:serviceReadWriteGraphStore "data" ;
  fuseki:dataset        :tdbDataset ;
.

# Service 2: Reasoning endpoint
:reasoningService a fuseki:Service ;
  fuseki:dataset                 :infDataset ;
  fuseki:name                    "wotReasoning" ;
  fuseki:serviceQuery            "query", "sparql" ;
  fuseki:serviceReadGraphStore   "get" ;
.

# Inference dataset
:infDataset rdf:type ja:RDFDataset ;
            ja:defaultGraph :infModel ;
.

# Inference model
:infModel a ja:InfModel ;
           ja:baseModel :g ;

           ja:reasoner [
              ja:reasonerClass "openllet.jena.PelletReasonerFactory" ;
            ] ;
.

# Intermediate graph referencing the default union graph
:g rdf:type tdb2:GraphTDB2 ;
   tdb2:dataset :tdbDataset ;
   tdb2:graphName <urn:x-arq:UnionGraph> ;
.

# The location of the TDB dataset
:tdbDataset rdf:type tdb2:DatasetTDB2 ;
            tdb2:location "/fuseki/databases/wot" ;
            tdb2:unionDefaultGraph true ; 
.

Explanation:

It has 2 Endpoints, one for the raw data, and one for the inferenced data.

The raw-data dataset has 2 graphs:

  • the data we read and push to fuseki
  • the restrictions we use for the reasoning

The inference dataset consists of the union-default-graph from the data-dataset (raw + restrictions) and the inference model.

We do this so we have 1 Endpoint to read/write our data and restrictions and 1 Endpoint to do the inference.

The problem is that the reasoning-endpoint won't "update", eg do the reasoning if new data comes in. How can we "trigger" the reasoning-engine to update its graph if new data arrives (or in general)?

Querying the dataset doesn't work, the only solution we found so far is restarting the server, which is not reasonable.

I found this configuration on this answer with the note

Note that the reasoning service will not see any changes in the dataset until it is reloaded, since reasoning is all done in memory.

That's exactly our problem.

Also: If you have a better idea for this approach in general please let me know. We thought it is a good idea to keep factual data and inferenced data separate and this was the only way we were able to achieve this.

I found the s-put in the./jena-fuseki2/apache-jena-fuseki/bin is pretty handy for this.

s-put http://localhost:3030/ds default./main.ttl

The above command will remove the default graph and reload the main.ttl. I'm sure curl can do it with more effort.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM