如何将推断的三元组输入其他SHACL规则?

如何解决如何将推断的三元组输入其他SHACL规则?

我最近联系了SHACL,我真的很喜欢。我对SHACL规则有疑问,我想知道是否有人可以帮助我。

我创建了这个小本体,是我正在研究的GDPR更大本体的一部分。

Text

有五个主要类:PersonalDataProcessing,DataSubject,LegalBasis,Consent和GiveConsent。并且,有四个(功能性)对象属性:

  • hasLegalBasis(域:PersonalDataProcessing,范围:LegalBasis)。
  • hasAgent(域:GiveConsent,范围:DataSubject)
  • 有患者(域:GiveConsent,范围:同意)
  • objectOfConsent(域:同意,范围:PersonalDataProcessing)

在PersonalDataProcessing上定义了一个数据类型(布尔)属性,称为“ isLawful”:每个PersonalDataProcessing可以合法(isLawful = true),也可以合法(isLawful = false)。

我在GiveConsent类中创建了一个单独的“ gc”。 “ gc”有一个代理“ John”(他是一个DataSubject)和一个病人“ c”(这是一个同意书)。同意“ c”通过objectOfConsent属性连接到另一个个人“ pdp”,这是一个PersonalDataProcessing。

然后我有两个SHACL规则。其中一个具有“ sh:order 1”,因此应在另一个(默认值为sh:order等于0)之后执行;

# baseURI: http://w3.org/ns/temp
# prefix: temp

@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix temp: <http://w3.org/ns/temp#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://w3.org/ns/temp>
  rdf:type owl:Ontology ;
  owl:versionInfo "Created with TopBraid Composer" ;
.
temp:Action
  rdf:type owl:Class ;
  rdfs:subClassOf owl:Thing ;
.
temp:Consent
  rdf:type owl:Class ;
  rdfs:subClassOf owl:Thing ;
.
temp:DataSubject
  rdf:type owl:Class ;
  rdfs:subClassOf owl:Thing ;
.
temp:GiveConsent
  rdf:type owl:Class ;
  rdfs:subClassOf temp:Action ;
.
temp:John
  rdf:type temp:DataSubject ;
.
temp:LegalBasis
  rdf:type owl:Class ;
  rdfs:subClassOf owl:Thing ;
.
temp:PersonalDataProcessing
  rdf:type owl:Class ;
  rdfs:subClassOf owl:Thing ;
.
temp:c
  rdf:type temp:Consent ;
  temp:objectOfConsent temp:pdp ;
.
temp:gc
  rdf:type temp:GiveConsent ;
  temp:hasAgent temp:John ;
  temp:hasPatient temp:c ;
.
temp:hasAgent
  rdf:type owl:FunctionalProperty ;
  rdfs:domain temp:GiveConsent ;
  rdfs:range temp:DataSubject ;
.
temp:hasLegalBasis
  rdf:type owl:FunctionalProperty ;
  rdfs:domain temp:PersonalDataProcessing ;
  rdfs:range temp:LegalBasis ;
.
temp:hasPatient
  rdf:type owl:FunctionalProperty ;
  rdfs:domain temp:GiveConsent ;
  rdfs:range temp:Consent ;
.
temp:isLawful
  rdf:type owl:DatatypeProperty ;
  rdfs:domain temp:PersonalDataProcessing ;
  rdfs:range xsd:boolean ;
.
temp:objectOfConsent
  rdf:type owl:FunctionalProperty ;
  rdfs:domain temp:Consent ;
  rdfs:range temp:PersonalDataProcessing ;
.
temp:pdp
  rdf:type temp:PersonalDataProcessing ;
.

上面的第一条规则指出,如果有人同意了PersonalDataProcessing,则该同意是PersonalDataProcessing的法律依据。第二条规则(带有“ sh:order 1;”)指出,每个具有法律依据的PersonalDataProcessing都是合法的。

最后,我编写了一个Java文件来执行规则:

# baseURI: http://w3.org/ns/rules
# imports: http://w3.org/ns/temp
# prefix: rules

@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rules: <http://w3.org/ns/rules#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix temp: <http://w3.org/ns/temp#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://w3.org/ns/rules>
  rdf:type owl:Ontology ;
  owl:imports <http://w3.org/ns/temp> ;
  owl:versionInfo "Created with TopBraid Composer" ;
.
rules:givenConsentIsLegalBasis
  rdf:type sh:NodeShape ;
  sh:rule [
      rdf:type sh:TripleRule ;
      sh:object [
          sh:path temp:hasPatient ;
        ] ;
      sh:predicate temp:hasLegalBasis ;
      sh:subject [
          sh:path (
              temp:hasPatient
              temp:objectOfConsent
            ) ;
        ] ;
    ] ;
  sh:targetClass temp:GiveConsent ;
.
rules:legalBasisEntailLawful
  rdf:type sh:NodeShape ;
  sh:rule [
      rdf:type sh:TripleRule ;
      sh:order 1 ;
      sh:condition [
          sh:property [
              sh:path temp:hasLegalBasis ;
              sh:minCount 1 ;
            ] ;
        ] ;
      sh:object "true"^^xsd:boolean ;
      sh:predicate temp:isLawful ;
      sh:subject sh:this ;
    ] ;
  sh:targetClass temp:PersonalDataProcessing ;
.

我写信给您,是因为第一个规则通过上面的Java代码正确创建了三重“ pdp hasLegalBasis c”:

    //Load the ontology
Model ontology = JenaUtil.createMemoryModel();
FileInputStream fisOntology = new FileInputStream("./ontology.ttl");
ontology.read(fisOntology,"urn:dummy",FileUtils.langTurtle);
        
    //Load the rules
Model rules = JenaUtil.createMemoryModel();
FileInputStream fisRules = new FileInputStream("./rules.ttl");
rules.read(fisRules,FileUtils.langTurtle);
        
    //Executing the rules
Model inferredModel = RuleUtil.executeRules(ontology,rules,null,null);
        
    //Print
System.out.println(ModelPrinter.get().print(inferredModel));

但是,在推断出该三元组之后,第二条规则 NOT 不会触发:isLawful是 NOT 设置为true。

另一方面,如果我在本体中手动添加三元组“ pdp hasLegalBasis c”,则这两个规则都会触发:

<http://w3.org/ns/temp#pdp>
        <http://w3.org/ns/temp#hasLegalBasis>
                <http://w3.org/ns/temp#c> ;

我在做什么错?你们中的任何一个可以帮助我吗?

非常感谢您

解决方法

首先,当您从TopBraid Composer执行时,您的示例可以正常工作,它会自动进行多次迭代。因此,我怀疑这与规则的顺序有关。 sh:order仅用于相同形状内的规则,但不会通知形状间的“外部”循环。结果,示例中的sh:order值无效。

作为一般选择,请尝试两次调用规则引擎,并将第一次迭代的推论作为第二轮的输入。为此,您需要在对RuleUtil的调用之外构造推理模型,类似于在将InferencesModel保留为null的情况下,RuleUtil进行的操作。请参阅RuleUtil类的源代码。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-