public static Collection<Quad> collectQuads(Op op, Collection<Quad> result) { if (op instanceof OpLeftJoin) { OpLeftJoin x = (OpLeftJoin) op; collectQuads(x.getLeft(), result); collectQuads(x.getRight(), result); } else if (op instanceof OpFilter) { OpFilter x = (OpFilter) op; collectQuads(x.getSubOp(), result); } else if (op instanceof OpJoin) { OpJoin x = (OpJoin) op; collectQuads(x.getLeft(), result); collectQuads(x.getRight(), result); } else if (op instanceof OpUnion) { System.out.println( "Warning: Collecting expressions from unions. Since the same vars may appear within different (parts of) unions, it may be ambiguous to which part the expression refers."); OpUnion x = (OpUnion) op; collectQuads(x.getLeft(), result); collectQuads(x.getRight(), result); } else if (op instanceof OpQuadPattern) { OpQuadPattern x = (OpQuadPattern) op; result.addAll(x.getPattern().getList()); } else if (op instanceof OpSequence) { OpSequence x = (OpSequence) op; for (Op element : x.getElements()) { collectQuads(element, result); } } else { throw new NotImplementedException("Encountered class: " + op); } return result; }
private static Op transformFilterQuadPattern( ExprList exprs, Set<Var> patternVarsScope, Node graphNode, BasicPattern pattern) { // Any filters that depend on no variables. Op op = insertAnyFilter(exprs, patternVarsScope, null); if (Var.isVar(graphNode)) { // Add in the graph node of the quad block. // It's picked up after the first triple is processed. VarUtils.addVar(patternVarsScope, Var.alloc(graphNode)); } for (Triple triple : pattern) { OpQuadPattern opQuad = getQuads(op); if (opQuad == null) { opQuad = new OpQuadPattern(graphNode, new BasicPattern()); op = OpSequence.create(op, opQuad); } opQuad.getBasicPattern().add(triple); // Update variables in scope. VarUtils.addVarsFromTriple(patternVarsScope, triple); // Attempt to place any filters op = insertAnyFilter(exprs, patternVarsScope, op); } return op; }
@Override public Op transform(OpQuadPattern quadPattern) { Node gNode = quadPattern.getGraphNode(); Node g = substitute(gNode, binding); BasicPattern triples = new BasicPattern(); for (Triple triple : quadPattern.getBasicPattern()) { Node s = substitute(triple.getSubject(), binding); Node p = substitute(triple.getPredicate(), binding); Node o = substitute(triple.getObject(), binding); Triple t = new Triple(s, p, o); triples.add(t); } // Pure quading. // for ( Iterator iter = quadPattern.getQuads().iterator() ; // iter.hasNext() ; ) // { // Quad quad = (Quad)iter.next() ; // if ( ! quad.getGraph().equals(gNode) ) // throw new // ARQInternalErrorException("Internal error: quads block is not uniform over the graph node") // ; // Node s = substitute(quad.getSubject(), binding) ; // Node p = substitute(quad.getPredicate(), binding) ; // Node o = substitute(quad.getObject(), binding) ; // Triple t = new Triple(s, p, o) ; // triples.add(t) ; // } return new OpQuadPattern(g, triples); }
public void visit(OpQuadPattern quadPattern) { System.out.println(quadPattern.toString()); }
private static Op transformFilterQuadPattern( ExprList exprs, Set<Var> patternVarsScope, OpQuadPattern pattern) { return transformFilterQuadPattern( exprs, patternVarsScope, pattern.getGraphNode(), pattern.getBasicPattern()); }