1

As the title suggests, I have preferred labels in english and german. I am trying to extract each label by it's language and bind to a (newly created) variable.

SELECT ?copyC ?enLabel ?defaultLabel
WHERE {
?targetC skos:prefLabel ?prefUri .
?prefUri skosxl:literalForm ?b
  # handle languages - english and german
  bind(if(langMatches(lang(?b),"en"),?b,?_) as ?enLabel)
  bind(if(langMatches(lang(?b),"de"),?b, ?_) as ?defaultLabel)
  ####
   .
  # create some uris
  BIND(IRI(CONCAT("http://example.com/", REPLACE(STR(?enLabel), "\\W", "", "i") )) AS ?copyC ) .
  BIND(IRI(CONCAT("http://example.com/", REPLACE(STR(?enLabel), "\\W", "", "i"),"_prefLabel_en" )) AS ?enLabelc ) .
    BIND(IRI(CONCAT("http://example.com/", REPLACE(STR(?defaultLabel), "\\W", "", "i"),"_prefLabel_de" )) AS ?defaultLabelc ) .  
  ####
}

A toy example model:

@prefix skos: <http://www.w3.org/2004/02/skos/core#> . 
@prefix skosxl: <http://www.w3.org/2008/05/skos-xl#> .  <http://example_copy.com/thing1> a skos:Concept ;     
    skosxl:prefLabel <http://example_copy.com/some_german_label>, <http://example>  <http://example_copy.com/some_german_label> a skosxl:Label ;     
    skosxl:literalForm "some german label"@de .  <http://example_copy.com/some_english_label> a skosxl:Label ;     
    skosxl:literalForm "some english label"@en .
    

results:

?c                                ?enLabel                                         ?defaultLabel
1 <http://example.com/thing1> <http:/example.com/some_english_label>                                                                        
2                                                              <http:/example.com/some_german_label>

above query follows this post: SPARQL filter language if possible in multiple value context

The ?englishLabelc is correctly associated to the bound ?copyC variable but the ?defaultLabelc is not. My desire is that both the english and german label will correctly be associated uri bound to ?copyC. I assume there is a scope problem in how I am "BIND"ing the ?copyC variable but I am not sure how to go about troubleshooting. If I simply use the ?b variable to create ?copyC two concepts will be created - one for the english and one for the german label which is what I want. Can someone help me figure this out?

Mason Edmison
  • 594
  • 3
  • 16
  • I'm a bit confused, but in my opinion the current query doesn't lead to the current shown result. I mean, the result shows URIs but not labels. Am I missing something? – UninformedUser Jul 29 '20 at 03:05
  • in general, the whole toy example is wrong. prefixes etc. won't match the query. I fixed it and the query `prefix skosxl: prefix skos: SELECT ?c ?enLabel ?defaultLabel WHERE { ?c skos:prefLabel ?prefUri . ?prefUri skosxl:literalForm ?b # handle languages - english and german bind(if(langMatches(lang(?b),"en"),?b,?_) as ?enLabel) bind(if(langMatches(lang(?b),"de"),?b, ?_) as ?defaultLabel) }` works as expected – UninformedUser Jul 29 '20 at 03:19
  • data: `@prefix skos: . @prefix skosxl: . a skos:Concept ; skos:prefLabel , a skosxl:Label ; skosxl:literalForm "some german label"@de . a skosxl:Label ; skosxl:literalForm "some english label"@en .` – UninformedUser Jul 29 '20 at 03:19
  • Hi, thanks and sorry for the wonky toy example. I have made edits above. Also I realize that problem specifically arises when I try to attach these labels to my newly created variable ?copyC (illustrated in edits above). If you could take a look and let me know what you think it would be greatly appreciated. – Mason Edmison Jul 29 '20 at 14:06
  • you use the binding of `?enLabel` to create `?copyC` - but this clearly does **not** exist for the bindingset with the German label. I mean, SPARQL evaluates the triple patterns and finds two bindings that match the graph pattern, right? So, for one binding there is no such English label, thus, `?enLabel` is not bound, thus, the IRIs will not be generated. Do you get what I mean? – UninformedUser Jul 29 '20 at 20:00
  • I understand. Do you see an alternate way to achieve what it is I am try to do using SPARQL? Worst case scenario I can write a python script to manually handle this - but thought I would give a shot to do this task solely in SPARQL. – Mason Edmison Jul 29 '20 at 22:59

0 Answers0