/** * The constructor * @param query The query that this handler will be modifying. */ public ConstructHandler(Query query) { this.query = query; constructs = new ArrayList<>(); if (query.getConstructTemplate() != null) { for (Triple t : query.getConstructTemplate().getTriples()) { constructs.add(t); } } }
/** * The constructor * @param query The query that this handler will be modifying. */ public ConstructHandler(Query query) { this.query = query; constructs = new ArrayList<>(); if (query.getConstructTemplate() != null) { for (Triple t : query.getConstructTemplate().getTriples()) { constructs.add(t); } } }
@Override public void visitConstructResultForm(Query query) { x ^= query.getConstructTemplate().hashCode() ; }
@Override public void visitConstructResultForm(Query query) { newQuery.setQueryConstructType(); newQuery.setConstructTemplate(query.getConstructTemplate()); }
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() ; }
@Override public void visitConstructResultForm(Query query) { newQuery.setQueryConstructType() ; newQuery.setConstructTemplate(query.getConstructTemplate()) ; }
public static Template parseTemplate(String string) { final Query query = new Query () ; Action action = new Action() { @Override public void exec(SPARQLParser11 parser) throws Exception { Template t = parser.ConstructTemplate() ; query.setConstructTemplate(t) ; } } ; perform(query, string, action) ; return query.getConstructTemplate() ; }
public static Template parseTemplate(String string) { final Query query = new Query () ; Action action = new Action() { @Override public void exec(ARQParser parser) throws Exception { Template t = parser.ConstructTemplate() ; query.setConstructTemplate(t) ; } } ; perform(query, string, action) ; return query.getConstructTemplate() ; }
@Override public void visitConstructResultForm(Query query1) { check("Not both CONSTRUCT queries", query2.isConstructType()) ; check("CONSTRUCT templates", query1.getConstructTemplate().equalIso(query2.getConstructTemplate(), new NodeIsomorphismMap()) ) ; }
private Iterator<Triple> executeConstructStreaming(Query query) { if (!query.isConstructType()) { throw new RuntimeException("CONSTRUCT query expected. Got: [" + query.toString() + "]"); } Query clone = query.cloneQuery(); clone.setQuerySelectType(); //Query selectQuery = QueryUtils.elementToQuery(query.getQueryPattern()); clone.setQueryResultStar(true); ResultSetCloseable rs = executeCoreSelect(clone); System.out.println("Executing query as: " + clone); // insertPrefixesInto(result) ; Template template = query.getConstructTemplate(); Iterator<Triple> result = new ConstructIterator(template, rs); return result; }
public static SparqlView create(String name, Query query) { if(!query.isConstructType()) { throw new RuntimeException("Query must be a construct query"); } Op tmp = Algebra.compile(query.getQueryPattern()); Op op = Algebra.toQuadForm(tmp); QuadPattern quadPattern = QuadPatternUtils.toQuadPattern(Quad.defaultGraphNodeGenerated, query.getConstructTemplate().getBGP()); // QuadPattern quadPattern = new QuadPattern(); // for(Triple triple : query.getConstructTemplate().getTriples()) { // quadPattern.add(new Quad(Quad.defaultGraphNodeGenerated, triple)); // } SparqlView result = create(name, quadPattern, op); //SparqlView result = new SparqlView(name, quadPattern, new ExprList(), new VarDefinition(), op); return result; }
@Override public void visitConstructResultForm(Query query) { out.print("CONSTRUCT ") ; // if ( query.isQueryResultStar() ) // { // out.print("*") ; // out.newline() ; // } // else { out.incIndent(BLOCK_INDENT) ; out.newline() ; Template t = query.getConstructTemplate() ; fmtTemplate.format(t) ; out.decIndent(BLOCK_INDENT) ; } }
public static MappedConcept<Graph> query(Query query, Var partitionVar) { Assert.isTrue(query.isConstructType()); Template template = query.getConstructTemplate(); BasicPattern bgp = template.getBGP(); BasicPattern newBgp = allocVarsForBlankNodes(bgp); //Element e = new Element Element newElement = new ElementTriplesBlock(newBgp); Template newTemplate = new Template(newBgp); Concept concept = new Concept(newElement, partitionVar); Agg<Graph> agg = AggGraph.create(newTemplate); MappedConcept<Graph> result = MappedConcept.create(concept, agg); return result; } }
@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); }
@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); }
private void processResults(TarqlQueryExecution ex) throws IOException { if (testQuery && ex.getFirstQuery().getConstructTemplate() != null) { IndentedWriter out = new IndentedWriter(System.out); new FmtTemplate(out, new SerializationContext(ex.getFirstQuery())).format(ex.getFirstQuery().getConstructTemplate()); out.flush(); } if (ex.getFirstQuery().isSelectType()) { System.out.println(ResultSetFormatter.asText(ex.execSelect())); } else if (ex.getFirstQuery().isAskType()) { System.out.println(ResultSetFormatter.asText(ex.execSelect())); } else if (ex.getFirstQuery().isConstructType()) { resultTripleIterator = resultTripleIterator.andThen(ex.execTriples()); } else { cmdError("Only query forms CONSTRUCT, SELECT and ASK are supported"); } }
public static MappedConcept<DatasetGraph> query2(Query query, Var partitionVar) { Assert.isTrue(query.isConstructType()); Template template = query.getConstructTemplate(); BasicPattern bgp = template.getBGP(); BasicPattern newBgp = allocVarsForBlankNodes(bgp); //org.aksw.jena_sparql_api.utils.VarUtils. // Allocate a fresh var for the graph Var g = Var.alloc("_g_"); //Element e = new Element Element tmp = new ElementTriplesBlock(newBgp); Element newElement = new ElementNamedGraph(g, tmp); OpQuadPattern tmpOp = new OpQuadPattern(g, newBgp); QuadPattern quadPattern = tmpOp.getPattern(); Concept concept = new Concept(newElement, partitionVar); Agg<DatasetGraph> agg = AggDatasetGraph.create(quadPattern); MappedConcept<DatasetGraph> result = MappedConcept.create(concept, agg); return result; }
Template template = query.getConstructTemplate(); QuadPattern qp = QuadPatternUtils.toQuadPattern(Quad.defaultGraphNodeGenerated, template.getBGP()); Agg<DatasetGraph> agg = AggDatasetGraph.create(qp);
final Template template = _query.getConstructTemplate();
final Template template = _query.getConstructTemplate();