[英]Implementing SHACL rule inference through expression in sh:object
目前我正在嘗試根據下面的三元組推斷一個新的屬性maps:mapstoclass
。 這個想法是我可以使用推斷的結果(連同包含數據:類的 alignment 的 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
的 object 屬性是否滿足我的qualifiedValueShape
(最后給出了shacl 形狀/規則)。 在這種情況下,只有帶有 maps:secfeature data1:object1 的 'hasOverlap' object 滿足條件。 因此“maps:mapsto”的 object 應該是 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;
];
];
].
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
可以在這里使用。 請記住,節點表達式基本上是管道,其中節點 go 在一側,其他節點 go 在另一側。 在你的情況下,我認為你想要
抱歉,我不能花更多時間在這個特定的例子上,但也許是這樣的
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 ;
]
]
]
] .
再次,未經測試,所以請對任何故障表示歉意:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.