use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class TransformMergeBGPs method transform.
@Override
public Op transform(OpSequence opSequence, List<Op> elts) {
// First check whether we need to do anything at all.
// Check for two BGPs.
boolean xform = false;
boolean previousBGP = false;
for (Op op1 : elts) {
BasicPattern p1 = asBGP(op1);
if (previousBGP && p1 != null) {
xform = true;
break;
}
previousBGP = (p1 != null);
}
if (!xform)
// Nothing to do here.
return super.transform(opSequence, elts);
OpSequence seq2 = OpSequence.create();
for (int i = 0; i < elts.size(); i++) {
Op op = elts.get(i);
BasicPattern p1 = asBGP(op);
if (p1 == null) {
// Do nothing
seq2.add(op);
// Outer loop.
continue;
}
// This is the op after the merge, if any.
BasicPattern pMerge = new BasicPattern();
seq2.add(new OpBGP(pMerge));
// Re-gets the BGP that trigegrs this all.
for (; i < elts.size(); i++) {
// Look at next element.
Op opNext = elts.get(i);
BasicPattern p2 = asBGP(opNext);
if (p2 == null) {
seq2.add(opNext);
break;
}
// Merge.
pMerge.addAll(p2);
}
}
if (seq2.size() == 1)
return seq2.get(0);
return seq2;
}
use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class PropertyFunctionGenerator method makeStages.
private static Op makeStages(BasicPattern triples, Map<Triple, PropertyFunctionInstance> pfInvocations) {
// Step 3 : Make the operation expression.
// For each property function, insert the implementation
// For each block of non-property function triples, make a BGP.
Op op = null;
BasicPattern pattern = null;
for (Triple t : triples) {
if (pfInvocations.containsKey(t)) {
op = flush(pattern, op);
pattern = null;
PropertyFunctionInstance pfi = pfInvocations.get(t);
OpPropFunc opPF = new OpPropFunc(t.getPredicate(), pfi.getSubjectArgList(), pfi.getObjectArgList(), op);
op = opPF;
continue;
}
// Regular triples - make sure there is a basic pattern in progress.
if (pattern == null)
pattern = new BasicPattern();
pattern.add(t);
}
op = flush(pattern, op);
return op;
}
use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class OpQuad method asQuadPattern.
public OpQuadPattern asQuadPattern() {
if (opQuadPattern == null) {
BasicPattern bp = new BasicPattern();
bp.add(getQuad().asTriple());
opQuadPattern = new OpQuadPattern(quad.getGraph(), bp);
}
return opQuadPattern;
}
use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class OpQuadBlock method convertOp.
/** Convenience - convert to OpQuadPatterns which are more widely used (currently?) */
public Op convertOp() {
if (quads.size() == 0)
return OpTable.empty();
if (quads.size() == 1) {
Quad q = quads.get(0);
BasicPattern bgp = new BasicPattern();
bgp.add(q.asTriple());
return new OpQuadPattern(q.getGraph(), bgp);
}
List<OpQuadPattern> x = convert();
OpSequence ops = OpSequence.create();
for (OpQuadPattern oqp : x) ops.add(oqp);
return ops;
}
use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class PropertyFunctionGenerator method compilePattern.
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.
// Property functions seen
List<Triple> propertyFunctionTriples = new ArrayList<>();
// A copy of all triples (later, it is mutated)
BasicPattern triples = new BasicPattern(pattern);
// 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 => property function instance
Map<Triple, PropertyFunctionInstance> pfInvocations = new HashMap<>();
// 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;
}
Aggregations