如何在 Jena TDB 中使用 Openllet OWL2 推理器(或任何其他推理器)?
How to use Openllet OWL2 reasoner (or any other) with Jena TDB?
我已经找到了一种使用 Openllet reasoner 和 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();
这行得通,但我想知道一种比实际替换数据集中的命名模型更优雅的方法。在理想情况下,我还希望推断是 continuous(一旦将三元组插入图形数据就会在现场自动推断)但我不知道这是否可能。
对于连续推理过程,您需要设置 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"
.
我已经找到了一种使用 Openllet reasoner 和 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();
这行得通,但我想知道一种比实际替换数据集中的命名模型更优雅的方法。在理想情况下,我还希望推断是 continuous(一旦将三元组插入图形数据就会在现场自动推断)但我不知道这是否可能。
对于连续推理过程,您需要设置 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"
.