简体   繁体   中英

Case insensitive match in SPARQL triple

Is there a way to make the following query case insensitive?

ASK {
    VALUES (?r) { (dbr:Game_of_Thrones) }
        { ?r ?p ?o }
        UNION
        { ?s ?r ?o }
        UNION
        { ?s ?p ?r }
    }

It shall return true no matter if I use dbr:Game_of_Thrones or dbr:game_of_thrones .

I tried using LCASE() but it's not allowed inside the triples. Is there another way? I'm using the DBpedia SPARQL endpoint ( https://dbpedia.org/sparql ).

IRIs are case-sensitive for good reasons. If you really want to workaround this then you have to use FILTER(lcase(str(?tmp)) = lcase(str(?r))) in each UNION clause:

ASK {
    VALUES (?r) { (dbr:Game_of_Thrones) }
        { ?tmp ?p ?o. FILTER(LCASE(STR(tmp)) = LCASE(STR(?r))) }
        UNION
        { ?s ?r ?o. FILTER(LCASE(STR(tmp)) = LCASE(STR(?r))) }
        UNION
        { ?s ?p ?r. FILTER(LCASE(STR(tmp)) = LCASE(STR(?r))) }
    }

Note, this can result in poor performance at it has to scan over all triples and do String comparison.

For fuzzy search, you should really think about a full-text index.

I'd also suggest omitting the second UNION clause as long as you're looking for resources that are probably not schema entities, thus, never occur in predicate position of an RDF triple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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