How to handle case-insensitive SPARQL data in MarkLogic

雨燕双飞 提交于 2021-02-18 21:58:37

问题


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"}

and

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

to return all values whether the object is "Red", "RED", "red" or "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)?


回答1:


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:

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. The SPARQL query then runs on the reduced set, limiting the number of triples that need to be filtered.



来源:https://stackoverflow.com/questions/27255449/how-to-handle-case-insensitive-sparql-data-in-marklogic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!