带有光学API(MarkLogic)的地理空间查询

时间:2019-06-03 10:43:08

标签: sparql marklogic

thread提出的问题。我目前正在尝试使用Optics API使用SPARQL和CTS进行搜索。我试图尝试使用以下代码

使用查询

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的op:result中具有相同的条目,但在$questions期间返回的结果为空。返回结果的一部分可以在下面看到。

返回的结果

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":"/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

生成了一部分结果。
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不兼容?任何澄清或建议将不胜感激。

==更新==

用于投射的查询

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()

1 个答案:

答案 0 :(得分:1)

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

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

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

希望有帮助,