示例#1
0
        /// <summary>
        /// Evaluates the Algebra in the given context
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            // First evaluate the inner algebra
            BaseMultiset results = context.Evaluate(_inner);

            context.OutputMultiset = new Multiset();

            if (results is NullMultiset)
            {
                context.OutputMultiset = results;
            }
            else if (results is IdentityMultiset)
            {
                context.OutputMultiset.AddVariable(_var);
                Set s = new Set();
                try
                {
                    INode temp = _expr.Evaluate(context, 0);
                    s.Add(_var, temp);
                }
                catch
                {
                    // No assignment if there's an error
                    s.Add(_var, null);
                }
                context.OutputMultiset.Add(s.Copy());
            }
            else
            {
                if (results.ContainsVariable(_var))
                {
                    throw new RdfQueryException("Cannot assign to the variable ?" + _var + "since it has previously been used in the Query");
                }

                context.InputMultiset = results;
                context.OutputMultiset.AddVariable(_var);
#if NET40
                if (Options.UsePLinqEvaluation && this._expr.CanParallelise)
                {
                    results.SetIDs.AsParallel().ForAll(id => EvalExtend(context, results, id));
                }
                else
                {
                    foreach (int id in results.SetIDs)
                    {
                        EvalExtend(context, results, id);
                    }
                }
#else
                foreach (var id in results.SetIDs)
                {
                    EvalExtend(context, results, id);
                }
#endif
            }

            return(context.OutputMultiset);
        }
示例#2
0
        /// <summary>
        /// Determines whether this Multiset is disjoint with another Multiset.
        /// </summary>
        /// <param name="other">Other Multiset.</param>
        /// <returns></returns>
        public override bool IsDisjointWith(BaseMultiset other)
        {
            if (other is IdentityMultiset || other is NullMultiset)
            {
                return(false);
            }

            return(this.Variables.All(v => !other.ContainsVariable(v)));
        }
示例#3
0
        /// <summary>
        /// Evaluates the Algebra in the given context
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            //First evaluate the inner algebra
            BaseMultiset results = context.Evaluate(this._inner);

            context.OutputMultiset = new Multiset();

            if (results is NullMultiset)
            {
                context.OutputMultiset = results;
            }
            else if (results is IdentityMultiset)
            {
                context.OutputMultiset.AddVariable(this._var);
                Set s = new Set();
                try
                {
                    INode temp = this._expr.Evaluate(context, 0);
                    s.Add(this._var, temp);
                }
                catch
                {
                    //No assignment if there's an error
                    s.Add(this._var, null);
                }
                context.OutputMultiset.Add(s.Copy());
            }
            else
            {
                if (results.ContainsVariable(this._var))
                {
                    throw new RdfQueryException("Cannot use a BIND assigment to BIND to a variable that has previously been used in the Query");
                }

                context.OutputMultiset.AddVariable(this._var);
                foreach (int id in results.SetIDs.ToList())
                {
                    ISet s = results[id].Copy();
                    try
                    {
                        //Make a new assignment
                        INode temp = this._expr.Evaluate(context, id);
                        s.Add(this._var, temp);
                    }
                    catch
                    {
                        //No assignment if there's an error but the solution is preserved
                    }
                    context.OutputMultiset.Add(s);
                }
            }

            return(context.OutputMultiset);
        }
示例#4
0
文件: Multiset.cs 项目: jmahmud/RDFer
        /// <summary>
        /// Determines whether this Multiset is disjoint with another Multiset
        /// </summary>
        /// <param name="other">Other Multiset</param>
        /// <returns></returns>
        public override bool IsDisjointWith(BaseMultiset other)
        {
            if (other is IdentityMultiset || other is NullMultiset) return false;

            return this._variables.All(v => !other.ContainsVariable(v));
        }