use of org.apache.jena.sparql.syntax.Template in project jena by apache.
the class ParserSPARQL10 method parseTemplate.
public static Template parseTemplate(String string) {
final Query query = new Query();
Action action = new Action() {
@Override
public void exec(SPARQLParser10 parser) throws Exception {
Template t = parser.ConstructTemplate();
query.setConstructTemplate(t);
}
};
perform(query, string, action);
return query.getConstructTemplate();
}
use of org.apache.jena.sparql.syntax.Template in project jena by apache.
the class ConstructHandler method setVars.
@Override
public void setVars(Map<Var, Node> values) {
if (values.isEmpty()) {
return;
}
AbstractRewriter<Node> rw = new AbstractRewriter<Node>(values) {
};
query.setConstructTemplate(new Template(BasicPattern.wrap(rw.rewrite(constructs))));
}
use of org.apache.jena.sparql.syntax.Template in project jena by apache.
the class ConstructHandlerTest method testSetVars.
@Test
public void testSetVars() {
Var v = Var.alloc("v");
Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v);
handler.addConstruct(t);
Template template = query.getConstructTemplate();
assertNotNull(template);
List<Triple> lst = template.getTriples();
assertEquals(1, lst.size());
assertEquals(t, lst.get(0));
Map<Var, Node> values = new HashMap<>();
values.put(v, NodeFactory.createURI("three"));
handler.setVars(values);
template = query.getConstructTemplate();
assertNotNull(template);
lst = template.getTriples();
assertEquals(1, lst.size());
t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
assertEquals(t, lst.get(0));
}
use of org.apache.jena.sparql.syntax.Template in project jena by apache.
the class QueryExecutionBase method execConstructTriples.
@Override
public Iterator<Triple> execConstructTriples() {
checkNotClosed();
if (!query.isConstructType())
throw new QueryExecException("Attempt to get a CONSTRUCT model from a " + labelForQuery(query) + " query");
// This causes there to be no PROJECT around the pattern.
// That in turn, exposes the initial bindings.
query.setQueryResultStar(true);
startQueryIterator();
Template template = query.getConstructTemplate();
return TemplateLib.calcTriples(template.getTriples(), queryIterator);
}
use of org.apache.jena.sparql.syntax.Template in project jena by apache.
the class QueryExecutionBase method execConstructQuads.
@Override
public Iterator<Quad> execConstructQuads() {
checkNotClosed();
if (!query.isConstructType())
throw new QueryExecException("Attempt to get a CONSTRUCT model from a " + labelForQuery(query) + " query");
// This causes there to be no PROJECT around the pattern.
// That in turn, exposes the initial bindings.
query.setQueryResultStar(true);
startQueryIterator();
Template template = query.getConstructTemplate();
return TemplateLib.calcQuads(template.getQuads(), queryIterator);
}
Aggregations