You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Kelvin Qian (Jira)" <ji...@apache.org> on 2022/01/04 15:55:00 UTC
[jira] [Created] (JENA-2242) Include VALUES clause in string when stringifying a WhereBuilder
Kelvin Qian created JENA-2242:
---------------------------------
Summary: Include VALUES clause in string when stringifying a WhereBuilder
Key: JENA-2242
URL: https://issues.apache.org/jira/browse/JENA-2242
Project: Apache Jena
Issue Type: Improvement
Components: QueryBuilder
Affects Versions: Jena 4.3.2
Reporter: Kelvin Qian
Assignee: Claude Warren
Currently when stringifying a WhereBuilder (e.g. for debugging), any VALUES clause is not included in the output of .toString:
{code:java}
import java.util.HashMap;
import org.apache.jena.graph.Node;
import org.apache.jena.grpah.Triple;
import org.apache.jena.arq.querybuilder.Converters;
import org.apache.jena.arq.querybuilder.WhereBuilder;
// Node creation
Node svarNode = Converters.checkVar(NodeFactory.createVariable("s"));
Node pvarNode = Converters.checkVar(NodeFactory.createVariable("p"));
Node ovarNode = Converters.checkVar(NodeFactory.createVariable("o"));
// Values map creation
ArrayList<Node> subjColl = new ArrayList<>();
subjColl.add(NodeFactory.createURI("http://example.org#subject"));
HashMap<Node, ArrayList<Node>> valMap = new HashMap<>();
valMap.put(svarNode, subjColl);
// WhereBuilder creation
WhereBuilder wb = new WhereBuilder();
wb.addWhere(svarNode, pvarNode, ovarNode);
wb.addWhereValueVars(valMap);
wb.toString();
// WHERE { ?s ?p ?o }
{code}
It is only when you add the WhereBuilder to another builder, e.g. a ConstructBuilder, when you are able to visualize the VALUES clause:
{code:java}
import org.apache.jena.arq.querybuilder.ConstructBuilder;
ConstructBuilder cb = new ConstructBuilder();
cb.addConstruct(new Triple(svarNode, pvarNode, ovarNode));
cb.addWhere(wb);
cb.toString();
// CONSTRUCT
// {
// ?s ?p ?o .
// }
// WHERE
// { ?s ?p ?o
// VALUES ( ?s ) { ( <http://example.org#subject> ) }
// }
{code}
Ideally we would like to visualize the VALUES clause by including it in the result string while stringifying the WhereBuilder, not just with the ConstructBuilder.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)