org.eclipse.rdf4j.query.algebra.MathExpr Java Examples
The following examples show how to use
org.eclipse.rdf4j.query.algebra.MathExpr.
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: SpinRenderer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void meet(MathExpr node) throws RDFHandlerException { Resource currentSubj = subject; flushPendingStatement(); handler.handleStatement(valueFactory.createStatement(subject, RDF.TYPE, toValue(node.getOperator()))); predicate = SP.ARG1_PROPERTY; node.getLeftArg().visit(this); predicate = SP.ARG2_PROPERTY; node.getRightArg().visit(this); subject = currentSubj; predicate = null; }
Example #2
Source File: StrictEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Value evaluate(MathExpr node, BindingSet bindings) throws QueryEvaluationException { // Do the math Value leftVal = evaluate(node.getLeftArg(), bindings); Value rightVal = evaluate(node.getRightArg(), bindings); if (leftVal instanceof Literal && rightVal instanceof Literal) { return MathUtil.compute((Literal) leftVal, (Literal) rightVal, node.getOperator()); } throw new ValueExprEvaluationException("Both arguments must be numeric literals"); }
Example #3
Source File: ExtendedEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Value evaluate(MathExpr node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException { Value leftVal = evaluate(node.getLeftArg(), bindings); Value rightVal = evaluate(node.getRightArg(), bindings); if (leftVal instanceof Literal && rightVal instanceof Literal) { return XMLDatatypeMathUtil.compute((Literal) leftVal, (Literal) rightVal, node.getOperator()); } throw new ValueExprEvaluationException("Both arguments must be literals"); }
Example #4
Source File: SparqlValueExprRenderer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @inheritDoc */ @Override public void meet(MathExpr theOp) throws Exception { mBuffer.append("("); theOp.getLeftArg().visit(this); mBuffer.append(" ").append(theOp.getOperator().getSymbol()).append(" "); theOp.getRightArg().visit(this); mBuffer.append(")"); }
Example #5
Source File: SerqlValueExprRenderer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @inheritDoc */ @Override public void meet(MathExpr theOp) throws Exception { mBuffer.append("("); theOp.getLeftArg().visit(this); mBuffer.append(" ").append(theOp.getOperator().getSymbol()).append(" "); theOp.getRightArg().visit(this); mBuffer.append(")"); }
Example #6
Source File: HalyardValueExprEvaluation.java From Halyard with Apache License 2.0 | 5 votes |
/** * Evaluate a {@link MathExpr} * @param node the node to evaluate * @param bindings the set of named value bindings * @return the {@link Value} of the math operation on the {@link Value}s return from evaluating the left and right arguments of the node * @throws ValueExprEvaluationException * @throws QueryEvaluationException */ private Value evaluate(MathExpr node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException { // Do the math Value leftVal = evaluate(node.getLeftArg(), bindings); Value rightVal = evaluate(node.getRightArg(), bindings); if (leftVal instanceof Literal && rightVal instanceof Literal) { return MathUtil.compute((Literal) leftVal, (Literal) rightVal, node.getOperator()); } throw new ValueExprEvaluationException("Both arguments must be numeric literals"); }
Example #7
Source File: SPARQLValueExprRenderer.java From semagrow with Apache License 2.0 | 5 votes |
/** * @inheritDoc */ @Override public void meet(MathExpr theOp) throws Exception { mBuffer.append("("); theOp.getLeftArg().visit(this); mBuffer.append(" ").append(theOp.getOperator().getSymbol()).append(" "); theOp.getRightArg().visit(this); mBuffer.append(")"); }
Example #8
Source File: StrictEvaluationStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Value evaluate(ValueExpr expr, BindingSet bindings) throws QueryEvaluationException { if (expr instanceof Var) { return evaluate((Var) expr, bindings); } else if (expr instanceof ValueConstant) { return evaluate((ValueConstant) expr, bindings); } else if (expr instanceof BNodeGenerator) { return evaluate((BNodeGenerator) expr, bindings); } else if (expr instanceof Bound) { return evaluate((Bound) expr, bindings); } else if (expr instanceof Str) { return evaluate((Str) expr, bindings); } else if (expr instanceof Label) { return evaluate((Label) expr, bindings); } else if (expr instanceof Lang) { return evaluate((Lang) expr, bindings); } else if (expr instanceof LangMatches) { return evaluate((LangMatches) expr, bindings); } else if (expr instanceof Datatype) { return evaluate((Datatype) expr, bindings); } else if (expr instanceof Namespace) { return evaluate((Namespace) expr, bindings); } else if (expr instanceof LocalName) { return evaluate((LocalName) expr, bindings); } else if (expr instanceof IsResource) { return evaluate((IsResource) expr, bindings); } else if (expr instanceof IsURI) { return evaluate((IsURI) expr, bindings); } else if (expr instanceof IsBNode) { return evaluate((IsBNode) expr, bindings); } else if (expr instanceof IsLiteral) { return evaluate((IsLiteral) expr, bindings); } else if (expr instanceof IsNumeric) { return evaluate((IsNumeric) expr, bindings); } else if (expr instanceof IRIFunction) { return evaluate((IRIFunction) expr, bindings); } else if (expr instanceof Regex) { return evaluate((Regex) expr, bindings); } else if (expr instanceof Coalesce) { return evaluate((Coalesce) expr, bindings); } else if (expr instanceof Like) { return evaluate((Like) expr, bindings); } else if (expr instanceof FunctionCall) { return evaluate((FunctionCall) expr, bindings); } else if (expr instanceof And) { return evaluate((And) expr, bindings); } else if (expr instanceof Or) { return evaluate((Or) expr, bindings); } else if (expr instanceof Not) { return evaluate((Not) expr, bindings); } else if (expr instanceof SameTerm) { return evaluate((SameTerm) expr, bindings); } else if (expr instanceof Compare) { return evaluate((Compare) expr, bindings); } else if (expr instanceof MathExpr) { return evaluate((MathExpr) expr, bindings); } else if (expr instanceof In) { return evaluate((In) expr, bindings); } else if (expr instanceof CompareAny) { return evaluate((CompareAny) expr, bindings); } else if (expr instanceof CompareAll) { return evaluate((CompareAll) expr, bindings); } else if (expr instanceof Exists) { return evaluate((Exists) expr, bindings); } else if (expr instanceof If) { return evaluate((If) expr, bindings); } else if (expr instanceof ListMemberOperator) { return evaluate((ListMemberOperator) expr, bindings); } else if (expr instanceof ValueExprTripleRef) { return evaluate((ValueExprTripleRef) expr, bindings); } else if (expr == null) { throw new IllegalArgumentException("expr must not be null"); } else { throw new QueryEvaluationException("Unsupported value expr type: " + expr.getClass()); } }
Example #9
Source File: AbstractQueryModelVisitor.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void meet(MathExpr node) throws X { meetBinaryValueOperator(node); }
Example #10
Source File: TupleExprBuilder.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public MathExpr visit(ASTMath node, Object data) throws VisitorException { ValueExpr leftArg = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, null); ValueExpr rightArg = (ValueExpr) node.jjtGetChild(1).jjtAccept(this, null); return new MathExpr(leftArg, rightArg, node.getOperator()); }
Example #11
Source File: HalyardValueExprEvaluation.java From Halyard with Apache License 2.0 | 4 votes |
/** * Determines which evaluate method to call based on the type of {@link ValueExpr} * @param expr the expression to evaluate * @param bindings the set of named value bindings the set of named value bindings * @return the {@link Value} resulting from the evaluation * @throws ValueExprEvaluationException * @throws QueryEvaluationException */ Value evaluate(ValueExpr expr, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException { if (expr instanceof Var) { return evaluate((Var) expr, bindings); } else if (expr instanceof ValueConstant) { return evaluate((ValueConstant) expr, bindings); } else if (expr instanceof BNodeGenerator) { return evaluate((BNodeGenerator) expr, bindings); } else if (expr instanceof Bound) { return evaluate((Bound) expr, bindings); } else if (expr instanceof Str) { return evaluate((Str) expr, bindings); } else if (expr instanceof Label) { return evaluate((Label) expr, bindings); } else if (expr instanceof Lang) { return evaluate((Lang) expr, bindings); } else if (expr instanceof LangMatches) { return evaluate((LangMatches) expr, bindings); } else if (expr instanceof Datatype) { return evaluate((Datatype) expr, bindings); } else if (expr instanceof Namespace) { return evaluate((Namespace) expr, bindings); } else if (expr instanceof LocalName) { return evaluate((LocalName) expr, bindings); } else if (expr instanceof IsResource) { return evaluate((IsResource) expr, bindings); } else if (expr instanceof IsURI) { return evaluate((IsURI) expr, bindings); } else if (expr instanceof IsBNode) { return evaluate((IsBNode) expr, bindings); } else if (expr instanceof IsLiteral) { return evaluate((IsLiteral) expr, bindings); } else if (expr instanceof IsNumeric) { return evaluate((IsNumeric) expr, bindings); } else if (expr instanceof IRIFunction) { return evaluate((IRIFunction) expr, bindings); } else if (expr instanceof Regex) { return evaluate((Regex) expr, bindings); } else if (expr instanceof Coalesce) { return evaluate((Coalesce) expr, bindings); } else if (expr instanceof Like) { return evaluate((Like) expr, bindings); } else if (expr instanceof FunctionCall) { return evaluate((FunctionCall) expr, bindings); } else if (expr instanceof And) { return evaluate((And) expr, bindings); } else if (expr instanceof Or) { return evaluate((Or) expr, bindings); } else if (expr instanceof Not) { return evaluate((Not) expr, bindings); } else if (expr instanceof SameTerm) { return evaluate((SameTerm) expr, bindings); } else if (expr instanceof Compare) { return evaluate((Compare) expr, bindings); } else if (expr instanceof MathExpr) { return evaluate((MathExpr) expr, bindings); } else if (expr instanceof In) { return evaluate((In) expr, bindings); } else if (expr instanceof CompareAny) { return evaluate((CompareAny) expr, bindings); } else if (expr instanceof CompareAll) { return evaluate((CompareAll) expr, bindings); } else if (expr instanceof Exists) { return evaluate((Exists) expr, bindings); } else if (expr instanceof If) { return evaluate((If) expr, bindings); } else if (expr instanceof ListMemberOperator) { return evaluate((ListMemberOperator) expr, bindings); } else if (expr == null) { throw new IllegalArgumentException("expr must not be null"); } else { throw new QueryEvaluationException("Unsupported value expr type: " + expr.getClass()); } }