[目前,我正在尝试根据以下三元组推断一个新属性maps:mapstoclass
。我的想法是,我可以使用推断的结果(以及包含data:classs对齐方式的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:条件是否需要在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;
];
];
].
sh:condition仅过滤出该规则适用的焦点节点,但对sh:object的评估没有影响。在您的情况下,未经验证,我假设您的(单个)焦点节点映射: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
可以在这里使用。请记住,节点表达式基本上是管道,其中节点在一侧进入,其他节点在另一侧出去。您的情况,我想您想
对不起,我不能在这个特定示例上花费更多的时间,但是也许有点像
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 ;
]
]
]
] .
再次,未经测试,请您对任何小故障表示歉意:)