sh:object中通过表达式实现SHACL规则推理
Implementing SHACL rule inference through expression in sh:object
目前我正在尝试根据下面的三元组推断出一个新的 属性 maps:mapstoclass
。我的想法是,我可以使用推断的结果(连同包含 data:classes 对齐的 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 shapes/rule在最后给出)。在这种情况下,只有具有 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:object 中显式应用规则的 sh:condition?我查看了节点表达式,但没有成功使用它 - 我在文档中找不到适用的示例。
使用的形状:
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;
];
];
].
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
可以用在这里。请记住,节点表达式基本上是管道,节点从一侧进入,其他节点从另一侧出去。在你的情况下,我想你想要
- 从 maps:hasOverlap
的所有值开始
- 然后仅过滤适用于您的值形状的那些,即 filterShape sh:and(例如:mainAreaShape ex:secAreaShape)
- 其中 return 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 ;
]
]
]
你需要"read"节点表达式从里到外,所以最里面的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 ;
]
]
]
] .
同样,未经测试,如有任何问题,敬请谅解:)
目前我正在尝试根据下面的三元组推断出一个新的 属性 maps:mapstoclass
。我的想法是,我可以使用推断的结果(连同包含 data:classes 对齐的 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 shapes/rule在最后给出)。在这种情况下,只有具有 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:object 中显式应用规则的 sh:condition?我查看了节点表达式,但没有成功使用它 - 我在文档中找不到适用的示例。
使用的形状:
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;
];
];
].
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
可以用在这里。请记住,节点表达式基本上是管道,节点从一侧进入,其他节点从另一侧出去。在你的情况下,我想你想要
- 从 maps:hasOverlap 的所有值开始
- 然后仅过滤适用于您的值形状的那些,即 filterShape sh:and(例如:mainAreaShape ex:secAreaShape)
- 其中 return 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 ;
]
]
]
你需要"read"节点表达式从里到外,所以最里面的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 ;
]
]
]
] .
同样,未经测试,如有任何问题,敬请谅解:)