Refine search
/** * Visiting triple patterns in SPARQL algebra. */ @Override public void visit(final OpBGP opBGP) { if(optionalFlag) { opBGP.getPattern().getList().forEach(triple -> optionalTraversals.add(TraversalBuilder.transform(triple))); opBGP.getPattern().getList().forEach(triple -> optionalVariable.add(triple.getObject().toString())); } else opBGP.getPattern().getList().forEach(triple -> traversalList.add(TraversalBuilder.transform(triple))); }
public final OpBGP asBGP() { if ( opBGP == null ) { BasicPattern bp = new BasicPattern() ; bp.add(getTriple()) ; opBGP = new OpBGP(bp) ; } return opBGP ; }
private static boolean oneLine(Op op) { if ( OpBGP.isBGP(op) ) { BasicPattern bgp = ((OpBGP)op).getPattern() ; if ( bgp.getList().size() <= 1 ) return true ; } return false ; }
@Override public Op transform(OpBGP opBGP) { BasicPattern bgp = opBGP.getPattern(); bgp = substitute(bgp, binding); return new OpBGP(bgp); }
/** * Transforms BGPs with the reordering */ @Override public Op transform(OpBGP opBGP) { BasicPattern pattern = opBGP.getPattern(); if ( pattern.size() < 2 ) return opBGP ; BasicPattern pattern2 = reorder.reorder(pattern); return new OpBGP(pattern2); }
private static BasicPattern asBGP(Op op) { if ( op instanceof OpBGP ) return ((OpBGP)op).getPattern() ; return null ; }
private static Op transformFilterBGP(ExprList exprs, Set<Var> patternVarsScope, BasicPattern pattern) { // Any filters that depend on no variables. Op op = insertAnyFilter(exprs, patternVarsScope, null); for (Triple triple : pattern) { OpBGP opBGP = getBGP(op); if (opBGP == null) { // Last thing was not a BGP (so it likely to be a filter) // Need to pass the results from that into the next triple. // Which is a join and sequence is a special case of join // which always evaluates by passing results of the early // part into the next element of the sequence. opBGP = new OpBGP(); op = OpSequence.create(op, opBGP); } opBGP.getPattern().add(triple); // Update variables in scope. VarUtils.addVarsFromTriple(patternVarsScope, triple); // Attempt to place any filters op = insertAnyFilter(exprs, patternVarsScope, op); } // Leave any remaining filter expressions - don't wrap up any as // something else may take them. return op; }
final List<Node> variables = new ArrayList<>(); for (final Triple t : opBGP.getPattern().getList()) { newBGP.add(registerBGPTriple(t, variables)); new OpBGP(BasicPattern.wrap(newBGP)));
rewriter = new OpRewriter(securityEvaluator, "http://example.com/dummy"); rewriter.visit(new OpBGP(BasicPattern.wrap(Arrays.asList(triples)))); Op op = rewriter.getResult(); Assert.assertTrue("Should have been an OpFilter", op = filter.getSubOp(); Assert.assertTrue("Should have been a OpBGP", op instanceof OpBGP); BasicPattern basicPattern = ((OpBGP) op).getPattern(); Assert.assertEquals(3, basicPattern.size()); Triple t = basicPattern.get(0); Assert.assertEquals(NodeFactory.createVariable("foo"), t.getSubject()); Assert.assertEquals(RDF.type.asNode(), t.getPredicate());
@Override public Op make(ItemList list) { BasicPattern triples = buildBGP(list) ; return new OpBGP(triples) ; } } ;
public boolean equivalent(OpBGP opBGP) { BasicPattern bgp = opBGP.getPattern() ; if ( bgp.size() != 1 ) return false ; Triple t = bgp.get(0) ; return triple.equals(t) ; }
@Override public Op transform(OpBGP op) { BasicPattern before = op.getPattern(); BasicPattern after = deduplicate(before); Op result = after.equals(before) ? op : new OpBGP(after); return result; }
private static Op compilePattern(PropertyFunctionRegistry registry, BasicPattern pattern, Context context) { // Split into triples and property functions. // 1/ Find property functions. // Property functions may involve other triples (for list arguments) // (but leave the property function triple in-place as a marker) // 2/ Find arguments for property functions // (but leave the property function triple in-place as a marker) // 3/ For remaining triples, put into basic graph patterns, // and string together the procedure calls and BGPs. List<Triple> propertyFunctionTriples = new ArrayList<>() ; // Property functions seen BasicPattern triples = new BasicPattern(pattern) ; // A copy of all triples (later, it is mutated) // Find the triples invoking property functions, and those not. findPropertyFunctions(context, pattern, registry, propertyFunctionTriples) ; if ( propertyFunctionTriples.size() == 0 ) //No property functions. return new OpBGP(pattern) ; Map<Triple, PropertyFunctionInstance> pfInvocations = new HashMap<>() ; // Map triple => property function instance // Removes triples of list arguments. This mutates 'triples' findPropertyFunctionArgs(context, triples, propertyFunctionTriples, pfInvocations) ; // Now make the OpSequence structure. Op op = makeStages(triples, pfInvocations) ; return op ; }
BasicPattern pMerge = new BasicPattern() ; seq2.add(new OpBGP(pMerge)) ; pMerge.addAll(p2) ;
@Override public void visit(OpBGP opBGP) { if ( opBGP.getPattern().size() == 1 ) { start(opBGP, NoNL) ; write(opBGP.getPattern(), true) ; finish(opBGP) ; return ; } start(opBGP, NL) ; write(opBGP.getPattern(), false) ; finish(opBGP) ; }
Node rewriteName= qSlot.rewriteGraphName ; if ( OpBGP.isBGP(op) ) if ( ((OpBGP)op).getPattern().isEmpty() ) noPattern = true ;
@Test public void bNodeSPARQL_Query_2() { String qs = "SELECT * { ?s ?p <_:BCD>}"; Query query = QueryFactory.create(qs); Op op = Algebra.compile(query); BasicPattern bp = ((OpBGP)op).getPattern(); Triple t = bp.get(0); assertEquals("BCD", t.getObject().getBlankNodeLabel()); }
public static Op buildPropertyFunctions(PropertyFunctionRegistry registry, OpBGP opBGP, Context context) { if ( opBGP.getPattern().isEmpty() ) return opBGP ; return compilePattern(registry, opBGP.getPattern(), context) ; }