【问题标题】:Implementing SHACL rule inference through expression in sh:object通过 sh:object 中的表达式实现 SHACL 规则推断
【发布时间】:2020-04-16 06:27:07
【问题描述】:

目前我正在尝试根据下面的三元组推断一个新属性maps:mapstoclass。这个想法是我可以使用推断的结果(连同包含数据对齐的 rdf 文件:类)来确定 data0:object100 与其来自 data1: 的重叠对象之间的相似性,在 maps:hasOverlap 中指定。

maps:relation_obj1  a     maps:OverlapRelations ;
        maps:hasOverlap   [ a                      data1:classA ;
                            maps:mainRelativeArea  "80.0"^^xsd:float ;
                            maps:secRelativeArea   "100.0"^^xsd:float ;
                            maps:secfeature        data1:object1 ;
                          ] ;
        maps:hasOverlap   [ a                      data1:classX ;
                            maps:mainRelativeArea  "40.0"^^xsd:float ;
                            maps:secRelativeArea   "100.0"^^xsd:float ;
                            maps:secfeature        data1:object2 ;
                          ] ;
        maps:mainfeature  data0:object100 ;
        maps:mainclass     data0:classB .

首先,我查看了maps:hasOverlap 的对象属性是否满足我的qualifiedValueShape(最后给出了shacl 形状/规则)。在这种情况下,只有带有 maps:secfeature data1:object1 的 'hasOverlap' 对象满足条件。因此'maps:mapsto'的对象应该是data1:object1。我期望的结果是:

maps:relation_obj1 maps:mapstoclass data1:object1. 

但是,我目前得到:

maps:relation_obj1 maps:mapstoclass data1:object1, data1:object2.

我做错了什么?规则的 sh:condition 是否需要在 sh:object 中显式应用?我查看了节点表达式,但没有成功使用它 - 我在文档中找不到适用的示例。

使用的形状:

ex:mainAreaShape
    rdf:type sh:NodeShape;
    sh:property [
        sh:path maps:mainRelativeArea ;
        sh:minInclusive 80 ;
    ].

ex:secAreaShape
    rdf:type sh:NodeShape;
    sh:property [
        sh:path maps:secRelativeArea ;
        sh:minInclusive 80 ;
    ].


ex:OverlapRelations
    rdf:type rdfs:Class, sh:NodeShape ;
    sh:targetClass maps:OverlapRelations;
    rdfs:label "whether overlap between features is enough to generate relation" ;
    sh:rule [
        rdf:type sh:TripleRule ;
        sh:subject sh:this ;
        sh:predicate maps:mapstoclass;
        sh:object [sh:path (maps:hasOverlap
                    rdf:type) ;
                    ];  
        sh:condition ex:OverlapRelations;
        sh:condition [
            sh:property [
            sh:path maps:hasOverlap ;
            sh:nodeKind sh:BlankNode ;
            sh:minCount 1;
            sh:qualifiedValueShape [
                    sh:and (ex:mainAreaShape ex:secAreaShape);  
                                    ];
                    sh:qualifiedMinCount 1;
                    sh:qualifiedMaxCount 1;
                        ];
                    ];
            ].

【问题讨论】:

    标签: rdf inference turtle-rdf shacl


    【解决方案1】:

    sh:condition 只过滤掉规则适用的焦点节点,但对 sh:object 的评估没有影响。在您的情况下,未经验证,我假设您的(单个)焦点节点 maps:relation_obj1 确实满足条件,因为它的值之一符合 QVS。但是,仍在为路径映射的所有值评估 sh:object 表达式:hasOverlap/rdf:type,然后传递两者的类型。

    一种选择是在 SPARQL 中表达您的需求并使用基于 SPARQL 的规则。

    另一个选择是将当前在 sh:condition 中的逻辑移动到 sh:object 节点表达式中。我相信 sh:filterShape

    https://w3c.github.io/shacl/shacl-af/#node-expressions-filter-shape

    可以在这里使用。请记住,节点表达式基本上是管道,其中节点从一侧进入,其他节点从另一侧输出。在你的情况下,我认为你想要

    1. 从地图的所有值开始:hasOverlap
    2. 然后仅过滤您的值形状适用的那些,即 filterShape sh:and (ex:mainAreaShape ex:secAreaShape)
    3. 其中返回 rdf:type

    对不起,我不能花更多时间在这个特定的例子上,但也许是这样的

    sh:object [  # 3.
        sh:path rdf:type ;
        sh:nodes [ # 2.
            sh:filterShape [ 
                sh:nodeKind sh:BlankNode ;
                sh:node ex:mainAreaShape, ex:secAreaShape ;  # same as your sh:not
            ] ;
            sh:nodes [ # 1.
                sh:path maps:hasOverlap ;
            ]
        ]
    ]
    

    您需要从内到外“读取”节点表达式,因此首先评估最里面的 hasOverlap 路径,然后通过过滤器运行结果。如果没有结果节点,或者没有 rdf:type 则没有 sh:object 被发现,因此没有三重推断。

    顺便说一句,不需要 sh:targetClass,我认为整个事情也可以使用(较新的)sh:values 关键字 as 来表达

    ex:OverlapRelations
        a rdfs:Class, sh:NodeShape ;
        rdfs:label "whether overlap between features is enough to generate relation" ;
        sh:property [
            sh:path maps:mapstoclass ;
            sh:values [ # 1.
                sh:path rdf:type ;
                sh:nodes [ # 2.
                    sh:filterShape [ 
                        sh:nodeKind sh:BlankNode ;
                        sh:node ex:mainAreaShape, ex:secAreaShape ;
                    ] ;
                    sh:nodes [ # 1.
                        sh:path maps:hasOverlap ;
                    ]
                ]
            ]
        ] .
    

    再次,未经测试,所以请对任何故障表示歉意:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      相关资源
      最近更新 更多