0

I need to find URIs of skos:Concept using skos:prefLabel (literal) from other skos:Concept. Here is my query:

SELECT ?variableURI ?variablePref ?entityPrefRegex ?entityURI ?entityPref WHERE {
    ?variableURI skos:prefLabel ?variablePref .
    FILTER(REGEX(?variablePref,"^Dissolved .* in surface water"))
    BIND(REPLACE(?variablePref,"^Dissolved (.*) concentration in surface water", "$1") AS ?entityPrefRegex).
    ?entityURI skos:prefLabel ?entityPref .
    FILTER(REGEX(?entityPref,?entityPrefRegex,"i")) 
}

My problem is that the filtering part return no result and I don't understand why.

Here are sample variables I'm trying to link my entities

variableURI variablePref entityPrefRegex
<:c_7e508e0e> "Dissolved aluminium concentration in surface water"@en "aluminium"@en
<:c_b5dec35c> "Dissolved arsenic concentration in surface water"@en "arsenic"@en
<:c_bc765ffd> "Dissolved boron concentration in surface water"@en "boron"@en
<:c_4ce4d2c7> "Dissolved caesium concentration in surface water"@en "caesium"@en

And the corresponding entities. As you can see the literal are identical except for the capital letter.

entityURI entityPref
<:c_d57d0742> "Aluminium"@en
<:c_d57d077> "Arsenic"@en
<:c_d57d0728> "Boron"@en
<:c_d57d0745> "Caesium"@en
charlycou
  • 1,778
  • 13
  • 37
  • the regex pattern is the second argument of the function `regex`, so it should be at least `FILTER(REGEX(?entityPref, ?entityPrefRegex, "i"))` - you should also consider to get the lexical form of literals, i.e. you should do `FILTER(REGEX(STR(?entityPref), STR(?entityPrefRegex),"i"))`, otherwise the filter will be evaulated to error because the pattern has to be a string and not a literal, thus, in the end the filter evaluates to false – UninformedUser Jan 24 '22 at 17:51
  • 1
    a dummy query works for me with the fix: `SELECT * { VALUES ?variablePref {"Dissolved aluminium concentration in surface water"@en} VALUES ?entityPref {"Aluminium"@en} FILTER(REGEX(?variablePref,"^Dissolved .* in surface water")) BIND(REPLACE(?variablePref,"^Dissolved (.*) concentration in surface water", "$1") AS ?entityPrefRegex). FILTER(REGEX(STR(?entityPref), STR(?entityPrefRegex),"i")) }` – UninformedUser Jan 24 '22 at 17:56
  • Thanks the STR() mehtod does the trick! – charlycou Jan 24 '22 at 18:05

1 Answers1

1

The pattern (second) argument to REGEX is a "simple literal" (a literal "without language tag or datatype IRI"). In this case, it looks like you are using ?entityPref values that have the @en language tag:

FILTER(REGEX(?entityPrefRegex,?entityPref,"i"))

Try instead casting the pattern to a plain string:

FILTER(REGEX(?entityPrefRegex,STR(?entityPref),"i"))