这是我的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 语句吗?谢谢你的帮助!