/** * Add a triple to the construct statement. * @param t The triple to add. */ public void addConstruct(Triple t) { constructs.add(t); query.setConstructTemplate(new Template(BasicPattern.wrap(constructs))); }
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; } }
public void subst(Collection<Triple> acc, Map<Node, Node> bNodeMap, Binding b) { for ( Triple t : getTriples() ) { t = TemplateLib.subst(t, b, bNodeMap) ; acc.add(t) ; } }
public ViewTemplateDefinition(Template template, List<Expr> varBindings) { //this.name = name; this.constructTemplate = QuadPatternUtils.toQuadPattern(template.getBGP()); this.varBindings = varBindings; }
/** * Returns an iterator over the triples generated by instancing the * template with each of the result set rows. * * Duplicates are not removed; this can be achieved by * wrapping this iterator with a UniqueIterator. * * TODO We could do some optimization by factoring out constant triples from the * template. * * @return * @throws Exception */ @Override protected Iterator<Triple> prefetch() throws Exception { // Build each template substitution as triples. while(rs.hasNext()) { Set<Triple> set = new HashSet<Triple>(); Map<Node, Node> bNodeMap = new HashMap<Node, Node>(); Binding binding = rs.nextBinding(); template.subst(set, bNodeMap, binding); return set.iterator(); } return null; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((template == null) ? 0 : template.hashCode()); return result; }
public ViewTemplateDefinition(Template template, List<Expr> varBindings) { //this.name = name; this.constructTemplate = QuadPatternUtils.toQuadPattern(template.getBGP()); this.varBindings = varBindings; }
@Override public void accumulate(Binding binding) { Set<Triple> triples = new HashSet<Triple>(); Map<Node, Node> bNodeMap = new HashMap<Node, Node>(); template.subst(triples, bNodeMap, binding); //Node TRUE = NodeValue.TRUE.asNode(); Node node = reverse.isVariable() ? binding.get((Var)reverse) : reverse ; boolean doReverse = node.isLiteral() ? isTrue(node.getLiteralValue()) : false ; for(Triple triple : triples) { if(doReverse) { triple = TripleUtils.swap(triple); } graph.add(triple); } }
@Override public void visitConstructResultForm(Query query) { x ^= query.getConstructTemplate().hashCode() ; }
/** * Add all the construct handlers from the handler argument to this construct. * @param handler The construct handler to copy from. */ public void addAll(ConstructHandler handler) { constructs.addAll(handler.constructs); query.setConstructTemplate(new Template(BasicPattern.wrap(constructs))); }
/** * 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 Set<Var> getDeclaredVars() { BasicPattern bgp = template.getBGP(); Set<Var> result = SetUtils.asSet(PatternVars.vars(new ElementTriplesBlock(bgp))); if(reverse.isVariable()) { result = Sets.union(Collections.singleton((Var)reverse), result); } return result; }
template.subst(set, bNodeMap, binding);
/** * Add a triple to the construct statement. * @param t The triple to add. */ public void addConstruct(Triple t) { constructs.add(t); query.setConstructTemplate(new Template(BasicPattern.wrap(constructs))); }
/** * 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); } } }
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; }
template.subst(set, bNodeMap, binding);
/** * Add all the construct handlers from the handler argument to this construct. * @param handler The construct handler to copy from. */ public void addAll(ConstructHandler handler) { constructs.addAll(handler.constructs); query.setConstructTemplate(new Template(BasicPattern.wrap(constructs))); }
@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); }
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; }