本文介绍了如何从Sparql在Marklogic中创建和使用GeoSpatial索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用RDF导入将geonames.org中的地理空间数据加载到Marklogic中.

I have loaded the geospatial data from geonames.org into Marklogic using RDF import.

使用查询控制台浏览数据时,我看到数据已加载到xml文档中,如下所示:

When using the Query Console to explore the data, I see the data has been loaded into an xml document and looks like this:

<sem:triple>
<sem:subject>http://sws.geonames.org/2736540/</sem:subject>
<sem:predicate>http://www.w3.org/2003/01/geo/wgs84_pos#lat</sem:predicate>
<sem:object datatype="http://www.w3.org/2001/XMLSchema#string">40.41476</sem:object>
</sem:triple>
<sem:triple>
<sem:subject>http://sws.geonames.org/2736540/</sem:subject>
<sem:predicate>http://www.w3.org/2003/01/geo/wgs84_pos#long</sem:predicate>
<sem:object datatype="http://www.w3.org/2001/XMLSchema#string">-8.54304</sem:object>
</sem:triple>

我能够执行SPARQL DESCRIBE并查看数据.这是一个例子.

I am able to do a SPARQL DESCRIBE and see data. Here is an example.

@prefix geonames: <http://www.geonames.org/ontology#> .
@prefix xs: <http://www.w3.org/2001/XMLSchema#> .
@prefix p0: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
<http://sws.geonames.org/2736540/> geonames:parentCountry <http://sws.geonames.org/2264397/> ;
                                   geonames:countryCode "PT"^^xs:string ;
                                   p0:long "-8.54304"^^xs:string ;
                                   geonames:featureCode <http://www.geonames.org/ontology#P.PPL> ;
                                   geonames:parentADM1 <http://sws.geonames.org/2742610/> ;
                                   geonames:parentFeature <http://sws.geonames.org/2742610/> ;
                                   <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> "http://sws.geonames.org/2736540/about.rdf"^^xs:string ;
                                   a geonames:Feature ;
                                   geonames:locationMap <http://www.geonames.org/2736540/pedreira-de-vilarinho.html> ;
                                   geonames:name "Pedreira de Vilarinho"^^xs:string ;
                                   geonames:nearbyFeatures <http://sws.geonames.org/2736540/nearby.rdf> ;
                                   geonames:featureClass geonames:P ;
                                   p0:lat "40.41476"^^xs:string .

我想使用SPARQL QUERY作为查询类型来查询这些数据,以便可以利用MarkLogic可以创建的地理空间索引.

I want to query over this data using SPARQL QUERY as my Query Type in a way where I can take advantage of the geospatial indexes that MarkLogic can create.

我在这两个方面都遇到了麻烦.

I have been having trouble with two aspects of this.

  1. 如何为wgs84_pos#lat和wgs84_pos#long谓词正确创建地理空间索引?
  2. 如何从SPARQL QUERY中访问这些索引?

我希望有一个sparql查询,它能够找到某个Point范围内的主题.

I would like to have a sparql query that would be able to find subjects within some range of a Point.

====================================

=====================================

跟进:

在遵循了David Ennis的回答之后(很好地工作,谢谢!),我最终得到了这个示例Xquery,它能够通过geosearch从文档中选择数据,然后在sparql值查询中使用这些IRI.

After following David Ennis's Answer (Which worked nicely, thanks!) I ended up with this sample Xquery that was able to select data out of documents via geosearch and then use those IRI's in a sparql values query.

示例:

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

let $matches := cts:search(//rdf:RDF,
  cts:element-pair-geospatial-query (
    fn:QName("http://www.geonames.org/ontology#","Feature"),
    fn:QName("http://www.w3.org/2003/01/geo/wgs84_pos#", "lat"),
    fn:QName ("http://www.w3.org/2003/01/geo/wgs84_pos#","long"),
    cts:circle(10, cts:point(19.8,99.8))))

let $iris := sem:iri($matches//@rdf:about)

let $bindings := (fn:map(function($n) { map:entry("featureIRI", $n) }, $iris))

let $sparql := '
  PREFIX wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
  SELECT *
  WHERE {
    ?featureIRI wgs:lat ?lat;
                wgs:long ?long.
  }
'

return sem:sparql-values($sparql, $bindings)

此xquery查询地理空间索引,找到匹配的文档,然后在xml文档的rdf:about属性中选择IRI.然后,它将在所有这些IRI上进行映射,并创建可以在sem:sparql-values函数的bindings参数中传递的映射条目.

This xquery queries the geospatial index, finds matching documents and then selects the IRI in the rdf:about attribute of the xml document.It then maps over all of those IRIs and creates map entries that can be passed in the bindings parameter of the sem:sparql-values function.

推荐答案

我不相信您可以仅通过本机SPARQL来完成您想做的事情.任何SPARQL实施中的地理空间查询都是geoSPARQL,Apache Jena地理空间查询等扩展.

I do not believe you can do what you want via just native SPARQL. Geospacial queries in any SPARQL implementation are extensions like geoSPARQL, Apache Jena geospacial queries etc.

我在MarkLogic中建议的方法:

My suggested approach in MarkLogic:

  1. 将地名主体作为非托管三元组(每个XML或JSON文档中都嵌入了三元组)插入MarkLogic中
  2. 在同一文档中,以可接受的MarkLogic格式之一包含地理空间数据.本质上,这将地理空间元数据添加到三元组中,因为它位于同一片段中.
  3. 为地理空间数据添加地理空间路径范围索引.
  4. 在具有cts查询限制的MarkLogic内部使用SPARQL.

以上构建基块:

  • Understanding unmanaged triples
  • Understanding Geo-spacial Region Types
  • Understanding Geo-spacial Indexes
  • Understanding Geo-spacial Queries
  • Understanding Semantics with cts search

用于最终查询的另一种方法可以是光学API ,但我看不出它会否定执行步骤1-3的需要

Another approach to the final query could be the Optic API but I do not see how it would negate the need to do steps 1-3

这篇关于如何从Sparql在Marklogic中创建和使用GeoSpatial索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 00:49