On 4 Jun 2012, at 10:43, Fariz Darari wrote:
> Dear Jena ARQ Community,
>
> I have this SPARQL query:
>
> *select ("abc" AS ?ABC) where {?ind a <http://dbpedia.org/ontology/Animal>}*
>
> Basically this query embeds a literal ("abc") in the head (inside the
> SELECT clause). I have looked into the javadoc of Jena ARQ, but it seems
> that the class Query (com.hp.hpl.jena.query) doesn't support to represent
> constant/literal in head.
Hi Fariz,
ARQ can do this. You need to use:
Query#addResultVar(String varName, Expr expr) [1]
The trick is to realise that ("abc" AS ?ABC) is just a constant expression
"abc", which is represented as a NodeValue [2] expression:
query.addResultVar("ABC", NodeValue.makeString("abc"));
Damian
[1]
<http://jena.apache.org/documentation/javadoc/arq/com/hp/hpl/jena/query/Query.html#addResultVar(com.hp.hpl.jena.graph.Node,%20com.hp.hpl.jena.sparql.expr.Expr)>
[2]
<http://jena.apache.org/documentation/javadoc/arq/com/hp/hpl/jena/sparql/expr/NodeValue.html>