【问题标题】:How to define very simple own rule in fuseki step by step?如何在 fuseki 中一步一步定义非常简单的自己的规则?
【发布时间】:2015-05-13 14:22:42
【问题描述】:

我请求您帮助了解如何在 fuseki 中创建我自己的属性规则。 我已经阅读了 Jena 和 Fuseki 关于推理器和规则的文档,但我不明白如何创建(逐步)简单的规则。我发现的例子都集中在 OWL 推理器上。

我不清楚 config.ttl 文件中写入的内容,以便 fuseki 考虑到我对本体的规则。我通过 sparql-client 将 Sparql 点与 python 一起使用,我不掌握 java 代码和应用程​​序。

我的目的是创建下一个规则:

@prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
@prefix ex: http://example.com/
@prefix xs: http://www.w3.org/2001/XMLSchema#
@prefix ont: http://www.myownontolongy/ontology/

[dependsOfExchange:
(?e ont:refersToPriorActivityData ?a)
(?a ont:hasExchange ?es)
->
(?e rme:dependsOfExchange ?es)
]

SWRL语法的原理是:

refersToPriorActivityData(?e,?a) ^ hasExchange(?a,?es) => dependsOfExchange(?e,?es)

提前致谢。


使用一种解决方案进行编辑

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

[] ja:loadClass "com.hp.hpl.jena.tdb.TDB" .
tdb:DatasetTDB  rdfs:subClassOf  ja:RDFDataset .
tdb:GraphTDB    rdfs:subClassOf  ja:Model .

[] rdf:type fuseki:Server ;
   # Timeout - server-wide default: milliseconds.
   # Format 1: "1000" -- 1 second timeout
   # Format 2: "10000,60000" -- 10s timeout to first result, then 60s timeout for the rest of query.
   # See java doc for ARQ.queryTimeout
   # ja:context [ ja:cxtName "arq:queryTimeout" ;  ja:cxtValue "10000" ] ;

   # ja:loadClass "your.code.Class" ;

   fuseki:services (
     <#reminer>
   ) .

## ---------------------------------------------------------------
## Updatable in-memory dataset.

<#reminer> rdf:type fuseki:Service ;
    # URI of the dataset -- http://host:port/reminer
    fuseki:name                        "name_of_your_database" ; 
    fuseki:serviceQuery                "sparql" ;
    fuseki:serviceQuery                "query" ;
    fuseki:serviceUpdate               "update" ;
    fuseki:serviceUpload               "upload" ;
    fuseki:serviceReadWriteGraphStore  "data" ;     
    fuseki:serviceReadGraphStore       "get" ;
    fuseki:serviceReadGraphStore       "" ;      
    fuseki:dataset                     <#myDataset> ;
    .

## In-memory, initially empty.
## This database set-up allows OWL inference.
<#myDataset> rdf:type ja:RDFDataset ;
                tdb:unionDefaultGraph true ; 
                ja:defaultGraph <#infGraph> .

<#infGraph> rdf:type ja:InfModel ;
             ja:reasoner [ ja:rulesFrom <file:rules/inference_rules.rules> ; ] ; #the rules directory is in the "run" directory
             ja:baseModel <#baseGraph> .

<#baseGraph> rdf:type tdb:GraphTDB;
             tdb:location "path_of_your_database" .

以 inference_rules.rules 为例:

@prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
@prefix ex: http://example.com/
@prefix xs: http://www.w3.org/2001/XMLSchema#
@prefix mO: http://www.semanticweb.org/myOntology/

[dependsOfExchange:
(?e mO:producedBy ?a)
(?a mO:hasExchange ?es)
                 ->
                 (?e rme:dependsOf ?es)
         ]

【问题讨论】:

    标签: jena fuseki swrl apache-jena jena-rules


    【解决方案1】:

    .ttl 通过命令行使用:./fuseki-server --config=/path/of/your/custom-config.ttl

    @prefix :        <#> .
    @prefix fuseki:  <http://jena.apache.org/fuseki#> .
    @prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix tdb:     <http://jena.hpl.hp.com/2008/tdb#> .
    @prefix ja:      <http://jena.hpl.hp.com/2005/11/Assembler#> .
    
    [] ja:loadClass "com.hp.hpl.jena.tdb.TDB" .
    tdb:DatasetTDB  rdfs:subClassOf  ja:RDFDataset .
    tdb:GraphTDB    rdfs:subClassOf  ja:Model .
    
    [] rdf:type fuseki:Server ;
       # Timeout - server-wide default: milliseconds.
       # Format 1: "1000" -- 1 second timeout
       # Format 2: "10000,60000" -- 10s timeout to first result, then 60s timeout for the rest of query.
       # See java doc for ARQ.queryTimeout
       # ja:context [ ja:cxtName "arq:queryTimeout" ;  ja:cxtValue "10000" ] ;
    
       # ja:loadClass "your.code.Class" ;
    
       fuseki:services (
         <#reminer>
       ) .
    
    ## ---------------------------------------------------------------
    ## Updatable in-memory dataset.
    
    <#reminer> rdf:type fuseki:Service ;
        # URI of the dataset -- http://host:port/reminer
        fuseki:name                        "name_of_your_database" ; 
        fuseki:serviceQuery                "sparql" ;
        fuseki:serviceQuery                "query" ;
        fuseki:serviceUpdate               "update" ;
        fuseki:serviceUpload               "upload" ;
        fuseki:serviceReadWriteGraphStore  "data" ;     
        fuseki:serviceReadGraphStore       "get" ;
        fuseki:serviceReadGraphStore       "" ;      
        fuseki:dataset                     <#myDataset> ;
        .
    
    ## In-memory, initially empty.
    ## This database set-up allows OWL inference.
    <#myDataset> rdf:type ja:RDFDataset ;
                    tdb:unionDefaultGraph true ; 
                    ja:defaultGraph <#infGraph> .
    
    <#infGraph> rdf:type ja:InfModel ;
                 ja:reasoner [ ja:rulesFrom <file:rules/inference_rules.rules> ; ] ; #the rules directory is in the "run" directory
                 ja:baseModel <#baseGraph> .
    
    <#baseGraph> rdf:type tdb:GraphTDB;
                 tdb:location "path_of_your_database" .
    

    以 inference_rules.rules 为例:

    @prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
    @prefix ex: http://example.com/
    @prefix xs: http://www.w3.org/2001/XMLSchema#
    @prefix mO: http://www.semanticweb.org/myOntology/
    
    [dependsOfExchange:
    (?e mO:producedBy ?a)
    (?a mO:hasExchange ?es)
                     ->
                     (?e rme:dependsOf ?es)
             ]
    

    【讨论】:

    • 你知道如何在汇编中直接使用字符串内容而不是使用 吗?
    猜你喜欢
    • 2014-01-11
    • 2010-09-19
    • 2017-03-04
    • 2014-07-04
    • 1970-01-01
    • 2021-06-11
    • 2014-05-11
    • 2019-05-21
    • 1970-01-01
    相关资源
    最近更新 更多