首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确使用sh:rule和sh:count

如何正确使用sh:rule和sh:count
EN

Stack Overflow用户
提问于 2021-08-12 16:40:42
回答 1查看 94关注 0票数 0

这是我的data.ttl:

代码语言:javascript
复制
@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为:

代码语言:javascript
复制
@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):

代码语言:javascript
复制
shaclinfer.bat -datafile D:\data.ttl -shapesfile D:\shacl.ttl>D:\report.txt

我得到的结果报告如下:

代码语言:javascript
复制
<http://example.com/ns#Bob>
        <http://example.com/ns#rating>  0 .

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

如果Bob得到2个以上的"A",那么--> :Bob :评级为“杰出”。

如何正确编写sh:condition语句?在这种情况下,sh:count应该计算测试哪个grade="A“的数量,我是否必须使用sparql构造语句?谢谢你的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-13 03:17:35

代码语言:javascript
复制
@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引擎的错误,错误消息如下:

代码语言:javascript
复制
Exception in thread "main" org.apache.jena.query.QueryParseException: Line 2, column 1: Unresolved prefixed name: :tookTest

有没有人可以用其他SHACL推理引擎测试一下?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68761288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档