예제 #1
0
        /// <summary>
        /// Counts the results.
        /// </summary>
        /// <param name="context">Evaluation Context.</param>
        /// <param name="bindingIDs">Binding IDs over which the Aggregate applies.</param>
        /// <returns></returns>
        public override IValuedNode Apply(SparqlEvaluationContext context, IEnumerable <int> bindingIDs)
        {
            int c;
            HashSet <IValuedNode> values = new HashSet <IValuedNode>();

            if (_varname != null)
            {
                // Ensure the COUNTed variable is in the Variables of the Results
                if (!context.Binder.Variables.Contains(_varname))
                {
                    throw new RdfQueryException("Cannot use the Variable " + _expr.ToString() + " in a COUNT Aggregate since the Variable does not occur in a Graph Pattern");
                }

                // Just Count the number of results where the variable is bound
                VariableTerm varExpr = (VariableTerm)_expr;

                foreach (int id in bindingIDs)
                {
                    IValuedNode temp = varExpr.Evaluate(context, id);
                    if (temp != null)
                    {
                        values.Add(temp);
                    }
                }
                c = values.Count;
            }
            else
            {
                // Count the distinct non-null results
                foreach (int id in bindingIDs)
                {
                    try
                    {
                        IValuedNode temp = _expr.Evaluate(context, id);
                        if (temp != null)
                        {
                            values.Add(temp);
                        }
                    }
                    catch
                    {
                        // Ignore errors
                    }
                }
                c = values.Count;
            }
            return(new LongNode(null, c));
        }
예제 #2
0
        /// <summary>
        /// Counts the results
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingIDs">Binding IDs over which the Aggregate applies</param>
        /// <returns></returns>
        public override IValuedNode Apply(SparqlEvaluationContext context, IEnumerable <int> bindingIDs)
        {
            int c = 0;

            if (this._varname != null)
            {
                //Ensure the COUNTed variable is in the Variables of the Results
                if (!context.Binder.Variables.Contains(this._varname))
                {
                    throw new RdfQueryException("Cannot use the Variable " + this._expr.ToString() + " in a COUNT Aggregate since the Variable does not occur in a Graph Pattern");
                }

                //Just Count the number of results where the variable is bound
                VariableTerm varExpr = (VariableTerm)this._expr;
                foreach (int id in bindingIDs)
                {
                    if (varExpr.Evaluate(context, id) != null)
                    {
                        c++;
                    }
                }
            }
            else
            {
                //Count the number of results where the result in not null/error
                foreach (int id in bindingIDs)
                {
                    try
                    {
                        if (this._expr.Evaluate(context, id) != null)
                        {
                            c++;
                        }
                    }
                    catch
                    {
                        //Ignore errors
                    }
                }
            }

            return(new LongNode(null, c));
        }
예제 #3
0
        /// <summary>
        /// Counts the results
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingIDs">Binding IDs over which the Aggregate applies</param>
        /// <returns></returns>
        public override IValuedNode Apply(SparqlEvaluationContext context, IEnumerable <int> bindingIDs)
        {
            int c = 0;

            if (this._varname != null)
            {
                //Just Count the number of results where the variable is bound
                VariableTerm varExpr = (VariableTerm)this._expr;
                foreach (int id in bindingIDs)
                {
                    if (varExpr.Evaluate(context, id) != null)
                    {
                        c++;
                    }
                }
            }
            else
            {
                //Count the number of results where the result in not null/error
                foreach (int id in bindingIDs)
                {
                    try
                    {
                        if (this._expr.Evaluate(context, id) != null)
                        {
                            c++;
                        }
                    }
                    catch
                    {
                        //Ignore errors
                    }
                }
            }

            return(new LongNode(null, c));
        }