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
Query Used
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()
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.
Results Returned
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"}
.....
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")
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.
==Update==
Query used for casting
let $questions := op:from-sparql('SELECT * WHERE {?person </has_dob> ?dob. }', "sparql")
=> op:select(( "person", op:as('person_string',fn:string(op:col('person'))) ))
==Update 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()
I believe that the URI lexicon is typed as xs:string and that triple subjects are typically typed as sem:iri.
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.
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.
Hoping that helps,