Java Code Examples for org.eclipse.rdf4j.query.algebra.evaluation.util.QueryEvaluationUtil#compare()
The following examples show how to use
org.eclipse.rdf4j.query.algebra.evaluation.util.QueryEvaluationUtil#compare() .
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: StrictEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public Value evaluate(CompareAny node, BindingSet bindings) throws QueryEvaluationException { Value leftValue = evaluate(node.getArg(), bindings); // Result is false until a match has been found boolean result = false; // Use first binding name from tuple expr to compare values String bindingName = node.getSubQuery().getBindingNames().iterator().next(); try (CloseableIteration<BindingSet, QueryEvaluationException> iter = evaluate(node.getSubQuery(), bindings)) { while (!result && iter.hasNext()) { BindingSet bindingSet = iter.next(); Value rightValue = bindingSet.getValue(bindingName); try { result = QueryEvaluationUtil.compare(leftValue, rightValue, node.getOperator()); } catch (ValueExprEvaluationException e) { // ignore, maybe next value will match } } } return BooleanLiteral.valueOf(result); }
Example 2
Source File: HalyardValueExprEvaluation.java From Halyard with Apache License 2.0 | 6 votes |
/** * Evaluate a {@link CompareAny} node * @param node the node to evaluate * @param bindings the set of named value bindings * @return * @throws ValueExprEvaluationException * @throws QueryEvaluationException */ private Value evaluate(CompareAny node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException { Value leftValue = evaluate(node.getArg(), bindings); // Result is false until a match has been found boolean result = false; // Use first binding name from tuple expr to compare values String bindingName = node.getSubQuery().getBindingNames().iterator().next(); try (CloseableIteration<BindingSet, QueryEvaluationException> iter = parentStrategy.evaluate(node.getSubQuery(), bindings)) { while (result == false && iter.hasNext()) { BindingSet bindingSet = iter.next(); Value rightValue = bindingSet.getValue(bindingName); try { result = QueryEvaluationUtil.compare(leftValue, rightValue, node.getOperator()); } catch (ValueExprEvaluationException e) { // ignore, maybe next value will match } } } return BooleanLiteral.valueOf(result); }
Example 3
Source File: HalyardValueExprEvaluation.java From Halyard with Apache License 2.0 | 6 votes |
/** * Evaluate a {@link CompareAll} node * @param node the node to evaluate * @param bindings the set of named value bindings * @return * @throws ValueExprEvaluationException * @throws QueryEvaluationException */ private Value evaluate(CompareAll node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException { Value leftValue = evaluate(node.getArg(), bindings); // Result is true until a mismatch has been found boolean result = true; // Use first binding name from tuple expr to compare values String bindingName = node.getSubQuery().getBindingNames().iterator().next(); try (CloseableIteration<BindingSet, QueryEvaluationException> iter = parentStrategy.evaluate(node.getSubQuery(), bindings)) { while (result == true && iter.hasNext()) { BindingSet bindingSet = iter.next(); Value rightValue = bindingSet.getValue(bindingName); try { result = QueryEvaluationUtil.compare(leftValue, rightValue, node.getOperator()); } catch (ValueExprEvaluationException e) { // Exception thrown by ValueCompare.isTrue(...) result = false; } } } return BooleanLiteral.valueOf(result); }
Example 4
Source File: StrictEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Value evaluate(ListMemberOperator node, BindingSet bindings) throws QueryEvaluationException { List<ValueExpr> args = node.getArguments(); Value leftValue = evaluate(args.get(0), bindings); boolean result = false; ValueExprEvaluationException typeError = null; for (int i = 1; i < args.size(); i++) { ValueExpr arg = args.get(i); try { Value rightValue = evaluate(arg, bindings); result = leftValue == null && rightValue == null; if (!result) { result = QueryEvaluationUtil.compare(leftValue, rightValue, CompareOp.EQ); } if (result) { break; } } catch (ValueExprEvaluationException caught) { typeError = caught; } } if (typeError != null && !result) { // cf. SPARQL spec a type error is thrown if the value is not in the // list and one of the list members caused a type error in the // comparison. throw typeError; } return BooleanLiteral.valueOf(result); }
Example 5
Source File: StrictEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Value evaluate(CompareAll node, BindingSet bindings) throws QueryEvaluationException { Value leftValue = evaluate(node.getArg(), bindings); // Result is true until a mismatch has been found boolean result = true; // Use first binding name from tuple expr to compare values String bindingName = node.getSubQuery().getBindingNames().iterator().next(); try (CloseableIteration<BindingSet, QueryEvaluationException> iter = evaluate(node.getSubQuery(), bindings)) { while (result && iter.hasNext()) { BindingSet bindingSet = iter.next(); Value rightValue = bindingSet.getValue(bindingName); try { result = QueryEvaluationUtil.compare(leftValue, rightValue, node.getOperator()); } catch (ValueExprEvaluationException e) { // Exception thrown by ValueCompare.isTrue(...) result = false; } } } return BooleanLiteral.valueOf(result); }
Example 6
Source File: HalyardValueExprEvaluation.java From Halyard with Apache License 2.0 | 5 votes |
/** * Evaluate a {@link ListMemberOperator} * @param node the node to evaluate * @param bindings the set of named value bindings * @return * @throws ValueExprEvaluationException * @throws QueryEvaluationException */ private Value evaluate(ListMemberOperator node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException { List<ValueExpr> args = node.getArguments(); Value leftValue = evaluate(args.get(0), bindings); boolean result = false; ValueExprEvaluationException typeError = null; for (int i = 1; i < args.size(); i++) { ValueExpr arg = args.get(i); try { Value rightValue = evaluate(arg, bindings); result = leftValue == null && rightValue == null; if (!result) { result = QueryEvaluationUtil.compare(leftValue, rightValue, Compare.CompareOp.EQ); } if (result) { break; } } catch (ValueExprEvaluationException caught) { typeError = caught; } } if (typeError != null && !result) { // cf. SPARQL spec a type error is thrown if the value is not in the // list and one of the list members caused a type error in the // comparison. throw typeError; } return BooleanLiteral.valueOf(result); }