本文介紹了如何在Jena TDB中使用Openllet OWL2推理器(或其他推理器)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我已經(jīng)找到了一種使用Openllet Reasoner和Jena TDB推斷三元組存儲(chǔ)內(nèi)容的方法,但它似乎不是最優(yōu)的。以下是我的解決方案:
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();
這是可行的,但我想知道一種比實(shí)際替換數(shù)據(jù)集中的命名模型更好的方法。在理想的情況下,我也希望推理是連續(xù)的(一旦將三元組插入到圖形中,就會(huì)當(dāng)場(chǎng)自動(dòng)推斷數(shù)據(jù)),但我不知道這是否可能。
推薦答案
對(duì)于連續(xù)推理過程,您需要設(shè)置fuseki配置。
這里是我在一個(gè)具有Openllet推理器的持久性TDB數(shù)據(jù)庫(kù)上的配置的快速示例。
@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"
.
這篇關(guān)于如何在Jena TDB中使用Openllet OWL2推理器(或其他推理器)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,