0

目前我正在尝试maps:mapstoclass根据下面的三元组推断一个新属性。data0:object100这个想法是我可以使用推断的结果(以及包含数据对齐的rdf 文件:类)来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;
                        ];
                    ];
            ].
4

1 回答 1

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 关键字表示为

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 ;
                ]
            ]
        ]
    ] .

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

于 2020-04-17T04:36:17.020 回答