简体   繁体   English

使用枚举自定义SPARQL构造

[英]Custom SPARQL Construct with enumeration

Is it possible to execute SPARQL construct while adding information outside the scope of query? 是否可以在查询范围之外添加信息时执行SPARQL构造? eg, I want to execute SPARQL construct while defining enumeration information like this: 例如,我想在定义枚举信息时执行SPARQL构造,如下所示:

PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
construct {
   ?s a skos:Concept
   ?s ex:index <enumeration starting from 1 -- this is just a sample>
}
where {
   ?s a skos:Concept
}

is it possible to do something like that with pure SPARQL? 是否可以使用纯SPARQL执行类似的操作? what are the alternatives? 有什么选择?

* Additional Information * * 附加信息 *

Probably I am not explained my problem clearly, so basically I want to achieve the following (assuming that ex:index is a valid datatypeProperty): 可能我没有清楚地解释我的问题,所以基本上我想实现以下(假设ex:index是一个有效的datatypeProperty):

== Initial RDF triples == ==初始RDF三元组==

@prefix skos:<http://www.w3.org/2004/02/skos/core#>
@prefix ex: <http://example.org/> .

ex:abc rdf:type skos:Concept .
ex:def rdf:type skos:Concept .
...
ex:endOfSample rdf:type skos:Concept .

== RDF triples after SPARQL Update execution == == SPARQL更新执行后的RDF三倍==

@prefix skos:<http://www.w3.org/2004/02/skos/core#>
@prefix ex: <http://example.org/> .

ex:abc rdf:type skos:Concept ;
    ex:index 1 .
ex:def rdf:type skos:Concept ;
    ex:index 2 .
...
ex:endOfSample rdf:type skos:Concept ;
    ex:index <endOfSampleNumber> .

You can construct any valid RDF value in a CONSTRUCT. 您可以在CONSTRUCT中构造任何有效的RDF值。 However the query will fail if any of the variables in the CONSTRUCT graph pattern is unbound after executing the WHERE graph. 但是,如果在执行WHERE图之后CONSTRUCT图模式中的任何变量未绑定,则查询将失败。 Ie there can be no binding for ?p in your query and the CONSTRUCT will never execute. 即你的查询中没有绑定到?p并且CONSTRUCT永远不会执行。

This is an example that should get you started: 这是一个可以帮助您入门的示例:

PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
PREFIX ex:<http://example.org/construct#>
construct {
  ex:someProp a owl:ObjectProperty .
  ?s ex:someProp (1 2 3)
}
where {
  ?s a skos:Concept
}

This will result in the construction of seven triples for the property value and the list structure. 这将导致为属性值和列表结构构建七个三元组。

The ex:someProp is added because there isn't a good object property in SKOS for ad-hoc lists. 添加了ex:someProp,因为SKOS中没有用于ad-hoc列表的良好对象属性。 It would be best to define the property with some semantic meaning. 最好定义具有某种语义含义的属性。 Also note that while the {ex:someProp a owl:ObjectProperty} triple will be asserted for each match of {?sa skos:Concept}, it is the same triple, hence there will be only one in the end. 还要注意,虽然{ex:someProp a owl:ObjectProperty}三元组将为{?sa skos:Concept}的每个匹配声明,但它是相同的三元组,因此最终只会有一个。 The price is efficiency, so asserting the property outside of this query would be a better choice - it is included in the above query for the sake of example completeness. 价格是效率,因此在此查询之外声明属性将是更好的选择 - 为了示例完整性,它包含在上述查询中。

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

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