Hi Holger
Thanks for the quick reply. Here are the source lines:
Map<String,RDFNode> map = new HashMap<String,RDFNode>();
map.put("predicate",RDF.Type);
Template templ = SPINFactory.asTemplate(sub);
com.hp.hpl.jena.query.Query arqQ =
ARQFactory.get().createQuery((Select)templ.getBody());
org.topbraid.spin.model.Query spinQuery = new
ARQ2SPIN(model).createQuery(arqQ, null);
StringBuilder queryBldr = new StringBuilder();
StringPrintContext printCntxt = new StringPrintContext(queryBldr,map);
spinQuery.print(printCntxt);
String sparqlStr = queryBldr.toString();
System.out.println(sparqlStr);
It still gives me the query with variables.
thanks
-amit
On Tue, Oct 18, 2011 at 2:22 PM, Holger Knublauch <[email protected]>wrote:
> Hi Amit,
>
> if you pass in the pre-bound variables as initialBindings, then the printed
> string will have the variables replaced, and you can use the string in
> non-Jena systems. If this does not work, I would need to see your source
> code.
>
> Thanks
> Holger
>
>
> On Oct 18, 2011, at 5:32 PM, Amit Jain wrote:
>
> Hi
> I am trying to do the same, getting a template stored in SPIN RDF format,
> get the SPIN query object and then get the sparql query with the variables
> in the template replaced with the runtime arguments. Now java source code
> attached in this thread does allow using jena QueryExecution to run the ARQ
> query on a model, this does not allow using other non-jena systems. Hence i
> want to be able to get the actual Sparql query with the replaced arguments
> and use it. Using the string builder and stringprintcontext gives me back
> the original query with the variables only.
> thanks for the help
> -amit
>
> On Wed, Jul 6, 2011 at 3:14 PM, Holger Knublauch
> <[email protected]>wrote:
>
>> Hi Laszlo,
>>
>> for help and clarification why remote query executions don't support
>> pre-bindings, you may need to follow up with the Jena mailing list. However,
>> there is a solution with the SPIN API that allows you to pre-bind variables
>> at serialization time. The effect is that when you have a SPIN RDF object
>> (Query) you can set variables in the PrintContext and this will create a
>> query string where the variables have been replaced with the values. I am
>> not 100% sure that this covers all cases, but it might work in your
>> scenarios. Something like
>>
>> StringBuilder sb = new StringBuilder();
>> StringPrintContext c = new StringPrintContext(sb, initialBindings);
>> query.print(c);
>> String arqString = sb.toString();
>>
>> would give you a string that you can then convert to a remote Jena query.
>>
>> Cheers,
>> Holger
>>
>
> --
> 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