我已经找到了一种使用 Openllet 推理器和耶拿 TDB 推断三重存储内容的方法,但它似乎不是最佳的。这是我的解决方案:
Reasoner reasoner = PelletReasonerFactory.theInstance().create();
InfModel infModel = ModelFactory
.createInfModel(reasoner, dataset.getNamedModel(KD.URI));
/*
* To extract the model, a transaction must be open in READ mode.
*/
dataset.begin(ReadWrite.READ);
ModelExtractor me = new ModelExtractor(infModel);
dataset.end();
/*
* To replace a currently existing named model within the dataset, a transaction must be open in WRITE mode.
*/
dataset.begin(ReadWrite.WRITE);
dataset.replaceNamedModel(KD.URI, me.extractModel());
dataset.commit();
dataset.end();
这有效,但我想知道一种比实际替换数据集中的命名模型更优雅的方法。在理想情况下,我还希望推理是连续的(一旦将三元组插入图形数据,就会当场自动推断(,但我不知道这是否可能。
对于连续推理过程,您需要设置 Fuseki 配置。
下面是我在持久 TDB 数据库上使用 Openllet 推理器的配置的快速示例。
@prefix : <http://base/#> . @prefix tdb:
<http://jena.hpl.hp.com/2008/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#> .
:service_tdb_all a fuseki:Service ;
rdfs:label "LABEL_OF_YOUR_SERVICE" ;
fuseki:dataset :dataset ;
fuseki:name "NAME_OF_YOUR_SERVICE" ;
fuseki:serviceQuery "query" , "sparql" ;
fuseki:serviceReadGraphStore "get" ;
fuseki:serviceReadWriteGraphStore
"data" ;
fuseki:serviceUpdate "update" ;
fuseki:serviceUpload "upload" .
:dataset a ja:RDFDataset ;
ja:defaultGraph <#modeInf>; .
<#modeInf> a ja:InfModel;
ja:baseModel <#tdbGraph>;
ja:reasoner [
ja:reasonerClass "openllet.jena.PelletReasonerFactory" ]
.
<#tdbGraph> rdf:type tdb:GraphTDB ;
tdb:dataset :tdb_dataset_readwrite .
:tdb_dataset_readwrite a
tdb:DatasetTDB ; tdb:location
"PATH_TO_YOUR_TDB"
.