简体   繁体   English

如何在 SPARQL 中构造列表

[英]How to construct a list in SPARQL

I have a ttl file that looks like this:我有一个看起来像这样的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:in (
        "Option 1"
        "Option 2"
    ) ;
    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?将上述数据加载到我的三重存储(已经包含许多形状)后,我可以使用什么查询来检索相同的数据?

This query gets everything I need except for the list.这个查询得到我需要的一切,除了列表。 For the list it only gives a blank node.对于列表,它只给出一个空白节点。

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
  }
}

First of all, why do you need to query to get the same data back?首先,为什么需要查询才能取回相同的数据? Do you mean you need to get it in the same syntax and formatting?您的意思是您需要以相同的语法和格式获取它吗?

  • to get the same data in the form of triples, you can simply execute SELECT * from ?s ?p ?o and it will give you all the triples.要以三元组的形式获取相同的数据,您可以简单地执行 SELECT * from ?s ?p ?o 它会给您所有的三元组。 It also depends on your triplestore.这也取决于您的三联店。

  • The standard query to fetch the items in your list would be the following:获取列表中项目的标准查询如下:

     PREFIX sh: <http://www.w3.org/ns/shacl#> PREFIX ex: <http://example.com/#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?item WHERE { ex:Property-1 sh:in/rdf:rest*/rdf:first ?item }

You can read more about how the list items are stored internally.您可以阅读有关列表项如何在内部存储的更多信息。 This link will be helpful.这个链接会很有帮助。 You can bind the ex:Property-1 in the same way in UNION or WHERE clause in your construct query to get the desired result.您可以在构造查询的 UNION 或 WHERE 子句中以相同的方式绑定 ex:Property-1 以获得所需的结果。

I hope it is helpful.我希望它会有所帮助。 Good luck.祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM