org.eclipse.rdf4j.query.algebra.Difference Java Examples

The following examples show how to use org.eclipse.rdf4j.query.algebra.Difference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LimitedSizeEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final Difference difference,
		final BindingSet bindings) throws QueryEvaluationException {
	Iteration<BindingSet, QueryEvaluationException> leftArg, rightArg;

	leftArg = new DelayedIteration<BindingSet, QueryEvaluationException>() {

		@Override
		protected Iteration<BindingSet, QueryEvaluationException> createIteration()
				throws QueryEvaluationException {
			return evaluate(difference.getLeftArg(), bindings);
		}
	};

	rightArg = new DelayedIteration<BindingSet, QueryEvaluationException>() {

		@Override
		protected Iteration<BindingSet, QueryEvaluationException> createIteration()
				throws QueryEvaluationException {
			return evaluate(difference.getRightArg(), bindings);
		}
	};

	return new LimitedSizeSPARQLMinusIteration(leftArg, rightArg, used, maxSize);
}
 
Example #2
Source File: StrictEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BinaryTupleOperator expr,
		BindingSet bindings) throws QueryEvaluationException {
	if (expr instanceof Join) {
		return evaluate((Join) expr, bindings);
	} else if (expr instanceof LeftJoin) {
		return evaluate((LeftJoin) expr, bindings);
	} else if (expr instanceof Union) {
		return evaluate((Union) expr, bindings);
	} else if (expr instanceof Intersection) {
		return evaluate((Intersection) expr, bindings);
	} else if (expr instanceof Difference) {
		return evaluate((Difference) expr, bindings);
	} else if (expr == null) {
		throw new IllegalArgumentException("expr must not be null");
	} else {
		throw new QueryEvaluationException("Unsupported binary tuple operator type: " + expr.getClass());
	}
}
 
Example #3
Source File: StrictEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final Difference difference,
		final BindingSet bindings) throws QueryEvaluationException {
	Iteration<BindingSet, QueryEvaluationException> leftArg, rightArg;

	leftArg = new DelayedIteration<BindingSet, QueryEvaluationException>() {

		@Override
		protected Iteration<BindingSet, QueryEvaluationException> createIteration()
				throws QueryEvaluationException {
			return evaluate(difference.getLeftArg(), bindings);
		}
	};

	rightArg = new DelayedIteration<BindingSet, QueryEvaluationException>() {

		@Override
		protected Iteration<BindingSet, QueryEvaluationException> createIteration()
				throws QueryEvaluationException {
			return evaluate(difference.getRightArg(), bindings);
		}
	};

	return new SPARQLMinusIteration<>(leftArg, rightArg);
}
 
Example #4
Source File: HalyardTupleExprEvaluation.java    From Halyard with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluate {@link BinaryTupleOperator} query model nodes
 * @param parent
 * @param expr
 * @param bindings
 */
private void evaluateBinaryTupleOperator(BindingSetPipe parent, BinaryTupleOperator expr, BindingSet bindings) {
    if (expr instanceof Join) {
        evaluateJoin(parent, (Join) expr, bindings);
    } else if (expr instanceof LeftJoin) {
        evaluateLeftJoin(parent, (LeftJoin) expr, bindings);
    } else if (expr instanceof Union) {
        evaluateUnion(parent, (Union) expr, bindings);
    } else if (expr instanceof Intersection) {
        evaluateIntersection(parent, (Intersection) expr, bindings);
    } else if (expr instanceof Difference) {
        evaluateDifference(parent, (Difference) expr, bindings);
    } else if (expr == null) {
        parent.handleException(new IllegalArgumentException("expr must not be null"));
    } else {
        parent.handleException(new QueryEvaluationException("Unsupported binary tuple operator type: " + expr.getClass()));
    }
}
 
Example #5
Source File: TupleExprBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Object visit(ASTMinusGraphPattern node, Object data) throws VisitorException {
	GraphPattern parentGP = graphPattern;

	TupleExpr leftArg = graphPattern.buildTupleExpr();

	graphPattern = new GraphPattern(parentGP);
	node.jjtGetChild(0).jjtAccept(this, null);
	TupleExpr rightArg = graphPattern.buildTupleExpr();

	parentGP = new GraphPattern();
	parentGP.addRequiredTE(new Difference(leftArg, rightArg));
	graphPattern = parentGP;

	return null;
}
 
Example #6
Source File: SparqlTupleExprRenderer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public void meet(Difference theOp) throws Exception {
	String aLeft = renderTupleExpr(theOp.getLeftArg());
	String aRight = renderTupleExpr(theOp.getRightArg());

	mJoinBuffer.append("\n{")
			.append(aLeft)
			.append("}")
			.append("\nminus\n")
			.append("{")
			.append(aRight)
			.append("}.\n");
}
 
Example #7
Source File: MinusBlock.java    From semagrow with Apache License 2.0 5 votes vote down vote up
public Collection<Plan> getMinusPlan(CompilerContext context, Collection<Plan> p1, Collection<Plan> p2) {
    //FIXME: Check the Site property
    return p1.stream().flatMap( pp1 ->
            p2.stream().flatMap(pp2 ->
                    Stream.of(context.asPlan(new Difference(pp1, pp2)))
            )
    ).collect(Collectors.toList());
}
 
