-1

The following SPARQL query

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. However, this is only the first of 63 top level classes altogether, so I would like to "loop" over all top level classes automatically. On top, I would like to adapt this to other patterns. Is there a way to do this with SPARQL? If not, what would you recommend instead?

Yahalnaut
  • 157
  • 1
  • 8
  • Just select all top level classes as well in your WHERE clause. I mean, it's basically a cartesian product. Just get the top level classes with a different variable than `?s` and use this instead of your hard-coded class. Done – UninformedUser Mar 02 '21 at 14:56
  • 1
    Do you mean a query like this? `PREFIX owl: PREFIX rdf: PREFIX rdfs: prefix skos: prefix msc: #level 1 zu level 2 - variante a construct {?s skos:broader ?y . } #select * where { ?s a skos:Concept ; skos:notation ?notation. ?y skos:topConceptOf msc: ; skos:notation ?not2. filter regex (?notation, "00-\d\d") filter regex (?not2, "00-XX") }` But that doesn't get the wanted result. – Yahalnaut Mar 02 '21 at 15:14
  • I don't know your data, but what is `?y skos:topConceptOf msc:` supposed to do in your opinion? I mean, `msc:` is just the prefix without anything. Is this an entity in your data? Why are you not just getting all top level classes by binding it to a variable? Like `?y skos:topConceptOf ?yy` - again, I don't know your data, but somehow you should be able to identify the top level classes by graph patterns or not? – UninformedUser Mar 02 '21 at 15:49
  • 1
    also, it is mostly useless to say "doesn't get the wanted result" ... we don't know your data, we don't know what the query does return and we don't know the expected result - makes sense, right? So again, in your RDF dataset, how are the top level classes modelled? Are there any triple that already indicate a class being a top level class? – UninformedUser Mar 02 '21 at 15:50
  • > what is ?y skos:topConceptOf msc: supposed to do in your opinion? It's giving all resources that are in a topConceptOf relation with msc:. msc: is the vocabulary. ?y is the variable for top level classes and it is now used in the construct query like you suggested. – Yahalnaut Mar 04 '21 at 16:18
  • Please excuse, if the wrong impression was created: Our data does not include the skos:broader relations between, e.g. concepts with notation 00-XX and 00-01, 00-02, yet (unfortunately). We want to construct them by comparing notations. This is time-consuming when there are many notations, because we have have to make sure that 00-\d\d only has skos:broader to 00-XX and not to 63-XX. We have to manually update the query many times. Can this be done faster? – Yahalnaut Mar 04 '21 at 16:19

2 Answers2

1

In the meantime we found a solution without 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.

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.

We use GREL's value.replace on the cells with the notations to create a new column:

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 (e.g. 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. These can then be exported from OpenRefine and just be copy-pasted to our SKOS vocabulary.

noidea
  • 36
  • 3
1

Here is a SPARQL answer based on the query in the question. Using filters and regex (as suggested in the comment by Yahalnaut as a reply to UninforomedUser above) is needed. Creating a skos:broader relation based on two concept's notations requires them to hava an identical sequence of digits before the - . The comparison should only between the first part of the notations, so each 00- should match another 00-but not a 01-. As asked, the solution below only considers topConcepts of the Vocabulary as potential objects for 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. 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)
}
noidea
  • 36
  • 3