如何在MarkLogic中处理不区分大小写的SPARQL数据 [英] How to handle case-insensitive SPARQL data in MarkLogic
问题描述
我试图了解如何最好地处理Marklogic SPARQL数据中的文字(无论如何).我希望能够进行不区分大小写的搜索,但是我相信语义查询是不可能做到的.对于一个简单的例子,我想要:
I'm trying to understand how best to handle literals in Marklogic SPARQL data which may be in any case. I'd like to be able to do a case insensitive search but I believe that isn't possible with semantic queries. For a simplistic example I want:
SELECT *
WHERE { ?s ?p "Red"}
和
SELECT *
WHERE { ?s ?p "red"}
返回所有值,无论对象是"Red","RED","red"还是"rED".
to return all values whether the object is "Red", "RED", "red" or "rED".
我的数据来自具有可变大小写规则的另一个来源.目前,我唯一想到的就是添加一个额外的三元组,该三元组始终以小写形式包含文本,以便我始终可以搜索该值.另外,是否可以使用不区分大小写的排序规则在MarkLogic中创建一些新的范围查询(如果可能在三重数据上使用)?
My data is from another source which has variable capitalisation rules. At the moment the only thing I can think of is to add an extra triple which always contains the text in lower case so I can always search on that value. Alternatively, would it make sense to create some new range query in MarkLogic with a case insensitive collation (if that's possible on triple data)?
推荐答案
您可以使用忽略大小写的过滤器.
You could use a filter that ignores case.
select * where {
?s ?p ?o
FILTER (lcase(str(?o)) = "red")
}
我向MarkLogic的PM Steve Buxton询问了语义功能,他提出了以下建议:
I asked Steve Buxton, MarkLogic's PM for semantics features, and he suggested this:
let $store := sem:store( (), cts:element-value-query(xs:QName("sem:object"), "red", "case-insensitive") )
return
sem:sparql('
SELECT ?o
WHERE {
?s ?p ?o
FILTER (lcase(str(?o)) = "red")
}', (), (), $store
)
sem:store是MarkLogic 8(现在可通过早期访问获得))功能,选择一组三元组.然后在缩减集上运行 SPARQL 查询,限制需要过滤的三元组的数量.
sem:store is a MarkLogic 8 (now available through Early Access) function that selects a group of triples. The SPARQL query then runs on the reduced set, limiting the number of triples that need to be filtered.
这篇关于如何在MarkLogic中处理不区分大小写的SPARQL数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!