[英]How to construct a SHACL shape using SPARQL
I have a ttl
file with this information:我有一个包含以下信息的ttl
文件:
ex:Shape1
a sh:NodeShape ;
sh:property ex:Property-1
rdfs:label "Shape 1"
ex:Property-1
a sh:PropertyShape ;
sh:path ex:property1
sh:name "Property 1"
ex:property1
a owl:DatatypeProperty
After loading the above data into my triple store (which contains many shapes already), what query can I use to retrieve the same data back?将上述数据加载到我的三重存储(已经包含许多形状)后,我可以使用什么查询来检索相同的数据?
I have tried a few things, the closest I got is the below query which returns every shape in my triple store (but not ex:property1
):我已经尝试了一些东西,我得到的最接近的是下面的查询,它返回我的三重存储中的每个形状(但不是ex:property1
):
PREFIX sh: <http://www.w3.org/ns/shacl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX ex: <http://example.com/#>
CONSTRUCT {
?subject ?predicate ?object
}
WHERE {
ex:Shape1 sh:property ?propertyShape .
{ ex:Shape1 ?predicate ?object } UNION { ?propertyShape ?predicate ?object }
?subject ?predicate ?object .
}
This query seems to do what I need:这个查询似乎做我需要的:
PREFIX sh: <http://www.w3.org/ns/shacl#>
PREFIX ex: <http://example.com/#>
CONSTRUCT {
?subject ?predicate ?object
}
WHERE {
{
bind(ex:Shape1 as ?subject)
ex:Shape1 ?predicate ?object
}
UNION
{
ex:Shape1 sh:property ?subject .
?subject ?predicate ?object
}
UNION
{
ex:Shape1 sh:property/sh:path ?subject .
?subject ?predicate ?object
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.