我已经找到了一种使用Openllet推理程序和Jena 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();
这可行,但是我想知道一种比在数据集中实际替换命名模型更优雅的方法。在理想情况下,我还希望推理是连续的(一旦在图表上自动插入了三元组,就可以自动推断出该数据),但是我不知道是否可能。
答案 0 :(得分:2)
对于连续推理过程,您需要设置Fuseki配置。
这是我使用Openllet推理程序在持久性TDB数据库上进行配置的快速示例。
@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"
.