0

这是我的data.ttl:

@prefix : <http://example.com/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:Bob  a  :Student ;
        :name "Bob" ;
        :tookTest :Test1, :Test2, :Test3, :Test4, :Test5 .

:Test1 a :Test ;   
          :grade "A" .

:Test2 a :Test ;
           :grade "A" .

:Test3  a :Test ;
          :grade "A" .

:Test4 a :Test ;
          :grade "C" .

:Test5 a :Test ;
          :grade "D" .

shacl.ttl 是:

@prefix : <http://example.com/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

:Test a rdfs:Class,  sh:NodeShape .
:Student    a rdfs:Class, sh:NodeShape ;
                sh:rule [
        a sh:TripleRule ;
        sh:subject sh:this ;
        sh:predicate :rating ;
        sh:object [sh:count [sh:path :Test] ];  
                     ] .

我使用 shacl 推理引擎(https://github.com/TopQuadrant/shacl):

shaclinfer.bat -datafile D:\data.ttl -shapesfile D:\shacl.ttl>D:\report.txt

我得到一个结果报告:

<http://example.com/ns#Bob>
        <http://example.com/ns#rating>  0 .

我实际上想实现以下规则:

如果 Bob 获得超过 2 个“A”,则 --> :Bob :rating "Outstanding" 。

如何正确编写此 sh:condition 语句?在这种情况下 sh:count 应该计算 Test which Grade="A" 的数量,我必须使用 sparql CONSTRUCT 语句吗?谢谢你的帮助!

4

1 回答 1

0
@prefix : <http://example.com/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

:Test a rdfs:Class,  sh:NodeShape .
:Student    a  rdfs:Class, sh:NodeShape ;
            sh:rule [
                    a sh:TripleRule ;
                    sh:subject sh:this ;
                    sh:predicate :rating ;
                    sh:object "Outstanding";  
                    sh:condition :Student ;
                    sh:condition [
                            sh:qualifiedValueShape [
                                     sh:path (:tookTest :grade ) ;
                                     sh:hasValue "A" ; ] ; 
                            sh:qualifiedMinCount 2 ; ];    
                    ] .

shacl.ttl 看起来接近正确,但它被https://github.com/TopQuadrant/shacl的引擎报错,错误信息如下:

Exception in thread "main" org.apache.jena.query.QueryParseException: Line 2, column 1: Unresolved prefixed name: :tookTest

有人可以用其他任何 SHACL 推理引擎对此进行测试吗?

于 2021-08-13T03:17:35.317 回答