当前位置: 首页>>代码示例>>C#>>正文


C# SparqlEvaluationContext.Evaluate方法代码示例

本文整理汇总了C#中SparqlEvaluationContext.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# SparqlEvaluationContext.Evaluate方法的具体用法?C# SparqlEvaluationContext.Evaluate怎么用?C# SparqlEvaluationContext.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SparqlEvaluationContext的用法示例。


在下文中一共展示了SparqlEvaluationContext.Evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Evaluate

        /// <summary>
        /// Evaluates an ExistsJoin
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            BaseMultiset initialInput = context.InputMultiset;
            BaseMultiset lhsResult = context.Evaluate(this._lhs);//this._lhs.Evaluate(context);
            context.CheckTimeout();

            if (lhsResult is NullMultiset)
            {
                context.OutputMultiset = lhsResult;
            }
            else if (lhsResult.IsEmpty)
            {
                context.OutputMultiset = new NullMultiset();
            }
            else
            {
                //Only execute the RHS if the LHS had results
                context.InputMultiset = lhsResult;
                BaseMultiset rhsResult = context.Evaluate(this._rhs);//this._rhs.Evaluate(context);
                context.CheckTimeout();

                context.OutputMultiset = lhsResult.ExistsJoin(rhsResult, this._mustExist);
                context.CheckTimeout();
            }

            context.InputMultiset = context.OutputMultiset;
            return context.OutputMultiset;
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:33,代码来源:AlgebraJoinClasses.cs

示例2: Evaluate

        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.Value(context, 0);
                    s.Add(this._var, temp);
                }
                catch
                {
                    //No assignment if there's an error
                    s.Add(this._var, null);
                }
                context.OutputMultiset.Add(s);
            }
            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())
                {
                    Set s = new Set(results[id]);
                    try
                    {
                        //Make a new assignment
                        INode temp = this._expr.Value(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;
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:53,代码来源:Extend.cs

示例3: Evaluate

        /// <summary>
        /// Evaluates a Group By by generating a <see cref="GroupMultiset">GroupMultiset</see> from the Input Multiset
        /// </summary>
        /// <param name="context">SPARQL Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            context.InputMultiset = context.Evaluate(this._pattern);//this._pattern.Evaluate(context);

            if (context.Query.GroupBy != null)
            {
                context.OutputMultiset = new GroupMultiset(context.InputMultiset, context.Query.GroupBy.Apply(context));
            }
            else if (this._grouping != null)
            {
                context.OutputMultiset = new GroupMultiset(context.InputMultiset, this._grouping.Apply(context));
            }
            else
            {
                context.OutputMultiset = context.InputMultiset;
            }
            return context.OutputMultiset;
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:23,代码来源:GroupBy.cs

示例4: Evaluate

        /// <summary>
        /// Evaluates the BINDINGS modifier
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            //Evalute the Pattern
            BaseMultiset results = context.Evaluate(this._pattern);//this._pattern.Evaluate(context);

            //If the result is Null/Identity/Empty
            if (results is NullMultiset || results is IdentityMultiset || results.IsEmpty)
            {
                context.OutputMultiset = results;
                return results;
            }
            else
            {
                //Result is an Join from the results to the Input Bindings
                context.OutputMultiset = results.Join(this._bindings.ToMultiset());
                return context.OutputMultiset;
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:23,代码来源:Bindings.cs

示例5: Evaluate

        /// <summary>
        /// Evaluates the Having Clause
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            context.InputMultiset = context.Evaluate(this._pattern);//this._pattern.Evaluate(context);

            if (context.Query != null)
            {
                if (context.Query.Having != null)
                {
                    context.Query.Having.Evaluate(context);
                }
            }
            else if (this._having != null)
            {
                this._having.Evaluate(context);
            }

            context.OutputMultiset = context.InputMultiset;
            return context.OutputMultiset;
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:24,代码来源:Having.cs

示例6: Evaluate

        /// <summary>
        /// Evaluates the Order By clause
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            context.InputMultiset = context.Evaluate(this._pattern);//this._pattern.Evaluate(context);

            if (context.Query != null)
            {
                if (context.Query.OrderBy != null)
                {
                    context.Query.OrderBy.Context = context;
                    context.InputMultiset.Sort(context.Query.OrderBy);
                }
            }
            else if (this._ordering != null)
            {
                context.InputMultiset.Sort(this._ordering);
            }
            context.OutputMultiset = context.InputMultiset;
            return context.OutputMultiset;
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:24,代码来源:OrderBy.cs

示例7: Evaluate

        /// <summary>
        /// Evaluates the Distinct Modifier
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            context.InputMultiset = context.Evaluate(this._pattern);//this._pattern.Evaluate(context);

            if (context.InputMultiset is IdentityMultiset || context.InputMultiset is NullMultiset)
            {
                context.OutputMultiset = context.InputMultiset;
                return context.OutputMultiset;
            }
            else
            {
                context.OutputMultiset = new Multiset(context.InputMultiset.Variables);
                IEnumerable<Set> sets = context.InputMultiset.Sets.Distinct();
                foreach (Set s in context.InputMultiset.Sets.Distinct())
                {
                    context.OutputMultiset.Add(s);
                }
                return context.OutputMultiset;
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:25,代码来源:Distinct.cs

示例8: Evaluate

        /// <summary>
        /// Applies the Filter over the results of evaluating the inner pattern
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            //Apply the Pattern first
            context.InputMultiset = context.Evaluate(this._pattern);//this._pattern.Evaluate(context);

            if (context.InputMultiset is NullMultiset)
            {
                //If we get a NullMultiset then the FILTER has no effect since there are already no results
            }
            else if (context.InputMultiset is IdentityMultiset)
            {
                if (this._filter.Variables.Any())
                {
                    //If we get an IdentityMultiset then the FILTER only has an effect if there are no
                    //variables - otherwise it is not in scope and causes the Output to become Null
                    context.InputMultiset = new NullMultiset();
                }
                else
                {
                    try
                    {
                        if (!this._filter.Expression.EffectiveBooleanValue(context, 0))
                        {
                            context.OutputMultiset = new NullMultiset();
                            return context.OutputMultiset;
                        }
                    }
                    catch
                    {
                        context.OutputMultiset = new NullMultiset();
                        return context.OutputMultiset;
                    }
                }
            }
            else
            {
                this._filter.Evaluate(context);
            }
            context.OutputMultiset = context.InputMultiset;
            return context.OutputMultiset;
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:46,代码来源:Filter.cs

示例9: Evaluate

        /// <summary>
        /// Evaluates the Path in the given context
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public override BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            //Try and generate an Algebra expression
            //Make sure we don't generate clashing temporary variable IDs over the life of the
            //Evaluation
            PathTransformContext transformContext = new PathTransformContext(this.PathStart, this.PathEnd);
            if (context["PathTransformID"] != null)
            {
                transformContext.NextID = (int)context["PathTransformID"];
            }
            ISparqlAlgebra algebra = this.Path.ToAlgebra(transformContext);
            context["PathTransformID"] = transformContext.NextID;

            //Now we can evaluate the resulting algebra
            //Note: We may need to preserve Blank Node variables across evaluations
            //which we usually don't do BUT because of the way we translate only part of the path
            //into an algebra at a time and may need to do further nested translate calls we do
            //need to do this here
            BaseMultiset initialInput = context.InputMultiset;
            bool trimMode = context.TrimTemporaryVariables;
            try
            {
                context.TrimTemporaryVariables = false;
                BaseMultiset result = context.Evaluate(algebra);//algebra.Evaluate(context);
                //Also note that we don't trim temporary variables here even if we've set the setting back
                //to enabled since a Trim will be done at the end of whatever BGP we are being evaluated in

                //Once we have our results can join then into our input
                context.OutputMultiset = initialInput.Join(result);
            }
            finally
            {
                context.TrimTemporaryVariables = trimMode;
            }

            return context.OutputMultiset;
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:42,代码来源:PropertyPath.cs

示例10: Evaluate

        /// <summary>
        /// Evaluates the Minus join by evaluating the LHS and RHS and substracting the RHS results from the LHS
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            BaseMultiset initialInput = context.InputMultiset;
            BaseMultiset lhsResult = context.Evaluate(this._lhs);//this._lhs.Evaluate(context);
            context.CheckTimeout();

            if (lhsResult is NullMultiset)
            {
                context.OutputMultiset = lhsResult;
            }
            else if (lhsResult.IsEmpty)
            {
                context.OutputMultiset = new NullMultiset();
            }
            else if (this._lhs.Variables.IsDisjoint(this._rhs.Variables))
            {
                //If the RHS is disjoint then there is no need to evaluate the RHS
                context.OutputMultiset = lhsResult;
            }
            else
            {
                //If we get here then the RHS is not disjoint so it does affect the ouput

                //Only execute the RHS if the LHS had results
                //context.InputMultiset = lhsResult;
                context.InputMultiset = initialInput;
                BaseMultiset rhsResult = context.Evaluate(this._rhs);//this._rhs.Evaluate(context);
                context.CheckTimeout();

                context.OutputMultiset = lhsResult.MinusJoin(rhsResult);
                context.CheckTimeout();
            }

            context.InputMultiset = context.OutputMultiset;
            return context.OutputMultiset;
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:41,代码来源:Minus.cs

示例11: Evaluate

        /// <summary>
        /// Evaluates the Ask Union
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            BaseMultiset initialInput = context.InputMultiset;
            BaseMultiset lhsResult = context.Evaluate(this._lhs);//this._lhs.Evaluate(context);
            context.CheckTimeout();

            if (lhsResult.IsEmpty)
            {
                //Only evaluate the RHS if the LHS was empty
                context.InputMultiset = initialInput;
                BaseMultiset rhsResult = context.Evaluate(this._rhs);//this._rhs.Evaluate(context);
                context.CheckTimeout();

                context.OutputMultiset = lhsResult.Union(rhsResult);
                context.CheckTimeout();

                context.InputMultiset = context.OutputMultiset;
            }
            else
            {
                context.OutputMultiset = lhsResult;
            }
            return context.OutputMultiset;
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:29,代码来源:AskBgp.cs

示例12: Evaluate

        /// <summary>
        /// Evaluates the Graph Clause by setting up the dataset, applying the pattern and then generating additional bindings if necessary
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            BaseMultiset result;

            //Q: Can we optimise GRAPH when the input is the Null Multiset to just return the Null Multiset?

            if (this._pattern is Bgp && ((Bgp)this._pattern).IsEmpty)
            {
                //Optimise the case where we have GRAPH ?g {} by not setting the Graph and just returning
                //a Null Multiset
                result = new NullMultiset();
            }
            else
            {
                bool datasetOk = false;
                try
                {
                    List<String> activeGraphs = new List<string>();

                    //Get the URIs of Graphs that should be evaluated over
                    if (this._graphSpecifier.TokenType != Token.VARIABLE)
                    {
                        switch (this._graphSpecifier.TokenType)
                        {
                            case Token.URI:
                            case Token.QNAME:
                                Uri activeGraphUri = UriFactory.Create(Tools.ResolveUriOrQName(this._graphSpecifier, context.Query.NamespaceMap, context.Query.BaseUri));
                                if (context.Data.HasGraph(activeGraphUri))
                                {
                                    //If the Graph is explicitly specified and there are FROM NAMED present then the Graph
                                    //URI must be in the graphs specified by a FROM NAMED or the result is null
                                    if (context.Query == null || !context.Query.NamedGraphs.Any() || context.Query.NamedGraphs.Any(u => EqualityHelper.AreUrisEqual(activeGraphUri, u)))
                                    {
                                        //Either there was no Query
                                        //OR there were no Named Graphs (hence any Graph URI is permitted)
                                        //OR the specified URI was a Named Graph URI
                                        //In any case we can go ahead and set the active Graph
                                        activeGraphs.Add(activeGraphUri.ToString());
                                    }
                                    else
                                    {
                                        //The specified URI was not present in the Default/Named Graphs so return null
                                        context.OutputMultiset = new NullMultiset();
                                        return context.OutputMultiset;
                                    }
                                }
                                else
                                {
                                    //If specifies a specific Graph and not in the Dataset result is a null multiset
                                    context.OutputMultiset = new NullMultiset();
                                    return context.OutputMultiset;
                                }
                                break;
                            default:
                                throw new RdfQueryException("Cannot use a '" + this._graphSpecifier.GetType().ToString() + "' Token to specify the Graph for a GRAPH clause");
                        }
                    }
                    else
                    {
                        String gvar = this._graphSpecifier.Value.Substring(1);

                        //Watch out for the case in which the Graph Variable is not bound for all Sets in which case
                        //we still need to operate over all Graphs
                        if (context.InputMultiset.ContainsVariable(gvar) && context.InputMultiset.Sets.All(s => s[gvar] != null))
                        {
                            //If there are already values bound to the Graph variable for all Input Solutions then we limit the Query to those Graphs
                            List<Uri> graphUris = new List<Uri>();
                            foreach (ISet s in context.InputMultiset.Sets)
                            {
                                INode temp = s[gvar];
                                if (temp != null)
                                {
                                    if (temp.NodeType == NodeType.Uri)
                                    {
                                        activeGraphs.Add(temp.ToString());
                                        graphUris.Add(((IUriNode)temp).Uri);
                                    }
                                }
                            }
                        }
                        else
                        {
                            //Nothing yet bound to the Graph Variable so the Query is over all the named Graphs
                            if (context.Query != null && context.Query.NamedGraphs.Any())
                            {
                                //Query specifies one/more named Graphs
                                activeGraphs.AddRange(context.Query.NamedGraphs.Select(u => u.ToString()));
                            }
                            else
                            {
                                //Query is over entire dataset/default Graph since no named Graphs are explicitly specified
                                activeGraphs.AddRange(context.Data.GraphUris.Select(u => u.ToSafeString()));
                            }
                        }
                    }
//.........这里部分代码省略.........
开发者ID:jmahmud,项目名称:RDFer,代码行数:101,代码来源:Graph.cs

示例13: Evaluate

        /// <summary>
        /// Applies the Projection to the results of Evaluating the Inner Pattern
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            try
            {
                context.InputMultiset = context.Evaluate(this._pattern);//this._pattern.Evaluate(context);
            }
            catch (RdfQueryTimeoutException)
            {
                //If not partial results throw the error
                if (!context.Query.PartialResultsOnTimeout) throw;
            }

            IEnumerable<SparqlVariable> vars;
            if (context.Query != null)
            {
                vars = context.Query.Variables;
            }
            else
            {
                vars = this._variables;
            }

            //For Null and Identity Multisets this is just a simple selection
            if (context.InputMultiset is NullMultiset)
            {
                context.InputMultiset = new Multiset(vars.Select(v => v.Name));
                context.OutputMultiset = context.InputMultiset;
            }
            else if (context.InputMultiset is IdentityMultiset)
            {
                context.InputMultiset = new Multiset(vars.Select(v => v.Name));
                Set s = new Set();
                context.InputMultiset.Add(s);
                context.OutputMultiset = context.InputMultiset;
            }

            //If we have a Group Multiset then Projection is more complex
            GroupMultiset groupSet = null;
            if (context.InputMultiset is GroupMultiset)
            {
                groupSet = (GroupMultiset)context.InputMultiset;

                //Project all simple variables for the Groups here
                foreach (SparqlVariable v in vars.Where(v => v.IsResultVariable && !v.IsProjection && !v.IsAggregate))
                {
                    //Can only project a variable if it's used in the GROUP OR if it was assigned by a GROUP BY expression
                    if (context.Query != null)
                    {
                        if (!groupSet.ContainsVariable(v.Name) && !context.Query.GroupBy.Variables.Contains(v.Name))
                        {
                            throw new RdfQueryException("Cannot project the variable ?" + v.Name + " since this Query contains Grouping(s) but the given Variable is not in the GROUP BY - use the SAMPLE aggregate if you need to sample this Variable");
                        }
                    }

                    //Project the value for each variable
                    if (!groupSet.ContainsVariable(v.Name))
                    {
                        //Simple Variable Projection used in GROUP BY so grab first value as all should be same
                        //for the group
                        context.OutputMultiset.AddVariable(v.Name);
                        foreach (int id in groupSet.SetIDs)
                        {
                            INode value = groupSet.Contents[groupSet.GroupSetIDs(id).First()][v.Name];
                            context.OutputMultiset[id].Add(v.Name, value);
                        }
                    }
                }
            }
            else if (context.Query.IsAggregate)
            {
                context.OutputMultiset = new Multiset();
            }

            //Project the rest of the Variables
            Set aggSet = new Set();
            foreach (SparqlVariable v in vars.Where(v => v.IsResultVariable))
            {
                if (groupSet == null)
                {
                    context.InputMultiset.AddVariable(v.Name);
                }
                else
                {
                    context.OutputMultiset.AddVariable(v.Name);
                }

                if (v.IsAggregate)
                {
                    //Compute the Aggregate
                    if (groupSet != null)
                    {
                        context.InputMultiset = groupSet.Contents;
                        foreach (int id in groupSet.SetIDs)
                        {
                            INode aggValue = v.Aggregate.Apply(context, groupSet.GroupSetIDs(id));
//.........这里部分代码省略.........
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:101,代码来源:Project.cs

示例14: EvaluateInternal

        /// <summary>
        /// Internal method which evaluates the Graph Pattern
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <remarks>
        /// We only ever need to evaluate the Graph Pattern once to get the Results
        /// </remarks>
        private void EvaluateInternal(SparqlEvaluationContext context)
        {
            this._result = null;
            this._lastInput = context.InputMultiset.GetHashCode();
            this._lastCount = context.InputMultiset.Count;

            //REQ: Optimise the algebra here
            ISparqlAlgebra existsClause = this._pattern.ToAlgebra();
            BaseMultiset initialInput = context.InputMultiset;
            this._result = context.Evaluate(existsClause);
            context.InputMultiset = initialInput;

            //This is the new algorithm which is also correct but is O(3n) so much faster and scalable
            //Downside is that it does require more memory than the old algorithm
            this._joinVars = context.InputMultiset.Variables.Where(v => this._result.Variables.Contains(v)).ToList();
            if (this._joinVars.Count == 0) return;

            List<HashTable<INode, int>> values = new List<HashTable<INode, int>>();
            List<List<int>> nulls = new List<List<int>>();
            foreach (System.String var in this._joinVars)
            {
                values.Add(new HashTable<INode, int>(HashTableBias.Enumeration));
                nulls.Add(new List<int>());
            }

            //First do a pass over the LHS Result to find all possible values for joined variables
            foreach (ISet x in context.InputMultiset.Sets)
            {
                int i = 0;
                foreach (System.String var in this._joinVars)
                {
                    INode value = x[var];
                    if (value != null)
                    {
                        values[i].Add(value, x.ID);
                    }
                    else
                    {
                        nulls[i].Add(x.ID);
                    }
                    i++;
                }
            }

            //Then do a pass over the RHS and work out the intersections
            this._exists = new HashSet<int>();
            foreach (ISet y in this._result.Sets)
            {
                IEnumerable<int> possMatches = null;
                int i = 0;
                foreach (System.String var in this._joinVars)
                {
                    INode value = y[var];
                    if (value != null)
                    {
                        if (values[i].ContainsKey(value))
                        {
                            possMatches = (possMatches == null ? values[i].GetValues(value).Concat(nulls[i]) : possMatches.Intersect(values[i].GetValues(value).Concat(nulls[i])));
                        }
                        else
                        {
                            possMatches = Enumerable.Empty<int>();
                            break;
                        }
                    }
                    else
                    {
                        //Don't forget that a null will be potentially compatible with everything
                        possMatches = (possMatches == null ? context.InputMultiset.SetIDs : possMatches.Intersect(context.InputMultiset.SetIDs));
                    }
                    i++;
                }
                if (possMatches == null) continue;

                //Look at possible matches, if is a valid match then mark the set as having an existing match
                //Don't reconsider sets which have already been marked as having an existing match
                foreach (int poss in possMatches)
                {
                    if (this._exists.Contains(poss)) continue;
                    if (context.InputMultiset[poss].IsCompatibleWith(y, this._joinVars))
                    {
                        this._exists.Add(poss);
                    }
                }
            }
        }
开发者ID:jmahmud,项目名称:RDFer,代码行数:93,代码来源:ExistsFunction.cs

示例15: Evaluate

        /// <summary>
        /// Evaluates a Sub-query in the given Evaluation Context
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        public override void Evaluate(SparqlEvaluationContext context)
        {
            //Use the same algebra optimisers as the parent query (if any)
            if (context.Query != null)
            {
                this._subquery.AlgebraOptimisers = context.Query.AlgebraOptimisers;
            }

            if (context.InputMultiset is NullMultiset)
            {
                context.OutputMultiset = context.InputMultiset;
            }
            else if (context.InputMultiset.IsEmpty)
            {
                context.OutputMultiset = new NullMultiset();
            }
            else
            {
                SparqlEvaluationContext subcontext = new SparqlEvaluationContext(this._subquery, context.Data, context.Processor);
                subcontext.InputMultiset = context.InputMultiset;

                //Add any Named Graphs to the subquery
                if (context.Query != null)
                {
                    foreach (Uri u in context.Query.NamedGraphs)
                    {
                        this._subquery.AddNamedGraph(u);
                    }
                }

                ISparqlAlgebra query = this._subquery.ToAlgebra();
                try
                {
                    //Evaluate the Subquery
                    context.OutputMultiset = subcontext.Evaluate(query);

                    //If the Subquery contains a GROUP BY it may return a Group Multiset in which case we must flatten this to a Multiset
                    if (context.OutputMultiset is GroupMultiset)
                    {
                        context.OutputMultiset = new Multiset((GroupMultiset)context.OutputMultiset);
                    }

                    //Strip out any Named Graphs from the subquery
                    if (this._subquery.NamedGraphs.Any())
                    {
                        this._subquery.ClearNamedGraphs();
                    }
                }
                catch (RdfQueryException queryEx)
                {
                    throw new RdfQueryException("Query failed due to a failure in Subquery Execution:\n" + queryEx.Message, queryEx);
                }
            }
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:58,代码来源:SubQueryPattern.cs


注:本文中的SparqlEvaluationContext.Evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。