简体   繁体   English

在 SPARQL 中构造循环

[英]Construct loop in SPARQL

The following SPARQL query以下 SPARQL 查询

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix msc: <http://msc.org/resources/MSC/msc2020/>

construct {?s skos:broader msc:00-XX . }
where
{
?s a skos:Concept ; skos:notation ?notation.
filter regex (?notation, "00-\d\d")
}

searches all notations 00-01, 00-02, etc. and constructs a relation to the top level class 00-XX.搜索所有符号 00-01、00-02 等并构造与顶级 class 00-XX 的关系。 However, this is only the first of 63 top level classes altogether, so I would like to "loop" over all top level classes automatically.然而,这只是 63 个顶级类中的第一个,所以我想自动“循环”所有顶级类。 On top, I would like to adapt this to other patterns.最重要的是,我想让它适应其他模式。 Is there a way to do this with SPARQL?有没有办法用 SPARQL 做到这一点? If not, what would you recommend instead?如果没有,你会推荐什么?

In the meantime we found a solution without SPARQL.与此同时,我们找到了一个没有 SPARQL 的解决方案。 The SPARQL CONSTRUCT query was supposed to create a skos:broader relation between a skos:Concept with a notation like "00-01" (and all other concepts with 00-\d\d notation) and its proper subordinate concept, which for 00-01 is the skos:Concept with the notation 00-XX. SPARQL CONSTRUCT 查询应该在 skos:Concept 之间创建一个 skos:broader 关系,其符号为“00-01”(以及所有其他带有 00-\d\d 符号的概念)及其适当的从属概念,即 00 -01 是符号 00-XX 的 skos:Concept。

The data originate from a table and Open Refine is much faster in creating the skos:broader statements than using the SPARQL query proposed above and adjusting it to other notation patterns.数据来自一个表,Open Refine 在创建 skos:broader 语句方面比使用上面提出的 SPARQL 查询并将其调整为其他符号模式要快得多。

We use GREL's value.replace on the cells with the notations to create a new column:我们在带有符号的单元格上使用 GREL 的 value.replace 来创建一个新列:

value.replace(/-\d\d/, "-XX").replace(/\d\d>/, "xx>")

The two replacements give us the notation of the original notation's superordinate concept in one step.这两个替换为我们一步一步地给出了原始符号的上位概念的符号。 The second replace already adapts to the other patterns mentioned in the question (eg 00A01).第二个替换已经适应了问题中提到的其他模式(例如 00A01)。 With the original notation and the value in the new column, we can easily create the skos:broader triples by concatenating text and the values from both columns.使用原始符号和新列中的值,我们可以通过连接文本和两列中的值轻松创建 skos:broader 三元组。 These can then be exported from OpenRefine and just be copy-pasted to our SKOS vocabulary.然后可以从 OpenRefine 导出这些内容,然后将其复制粘贴到我们的 SKOS 词汇表中。

Here is a SPARQL answer based on the query in the question.这是基于问题中的查询的 SPARQL 答案。 Using filters and regex (as suggested in the comment by Yahalnaut as a reply to UninforomedUser above) is needed.需要使用过滤器和正则表达式(正如 Yahalnaut 在上面对 UninformedUser 的回复中所建议的那样)。 Creating a skos:broader relation based on two concept's notations requires them to hava an identical sequence of digits before the - .基于两个概念符号创建 skos:broader 关系要求它们在-之前具有相同的数字序列。 The comparison should only between the first part of the notations, so each 00- should match another 00- but not a 01- .比较应该只在符号的第一部分之间进行,因此每个00-应该匹配另一个00-而不是01- As asked, the solution below only considers topConcepts of the Vocabulary as potential objects for skos:broader.如所问,下面的解决方案仅将词汇的 topConcepts 视为 skos:broader 的潜在对象。 The concepts should also not relate to themselves, therefore the last filter.这些概念也不应该与它们本身相关,因此是最后一个过滤器。 This should then be adoptable to other patterns as well.这也应该适用于其他模式。 Depending on the number of Concepts and the memory available for the query, this may last a while or even stop before finished.根据可用于查询的概念和 memory 的数量,这可能会持续一段时间甚至在完成之前停止。 It eliminates lot of the effort though.它虽然消除了很多努力。

PREFIX owl: <http://www.w3.org/2002/07/owl#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix skos: <http://www.w3.org/2004/02/skos/core#> 
prefix msc: <http://msc.org/resources/MSC/msc2020/>  


construct {?s skos:broader ?y . } 
where { 
?s a skos:Concept ; skos:notation ?notation. 
?y skos:topConceptOf msc: ; skos:notation ?not2. 
bind (REPLACE (?not2 , "-XX" , "") as ?1)
bind  (REPLACE (?notation , "-\d\d", "" ) as ?2 )
filter (?1 = ?2)
filter (?not2 != ?notation)
}

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

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