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

问题描述

线程提出的问题.我目前尝试使用Optics API使用SPARQL和CTS进行搜索.我试图尝试使用以下代码

Question brought over from thread.I am currently trying to do a search with SPARQL and CTS using Optics API. I have attempted to try using the following 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(7500, cts:point(89.39101918779838, 51.97989163203445)),
    "type=long-lat-point")
  )

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

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

但是,在op:join-inner期间,尽管在$people$questions的op:result中具有相同的条目,但返回的结果为空.返回结果的一部分可以在下面看到.

However, during op:join-inner the results returned is empty despite having same entries in both op:result from $people and $questions. A piece of the results returned can be seen below.

返回的结果

lexicon.people

lexicon.people

{"lexicon.people":"/people/Aaren_DETERS/000000000055933"}
{"lexicon.people":"/people/Aaren_HOWK/000000000117433"}
{"lexicon.people":"/people/Aaren_HUSTEDT/000000000038649"}
{"lexicon.people":"/people/Aaren_SHUSTA/000000000123065"}
{"lexicon.people":"/people/Aaren_SIEBERS/000000000035010"}
{"lexicon.people":"/people/Aarika_BETHARD/000000000048955"}
{"lexicon.people":"/people/Aarika_CHO/000000000093078"}
{"lexicon.people":"/people/Aarika_EVORA/000000000117911"}
{"lexicon.people":"/people/Aarika_LUCKRITZ/000000000001593"}
{"lexicon.people":"/people/Aarika_MCALPHIN/000000000043365"}
{"lexicon.people":"/people/Aarika_PAET/000000000067579"}
{"lexicon.people":"/people/Aarika_SENGUN/000000000047752"}
{"lexicon.people":"/people/Aarika_WEDEMEYER/000000000022594"}
......

sparql.person

sparql.person

......
{"sparql.person":"/people/Aaren_CRIBLEZ/000000000087536", "sparql.dob":"1999-07-21T00:19:21"}
{"sparql.person":"/people/Aaren_DEBRITO/000000000049208", "sparql.dob":"2018-10-09T08:09:48"}
{"sparql.person":"/people/Aaren_DEMASTERS/000000000091082", "sparql.dob":"2014-08-21T06:43:44"}
{"sparql.person":"/people/Aaren_DETERS/000000000055933", "sparql.dob":"2011-09-11T02:44:22"}
{"sparql.person":"/people/Aaren_GARY/000000000100658", "sparql.dob":"1998-06-04T00:39:23"}
{"sparql.person":"/people/Aaren_HANNAWAY/000000000045087", "sparql.dob":"2002-06-17T05:45:15"}
{"sparql.person":"/people/Aaren_HOWK/000000000117433", "sparql.dob":"2002-06-21T06:00:34"}
{"sparql.person":"/people/Aaren_HUSTEDT/000000000038649", "sparql.dob":"2018-06-07T14:56:39"}
{"sparql.person":"/people/Aaren_JURICH/000000000039301", "sparql.dob":"2003-07-14T16:20:05"}
{"sparql.person":"/people/Aaren_KRACK/000000000101407", "sparql.dob":"2014-03-19T06:25:39"}
{"sparql.person":"/people/Aaren_MACCONNELL/000000000053205", "sparql.dob":"1995-06-21T16:15:53"}
.....

我还进行了一些其他测试,其中使用以下代码使用op:from-sparql

I have also done some additional testing where the following code was used to generate a portion of the results using op:from-sparql

let $query = 'SELECT * WHERE {?person </has_age> ? age . 
                              FILTER(?age > 75)}'
let $questions2 := op:from-sparql($query, "sparql2")

使用此结果,我执行了op:join-inner,并且效果很好.这使我认为op:from-lexicons可能返回的某些数据格式与op:from-sparql不兼容?任何澄清或建议将不胜感激.

Using this result I performed op:join-inner and it worked perfectly. This leads me to think that op:from-lexicons might be returning a certain data format that is not compatible with op:from-sparql? Any clarification or advise will be greatly appreciated.

==更新==

用于投射的查询

let $questions := op:from-sparql('SELECT * WHERE {?person </has_dob> ?dob. }', "sparql")
                => op:select((  "person", op:as('person_string',fn:string(op:col('person'))) ))

==更新2 ==

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(7500, cts:point(89.39101918779838, 51.97989163203445)),
    "type=long-lat-point")
  )

let $questions := op:from-sparql('SELECT * WHERE {?person </has_dob> ?dob. }', "sparql") 
                => op:select(( "dob", op:as('personStr',ofn:string(op:col('person'))) ))

return $questions  => op:join-inner(
    $people,
    op:on(
      "people","personStr"
    )
  ) => op:select(("personStr","dob")) => op:count("Row Count", "personStr") => op:result()

推荐答案

我相信URI词典的类型为xs:string,三重主题的类型通常为sem:iri.

I believe that the URI lexicon is typed as xs:string and that triple subjects are typically typed as sem:iri.

一种检查方法是在SPARQL行上使用带oxs:string()光学表达式的op:select()将主题值转换为内部联接之前的字符串.

One way to check would be to use an op:select() on the SPARQL rows with an oxs:string() Optic expression to cast the the subject values to strings prior to the inner join.

如果这行得通,那么使用TDE模板创建具有xs:string数据类型而不是sem:iri数据类型的主题可能是有益的.

If that works, then it might be beneficial to use a TDE template to create the subjects with the xs:string data type instead of the sem:iri data type.

希望有帮助,

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

10-12 01:01