/// <summary>
        /// Calculates the Numeric Value of this Expression as evaluated for a given Binding.
        /// </summary>
        /// <param name="context">Evaluation Context.</param>
        /// <param name="bindingID">Binding ID.</param>
        /// <returns></returns>
        public override IValuedNode Evaluate(SparqlEvaluationContext context, int bindingID)
        {
            IValuedNode a = _leftExpr.Evaluate(context, bindingID);
            IValuedNode b = _rightExpr.Evaluate(context, bindingID);

            IValuedNode[]   inputs = new IValuedNode[] { a, b };
            ISparqlOperator op     = null;

            if (SparqlOperators.TryGetOperator(SparqlOperatorType.Multiply, out op, inputs))
            {
                return(op.Apply(inputs));
            }
            else
            {
                throw new RdfQueryException("Cannot apply multiplication to the given inputs");
            }

            // if (a == null || b == null) throw new RdfQueryException("Cannot apply multiplication when one/both arguments are null");

            // SparqlNumericType type = (SparqlNumericType)Math.Max((int)a.NumericType, (int)b.NumericType);

            // switch (type)
            // {
            //    case SparqlNumericType.Integer:
            //        return new LongNode(null, a.AsInteger() * b.AsInteger());
            //    case SparqlNumericType.Decimal:
            //        return new DecimalNode(null, a.AsDecimal() * b.AsDecimal());
            //    case SparqlNumericType.Float:
            //        return new FloatNode(null, a.AsFloat() * b.AsFloat());
            //    case SparqlNumericType.Double:
            //        return new DoubleNode(null, a.AsDouble() * b.AsDouble());
            //    default:
            //        throw new RdfQueryException("Cannot evalute an Arithmetic Expression when the Numeric Type of the expression cannot be determined");
            // }
        }
Exemplo n.º 2
0
        private void TestApplication(SparqlOperatorType opType, IEnumerable <IValuedNode> ns, IValuedNode expected, bool shouldFail)
        {
            ISparqlOperator op = null;

            if (SparqlOperators.TryGetOperator(opType, out op, ns.ToArray()))
            {
                IValuedNode actual;
                try
                {
                    actual = op.Apply(ns.ToArray());
                }
                catch (Exception ex)
                {
                    if (shouldFail)
                    {
                        return;
                    }
                    throw;
                }

                Assert.AreEqual(expected, actual);
            }
            else
            {
                if (!shouldFail)
                {
                    Assert.Fail("Expected to be able to select an operator to apply to the inputs");
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the Numeric Value of this Expression as evaluated for a given Binding
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingID">Binding ID</param>
        /// <returns></returns>
        public override IValuedNode Evaluate(SparqlEvaluationContext context, int bindingID)
        {
            IValuedNode a = this._leftExpr.Evaluate(context, bindingID);
            IValuedNode b = this._rightExpr.Evaluate(context, bindingID);

            IValuedNode[]   inputs = new IValuedNode[] { a, b };
            ISparqlOperator op     = null;

            if (SparqlOperators.TryGetOperator(SparqlOperatorType.Divide, out op, inputs))
            {
                return(op.Apply(inputs));
            }
            else
            {
                throw new RdfQueryException("Cannot apply division to the given inputs");
            }
        }