0

The query below works when I include the line that uses CONTAINS for the filter, but fails if I simply check if the value (LCASE) is equal to "donald trump" (it is).

Use this line, and it works:

FILTER(CONTAINS(LCASE(?idLabel), "donald trump") ).

Use this line, and it fails:

FILTER(LCASE(?idLabel) = "donald trump") .

The output for the query that WORKS has idLabel = "Donald Trump"

SPARQL Query:

SELECT DISTINCT ?id ?idLabel ?PV WHERE {

  ?id wdt:P106 ?V0. VALUES ?V0 { wd:Q39631  } . 

  OPTIONAL {
        ?id rdfs:label ?idLabel .
        FILTER(LANG(?idLabel) = 'en') .
  } .

    # Filter on Label

    # WORKS:
    FILTER(CONTAINS(LCASE(?idLabel), "donald trump") ).

    # DOES NOT WORK
    #FILTER(LCASE(?idLabel) = "donald trump") .

    # subselect on instance type
    {
       SELECT ?id WHERE {
         ?id wdt:P31/wdt:P279* ?PV . VALUES(?PV) {(wd:Q5) } .
       }
    }  .
}

Try it here

My question is WHY the second option does NOT work ?

(And yes, I'm looking for the surgeon Donald Trump, not that other guy)

Andy
  • 842
  • 1
  • 12
  • 24

1 Answers1

2

The labels in Wikidata have language tags, thus, the label literal is

"Donald Trump"@en

and the string after LCASE will be

"donald trump"@en

Indeed CONTAINS works here.

You have to use STR function to get the lexical form, i.e. just

"Donald Trump"

Solution:

FILTER(LCASE(STR(?idLabel)) = "donald trump") .

UninformedUser
  • 8,397
  • 1
  • 14
  • 23