简体   繁体   English

如何在MarkLogic中处理不区分大小写的SPARQL数据

[英]How to handle case-insensitive SPARQL data in MarkLogic

I'm trying to understand how best to handle literals in Marklogic SPARQL data which may be in any case. 我试图理解如何最好地处理Marklogic SPARQL数据中的文字,这在任何情况下都可能。 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"}

and

SELECT *
WHERE { ?s ?p "red"}

to return all values whether the object is "Red", "RED", "red" or "rED". 返回所有值,无论对象是“红色”,“红色”,“红色”还是“rED”。

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)? 或者,使用不区分大小写的排序规则在MarkLogic中创建一些新的范围查询是否有意义(如果可以在三重数据上进行)?

You could use a filter that ignores case. 您可以使用忽略大小写的过滤器。

select * where {
  ?s ?p ?o
  FILTER (lcase(str(?o)) = "red")
}

Based on the answer to another question . 基于另一个问题的答案

Edit: I asked Steve Buxton, MarkLogic's PM for semantics features, and he suggested this: 编辑:我问过MarkLogic的PM语义功能Steve Buxton,他建议:

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 is a MarkLogic 8 (now available through Early Access ) function that selects a group of triples. sem:store是MarkLogic 8(现在可通过Early Access获得 )功能,它选择一组三元组。 The SPARQL query then runs on the reduced set, limiting the number of triples that need to be filtered. 然后,SPARQL查询在简化集上运行,限制需要过滤的三元组数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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