SPARQL地理空间查询(MarkLogic) [英] SPARQL Geospatial Queries (MarkLogic)

查看:142
本文介绍了SPARQL地理空间查询(MarkLogic)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处继续上一个问题.需要指出的是,在SPARQL查询中应避免使用fn:doc().但是,除了下面显示的代码外,对于地理空间查询,我无法找到其他解决方案.我也使用了这个查询,它的运行时间确实很慢.对于更大的数据集,它将达到1小时超时.

Carrying on from a previous question here. Where it was noted that avoiding fn:doc() should be avoided in SPARQL queries. However, for geospatial queries aside from the code shown below I am unable to find an alternative solution. I have also used this query and it's runtime is really slow. For bigger set of data it will hit the 1 hour timeout.

因此,我想问问是否有更好的方法为SPARQL实现地理空间查询?可以在PREFIX spatial:<http://jena.apache.org/spatial#>中使用GEOSPARQL吗?

Hence, I would like to ask if there is a better way in implementing Geospatial queries for SPARQL? Is it possible to use GEOSPARQL with PREFIX spatial:<http://jena.apache.org/spatial#>?

xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";
import module namespace thsr="http://marklogic.com/xdmp/thesaurus" 
                             at "/MarkLogic/thesaurus.xqy";

let $query := sem:sparql(
'
PREFIX xs: <http://www.w3.org/2001/XMLSchema#>
PREFIX cts: <http://marklogic.com/cts#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema/>
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX db: <http://dbpedia.org/resource/>
PREFIX onto: <http://dbpedia.org/ontology/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns>
PREFIX xdmp: <http://marklogic.com/xdmp#>

SELECT *
WHERE{
?people </posted> ?question .
FILTER (cts:contains(fn:doc(?people), 
cts:path-geospatial-query("/people_data/location",  cts:circle(10, cts:point(59,28)))
)) .
}',
(),
(),
()
)

return (xdmp:elapsed-time())

======= 更新 =======

=======Update========

问题转交给线程

推荐答案

我在这里看到两个选项:

I see two options here:

  • 您可以使用MarkLogic内置的地理空间功能直接从SPARQL内部查找地理空间重叠,最好是比较RDF属性,而不是比较路径索引中的值(仍然不理想)
  • 更好:预取与您的地理空间约束匹配的文档列表,并将其作为约束输入到您的SPARQL中(这应该是高性能的)

类似的东西:

let $uris := cts:uris((), (), cts:path-geospatial-query("/people_data/location",  cts:circle(10, cts:point(59,28))))
return sem:sparql('
  SELECT *
  WHERE{
    ?person </posted> ?question .
    FILTER (?person = ?people) .
  }
', map:entry("people", $uris))

上面示例的更方便,更好的优化是使用Optic API重写它.它专门用于提供一种高性能的方式来弥合各种数据模型之间的差距.

A slightly more convenient, and better optimized of above example would be to rewrite it using Optic API. It is designed specifically for providing a highly performant way of bridging the gap between the various data models.

推断上面的代码,我认为它将在光学代码中读取如下内容:

Extrapolating on the above code, I think it would read something like this in optic code:

import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy";

let $people := op:from-lexicons(
  map:entry("people", cts:uri-reference()),
  "lexicon"
)
  => op:where(
    cts:path-geospatial-query("/people_data/location", cts:circle(10, cts:point(59,28)))
  )

let $questions := op:from-sparql('SELECT * WHERE { ?person </posted> ?question. }', "sparql")

return $people
  => op:join-inner(
    $questions,
    op:on(
      op:view-col("lexicon", "people"),
      op:view-col("sparql", "person")
    )
  )
  =>op:result()

在没有适当的数据和索引的情况下进行测试有点困难,但是我希望它足以使您入门.

It is a bit hard to test it without proper data and indexes, but I hope it is enough to get you started.

您可以在此处找到介绍性文档:

You can find introductory documentation on it here:

https://docs.marklogic.com/guide/app-dev/OpticAPI

有关API的参考资料,请参见:

And the API reference can be found here:

https://docs.marklogic.com/op

HTH!

这篇关于SPARQL地理空间查询(MarkLogic)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