[英]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
. 无论我使用
dbr:Game_of_Thrones
还是dbr:game_of_thrones
dbr:Game_of_Thrones
将返回true。
I tried using LCASE()
but it's not allowed inside the triples. 我尝试使用
LCASE()
但在三元组中不允许使用它。 Is there another way? 还有另一种方法吗? I'm using the DBpedia SPARQL endpoint ( https://dbpedia.org/sparql ).
我正在使用DBpedia SPARQL端点( https://dbpedia.org/sparql )。
IRIs are case-sensitive for good reasons. IRI区分大小写是有充分理由的。 If you really want to workaround this then you have to use
FILTER(lcase(str(?tmp)) = lcase(str(?r)))
in each UNION
clause: 如果您真的想解决此问题,则必须在每个
UNION
子句中使用FILTER(lcase(str(?tmp)) = lcase(str(?r)))
:
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. 请注意,这可能会导致性能下降,因为它必须扫描所有三元组并进行String比较。
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. 我还建议不要使用第二个
UNION
子句,只要您要查找的资源可能不是架构实体,因此就永远不会出现在RDF三元组的谓词位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.