Hi Holger,

thanks, it was giant leap towards the solution. However, it is important
that I can run the instantiated template query against an external SPARQL
endpoint, as seen in the following snippet.


        Query arqQuery =
ARQFactory.get().createQuery((org.topbraid.spin.model.Construct)templ.getBody());
        List<String> sparqlEndpoint = new ArrayList<String>();
        sparqlEndpoint.add("http://edgy:8890/sparql";);

        QueryEngineHTTP qexec =
ARQFactory.get().createRemoteQueryExecution(arqQuery, sparqlEndpoint);

        QuerySolutionMap arqBindings = new QuerySolutionMap();
        arqBindings.add("predicate", RDFS.label);
        arqBindings.add("arg1", postalCodeProp);

        qexec.setInitialBinding(arqBindings);
        qexec.execConstruct(newTriples);

ISSUE: QueryEngineHTTP doesn't not implement setInitialBinding. :( An
alternative could be (as I've heard), to add SERVICE to the query. However,
I didn't find a way to do it using some factory or fluent builder in the
API. I could surely resort to toString() and some regex or String.replace
magic, but then SPIN API would be degraded to a SPARQL serialization library
in the given scenario.

Let me know what you think.

Thanks,

Las


2011/7/5 Holger Knublauch <[email protected]>

> Hi László,
>
> I have just added a small example of the SPIN API to create and invoke a
> SPIN template.
>
> The key idea is to use pre-binding of variables in the Jena QueryExecution:
>
> com.hp.hpl.jena.query.Query arq =
> ARQFactory.get().createQuery((Select)template.getBody());
> QueryExecution qexec = ARQFactory.get().createQueryExecution(arq, model);
> QuerySolutionMap arqBindings = new QuerySolutionMap();
> arqBindings.add("predicate", RDFS.label);
> qexec.setInitialBinding(arqBindings); // Pre-assign the arguments
> ResultSet rs = qexec.execSelect();
>
> The full source code is attached. Please follow up if this doesn't cover
> your use case.
>
> Regards,
> Holger
>
>
> On Jul 1, 2011, at 11:21 PM, László Török wrote:
>
> Hi Scott,
>
> thanks, I think I'm sufficiently comfortable with TBC. What I don't quite
> grok yet, is how to do even simple things programmatically.
>
> Given the example SPIN template below, I'd like to replace the template
> variable with an actual property (which is a resource).
>
> Well, I can surely call toString() on Template to get the SPARQL query as
> string and do some regex magic, but there has to be a more elegant way. The
> javadoc is not very intuitive unfortunatelly. Any pointers how to do that?
> (TBC must be doing it somehow too.. :), no I'm not developing a TBC clone :)
> )
>
> Thanks,
>
> Las
>
> 2011/7/1 Scott Henninger <[email protected]>
>
>> Las; You should be able to run the SPARQL query against an endpoint
>> using the SERVICE keyword.  E.g.:
>>
>> CONSTRUCT{
>>    _:b0 a spin:ConstraintViolation .
>>    _:b0 spin:violationRoot ?s .
>>    _:b0 spin:violationPath ?arg1 .
>> }
>> WHERE{
>>    SERVICE <service-uri>
>>    {  ?s ?arg1 ?value .
>>       FILTER (!regex(str(?value), "^[0-9]{5}$"^^xsd:string))
>>    }
>> }
>>
>> If you're overwhelmed by the SPIN API, you may want to download TBC-SE/
>> ME/Free (http://www.topquadrant.com/products/TB_install.php) to
>> experiment with SPIN features before jumping headlong into the API.
>>
>> -- Scott
>>
>>
>> On Jul 1, 5:45 am, Las <[email protected]> wrote:
>> > Hi,
>> >
>> > just started playing with SPIN 1.2, and I'm a bit overwhelmed.
>> >
>> > Basically, I've managed to load a serialized SPIN template. [1] I'd
>> > like to set the free template variables and run it against a SPARQL
>> > endpoint without loading all it's triples into memory (Jena Model).
>> >
>> > Can anybody give me some pointers how to do that?
>> >
>> > Thx,
>> > Las
>> >
>> > [1]
>> http://semwebquality.org/ontologies/dq-constraints#FiveDigitNumericAll
>>
>> --
>> You received this message because you are subscribed to the Google
>> Group "TopBraid Suite Users", the topics of which include TopBraid
>> Composer,
>> TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN.
>> To post to this group, send email to
>> [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/topbraid-users?hl=en
>>
>
>
>
> --
> László Török
>
> Skype: laczoka2000
> Twitter: @laczoka
>
>
> --
> You received this message because you are subscribed to the Google
> Group "TopBraid Suite Users", the topics of which include TopBraid
> Composer,
> TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN.
> To post to this group, send email to
> [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/topbraid-users?hl=en
>
>
> --
> You received this message because you are subscribed to the Google
> Group "TopBraid Suite Users", the topics of which include TopBraid
> Composer,
> TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN.
> To post to this group, send email to
> [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/topbraid-users?hl=en
>
>
>


-- 
László Török

Skype: laczoka2000
Twitter: @laczoka

-- 
You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include TopBraid Composer,
TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en

Reply via email to