简体   繁体   中英

How to build case-insensitive SPARQL filter?

I am trying to build some queries with SPARQL searching by the label field without case sensivity.

I start from this query which works fine:

SELECT distinct ?concepto, ?objeto, ?label WHERE {?concepto rdfs:comment ?objeto. ?concepto rdfs:label ?label. FILTER (lang(?label) = 'es' && ?label='Francisco de Quevedo'@es && (lang(?objeto) = 'es' || lang(?objeto) = 'en'))} LIMIT 100

But if I try to add a FILTER constraint to make the query case insensitive, it doesn't work:

SELECT distinct ?concepto, ?objeto, ?label WHERE {?concepto rdfs:comment ?objeto. ?concepto rdfs:label ?label. FILTER (lang(?label) = 'es' && lcase(str(?label))='francisco de quevedo'@es && (lang(?objeto) = 'es' || lang(?objeto) = 'en'))} LIMIT 100

Diferent options to do queries searching by labels searching general concepts (ie: Galaxy, Mountain, Francisco de Quevedo). I need to identify only one object that contains this topics and I don't know previously if the label is registered in lower or upper case.

Next code doesn't work (it's a heavy query, and take all the objects that CONTAIN tha word Galaxy:

SELECT distinct ?concepto ?objeto ?label WHERE {?concepto rdfs:comment ?objeto. ?concepto rdfs:label ?label FILTER (lang(?label) = 'es' && (lang(?objeto) = 'es' || lang(?objeto) = 'en') && regex(?label, "Galaxia","i"))} LIMIT 100

This other code works fine, I obtain the correct object but I need to know exactly how it is write (upper or lower case):

SELECT distinct ?concepto ?objeto ?label WHERE { ?concepto rdfs:comment ?objeto. ?concepto rdfs:label ?label FILTER (lang(?label) = 'es' && (lang(?objeto) = 'es' || lang(?objeto) = 'en') && ?label = "Galaxia"@es)} LIMIT 1000

And the last one is ok with the performance but obtain lots of results, I need to obtain only the object Galaxy searching by label in Spanish:

SELECT distinct ?concepto ?objeto ?label WHERE {?concepto rdfs:comment ?objeto. ?concepto rdfs:label ?label. ?label bif:contains '"Galaxia"' FILTER (lang(?label) = 'es' && (lang(?objeto) = 'es' || lang(?objeto) = 'en'))} LIMIT 100

应用STR(?label)导致语言标签被删除,因此@es从要比较的字符串中删除@es

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