You can bind to an external variable that returns the subject outside the
binding like so:

'use strict';
//xdmp.documentInsert("/foo.xml",{"triple" :
sem.triple(sem.iri('foo'),sem.iri('hasBar'),sem.iri('bar'))});

var sem = require('/MarkLogic/semantics');
var s0 = { 's0': [ sem.iri('foo')] }
sem.sparql('SELECT * WHERE { ?s ?p ?o  FILTER(?s = ?s0)}',s0)


On Sun, May 15, 2016 at 3:00 PM, <general-requ...@developer.marklogic.com>
wrote:

> Send General mailing list submissions to
>         general@developer.marklogic.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://developer.marklogic.com/mailman/listinfo/general
> or, via email, send a message with subject or body 'help' to
>         general-requ...@developer.marklogic.com
>
> You can reach the person managing the list at
>         general-ow...@developer.marklogic.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of General digest..."
>
>
> Today's Topics:
>
>    1. sem.sparql: get bound placeholders in the result (Florent Georges)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sun, 15 May 2016 13:41:47 +0200
> From: Florent Georges <li...@fgeorges.org>
> Subject: [MarkLogic Dev General] sem.sparql: get bound placeholders in
>         the     result
> To: MarkLogic Developer Discussion <general@developer.marklogic.com>
> Message-ID:
>         <CADyR_r2yxSC__=qmf83eECJH=
> uasfvz+amdqaradaqkr75p...@mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> Hi,
>
> Using `sem.sparql()`, it is possible to bind a SPARQL placeholder to
> an array, to serve as many alternatives to the placeholder in the
> triples pattern.  For instance, the following query:
>
>     require('/MarkLogic/semantics').sparql(
>        'SELECT * WHERE { ?s ?p ?o }',
>        { 's': [ sem.iri('#1'), sem.iri('#2') ] })
>
> returns the predicates and values for al triples with the subject
> equal to either `#1` or `#2`.
>
> Problem is, the bound placeholder is not part of the result (in this
> example, `?s`).  The result is an iterator over objects of the
> following form:
>
>     { p: "#pred", o: "value" }
>
> So it is not possible to use the result in a way to would need to know
> which subject each row is attached to (which I believe is generally
> the case when binding them to arrays, as opposed to scalar values).
>
> Is there any way to have `sem.sparql()` include bound placeholders in
> the result?
>
> Regards,
>
> --
> Florent Georges
> http://fgeorges.org/
> http://h2oconsulting.be/
>
>
> ------------------------------
>
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
> End of General Digest, Vol 143, Issue 21
> ****************************************
>
_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to