Rdf 通过sh:object中的表达式实现SHACL规则推理
目前,我正试图根据下面的三元组推断一个新属性Rdf 通过sh:object中的表达式实现SHACL规则推理,rdf,inference,turtle-rdf,shacl,Rdf,Inference,Turtle Rdf,Shacl,目前,我正试图根据下面的三元组推断一个新属性maps:mapstoclass。我的想法是,我可以使用推断结果(以及包含数据对齐:类的rdf文件)来确定data0:object100及其重叠对象之间的相似性,这些重叠对象来自data1:,在maps:hasOverlap中指定 maps:relation_obj1 a maps:OverlapRelations ; maps:hasOverlap [ a data1:class
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 .
首先,我查看了映射的对象属性: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: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的计算没有影响。在您的情况下,在不进行验证的情况下,我假设您的(单个)焦点节点映射:relationship_obj1确实满足条件,因为它的一个值符合qv。但是,仍在对sh:object表达式求值,以获取路径映射的所有值:hasOverlap/rdf:type,然后它将传递这两种类型 一种选择是在SPARQL中表达您需要的内容,并使用基于SPARQL的规则 另一个选项是将当前处于sh:condition中的逻辑移动到sh:object节点表达式中。我相信sh:过滤器 可以在这里使用。请记住,节点表达式基本上是管道,其中节点在一侧进入,其他节点在另一侧离开。就你而言,我想你想
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 ;
]
]
]
] .
同样,未经测试,因此请对任何故障道歉:)