Example #8
Source File: ContextCollector.java    From semagrow with Apache License 2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public void meet(Difference theOp)
        throws Exception
{
    binaryOpMeet(theOp, theOp.getLeftArg(), theOp.getRightArg());
}
 
Example #9
Source File: SPARQLTupleExprRenderer.java    From semagrow with Apache License 2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public void meet(Difference theOp)
        throws Exception
{
    String aLeft = renderTupleExpr(theOp.getLeftArg());
    String aRight = renderTupleExpr(theOp.getRightArg());

    mJoinBuffer.append("\n{").append(aLeft).append("}").append("\nminus\n").append("{").append(aRight).append(
            "}.\n");
}
 
Example #10
Source File: PCJOptimizerUtilities.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
public void meet(final Difference node) {
	if (Sets.intersection(node.getRightArg().getBindingNames(), filterVars).size() > 0) {
		relocate(filter, node.getRightArg());
	} else if (Sets.intersection(node.getLeftArg().getBindingNames(), filterVars).size() > 0) {
		final Filter clone = new Filter(filter.getArg(), filter
				.getCondition().clone());
		relocate(clone, node.getLeftArg());
	}
}
 
Example #11
Source File: QueryModelBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public TupleExpr visit(ASTGraphMinus node, Object data) throws VisitorException {
	TupleExpr leftArg = (TupleExpr) node.getLeftArg().jjtAccept(this, null);
	TupleExpr rightArg = (TupleExpr) node.getRightArg().jjtAccept(this, null);

	return new Difference(leftArg, rightArg);
}
 
Example #12
Source File: QueryModelBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public TupleExpr visit(ASTTupleMinus node, Object data) throws VisitorException {
	TupleExpr leftArg = (TupleExpr) node.getLeftArg().jjtAccept(this, null);
	TupleExpr rightArg = (TupleExpr) node.getRightArg().jjtAccept(this, null);

	return new Difference(leftArg, rightArg);
}
 
Example #13
Source File: SerqlTupleExprRenderer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public void meet(Difference theOp) throws Exception {
	String aLeft = renderTupleExpr(theOp.getLeftArg());
	String aRight = renderTupleExpr(theOp.getRightArg());

	mBuffer.append(aLeft).append("\nminus\n").append(aRight);
}
 
Example #14
Source File: SpinRenderer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void meet(Difference node) throws RDFHandlerException {
	node.getLeftArg().visit(this);
	listEntry();
	handler.handleStatement(valueFactory.createStatement(subject, RDF.TYPE, SP.MINUS_CLASS));
	Resource elementsList = valueFactory.createBNode();
	handler.handleStatement(valueFactory.createStatement(subject, SP.ELEMENTS_PROPERTY, elementsList));
	ListContext elementsCtx = newList(elementsList);
	node.getRightArg().visit(this);
	endList(elementsCtx);
}
 
Example #15
Source File: QueryModelNormalizer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void meet(Difference difference) {
	super.meet(difference);

	TupleExpr leftArg = difference.getLeftArg();
	TupleExpr rightArg = difference.getRightArg();

	if (leftArg instanceof EmptySet) {
		difference.replaceWith(leftArg);
	} else if (rightArg instanceof EmptySet) {
		difference.replaceWith(leftArg);
	} else if (leftArg instanceof SingletonSet && rightArg instanceof SingletonSet) {
		difference.replaceWith(new EmptySet());
	}
}
 
Example #16
Source File: FilterOptimizer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void meet(Difference node) {
	Filter clone = new Filter();
	clone.setCondition(filter.getCondition().clone());

	relocate(filter, node.getLeftArg());
	relocate(clone, node.getRightArg());

	FilterRelocator.relocate(filter);
	FilterRelocator.relocate(clone);
}
 
Example #17
Source File: QueryModelPruner.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void meet(Difference difference) {
	super.meet(difference);

	TupleExpr leftArg = difference.getLeftArg();
	TupleExpr rightArg = difference.getRightArg();

	if (leftArg instanceof EmptySet) {
		difference.replaceWith(leftArg);
	} else if (rightArg instanceof EmptySet) {
		difference.replaceWith(leftArg);
	} else if (leftArg instanceof SingletonSet && rightArg instanceof SingletonSet) {
		difference.replaceWith(new EmptySet());
	}
}
 
Example #18
Source File: QueryModelPruner.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void meet(Difference difference) {
	super.meet(difference);
	TupleExpr leftArg = difference.getLeftArg();
	TupleExpr rightArg = difference.getRightArg();
	if (leftArg instanceof EmptySet) {
		difference.replaceWith(leftArg);
	} else if (rightArg instanceof EmptySet) {
		difference.replaceWith(leftArg);
	} else if (leftArg instanceof SingletonSet && rightArg instanceof SingletonSet) {
		difference.replaceWith(new EmptySet());
	}
}
 
Example #19
Source File: ContextCollector.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public void meet(Difference theOp) throws Exception {
	binaryOpMeet(theOp, theOp.getLeftArg(), theOp.getRightArg());
}
 
Example #20
Source File: AbstractQueryModelVisitor.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void meet(Difference node) throws X {
	meetBinaryTupleOperator(node);
}