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


C# SparqlEvaluationContext类代码示例

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


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

示例1: Evaluate

 /// <summary>
 /// Gets the value of the function in the given Evaluation Context for the given Binding ID
 /// </summary>
 /// <param name="context">Evaluation Context</param>
 /// <param name="bindingID">Binding ID</param>
 /// <returns></returns>
 public override IValuedNode Evaluate(SparqlEvaluationContext context, int bindingID)
 {
     INode temp = this._expr.Evaluate(context, bindingID);
     if (temp != null)
     {
         if (temp.NodeType == NodeType.Uri)
         {
             IUriNode u = (IUriNode)temp;
             if (!u.Uri.Fragment.Equals(String.Empty))
             {
                 return new StringNode(null, u.Uri.Fragment.Substring(1));
             }
             else
             {
     #if SILVERLIGHT
                 return new StringNode(null, u.Uri.Segments().Last());
     #else
                 return new StringNode(null, u.Uri.Segments.Last());
     #endif
             }
         }
         else
         {
             throw new RdfQueryException("Cannot find the Local Name for a non-URI Node");
         }
     }
     else
     {
         throw new RdfQueryException("Cannot find the Local Name for a null");
     }
 }
开发者ID:jmahmud,项目名称:RDFer,代码行数:37,代码来源:LocalNameFunction.cs

示例2: Evaluate

        /// <summary>
        /// Evaluates the Select Distinct Graphs optimisation
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            context.OutputMultiset = new Multiset();
            String var;
            if (context.Query != null)
            {
                var = context.Query.Variables.First(v => v.IsResultVariable).Name;
            }
            else
            {
                var = this._graphVar;
            }

            foreach (Uri graphUri in context.Data.GraphUris)
            {
                Set s = new Set();
                if (graphUri == null)
                {
                    s.Add(var, null);
                }
                else
                {
                    s.Add(var, new UriNode(null, graphUri));
                }
                context.OutputMultiset.Add(s);
            }

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

示例3: NumericValue

 /// <summary>
 ///   Gets the numeric value of the function in the given Evaluation Context for the given Binding ID
 /// </summary>
 /// <param name = "context">Evaluation Context</param>
 /// <param name = "bindingID">Binding ID</param>
 /// <returns></returns>
 public override object NumericValue(SparqlEvaluationContext context, int bindingID)
 {
     INode temp = _expr.Value(context, bindingID);
     if (temp != null)
     {
         if (temp.NodeType == NodeType.Literal)
         {
             ILiteralNode lit = (ILiteralNode) temp;
             if (lit.DataType != null)
             {
                 if (lit.DataType.ToString().Equals(XmlSpecsHelper.XmlSchemaDataTypeDateTime) ||
                     lit.DataType.ToString().Equals(XmlSpecsHelper.XmlSchemaDataTypeDate))
                 {
                     DateTimeOffset dt;
                     if (DateTimeOffset.TryParse(lit.Value, out dt))
                     {
                         return NumericValueInternal(dt);
                     }
                     throw new RdfQueryException(
                         "Unable to evaluate an XPath Date Time function as the value of the Date Time typed literal couldn't be parsed as a Date Time");
                 }
                 throw new RdfQueryException(
                     "Unable to evaluate an XPath Date Time function on a typed literal which is not a Date Time");
             }
             throw new RdfQueryException(
                 "Unable to evaluate an XPath Date Time function on an untyped literal argument");
         }
         throw new RdfQueryException(
             "Unable to evaluate an XPath Date Time function on a non-literal argument");
     }
     throw new RdfQueryException("Unable to evaluate an XPath Date Time function on a null argument");
 }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:38,代码来源:XPathDateTimeFunctions.cs

示例4: NumericValue

        /// <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 object NumericValue(SparqlEvaluationContext context, int bindingID)
        {
            if (this._leftExpr is ISparqlNumericExpression && this._rightExpr is ISparqlNumericExpression)
            {
                ISparqlNumericExpression a, b;
                a = (ISparqlNumericExpression)this._leftExpr;
                b = (ISparqlNumericExpression)this._rightExpr;

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

                switch (type)
                {
                    case SparqlNumericType.Integer:
                        return a.IntegerValue(context, bindingID) + b.IntegerValue(context, bindingID);
                    case SparqlNumericType.Decimal:
                        return a.DecimalValue(context, bindingID) + b.DecimalValue(context, bindingID);
                    case SparqlNumericType.Float:
                        return a.FloatValue(context, bindingID) + b.FloatValue(context, bindingID);
                    case SparqlNumericType.Double:
                        return a.DoubleValue(context, bindingID) + b.DoubleValue(context, bindingID);
                    default:
                        throw new RdfQueryException("Cannot evalute an Arithmetic Expression when the Numeric Type of the expression cannot be determined");
                }
            }
            else
            {
                throw new RdfQueryException("Cannot evalute an Arithmetic Expression where the two sub-expressions are not Numeric Expressions");
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:35,代码来源:SparqlNumericExpressions.cs

示例5: Evaluate

        /// <summary>
        /// Gets the Timezone of the Argument Expression as evaluated for the given Binding in the given Context
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingID">Binding ID</param>
        /// <returns></returns>
        public override IValuedNode Evaluate(SparqlEvaluationContext context, int bindingID)
        {
            IValuedNode temp = this._expr.Evaluate(context, bindingID);
            if (temp != null)
            {
                DateTimeOffset dt = temp.AsDateTime();
                //Regex based check to see if the value has a Timezone component
                //If not then the result is a null
                if (!Regex.IsMatch(temp.AsString(), "(Z|[+-]\\d{2}:\\d{2})$")) return new StringNode(null, string.Empty);

                //Now we have a DateTime we can try and return the Timezone
                if (dt.Offset.Equals(TimeSpan.Zero))
                {
                    //If Zero it was specified as Z (which means UTC so zero offset)
                    return new StringNode(null, "Z");
                }
                else
                {
                    //If the Offset is outside the range -14 to 14 this is considered invalid
                    if (dt.Offset.Hours < -14 || dt.Offset.Hours > 14) return null;

                    //Otherwise it has an offset which is a given number of hours (and minutes)
                    return new StringNode(null, dt.Offset.Hours.ToString("00") + ":" + dt.Offset.Minutes.ToString("00"));
                }
            }
            else
            {
                throw new RdfQueryException("Unable to evaluate a Date Time function on a null argument");
            }
        }
开发者ID:jmahmud,项目名称:RDFer,代码行数:36,代码来源:TZFunction.cs

示例6: EffectiveBooleanValue

 /// <summary>
 /// Computes the Effective Boolean 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 bool EffectiveBooleanValue(SparqlEvaluationContext context, int bindingID)
 {
     //Lazy Evaluation for efficiency
     try
     {
         bool leftResult = this._leftExpr.EffectiveBooleanValue(context, bindingID);
         if (leftResult)
         {
             //If the LHS is true it doesn't matter about any subsequenct results
             return true;
         }
         else
         {
             //If the LHS is false then we have to evaluate the RHS
             return this._rightExpr.EffectiveBooleanValue(context, bindingID);
         }
     }
     catch
     {
         //If there's an Error on the LHS we return true only if the RHS evaluates to true
         //Otherwise we throw the Error
         bool rightResult = this._rightExpr.EffectiveBooleanValue(context, bindingID);
         if (rightResult)
         {
             return true;
         }
         else
         {
             throw;
         }
     }
 }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:38,代码来源:SPARQLExpressionClasses.cs

示例7: Evaluate

        /// <summary>
        /// Returns the value of the Expression as evaluated for a given Binding as a Literal Node
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingID">Binding ID</param>
        /// <returns></returns>
        public override IValuedNode Evaluate(SparqlEvaluationContext context, int bindingID)
        {
            INode result = this._expr.Evaluate(context, bindingID);
            if (result == null)
            {
                throw new RdfQueryException("Cannot return the Data Type URI of a NULL");
            }
            else
            {
                switch (result.NodeType)
                {
                    case NodeType.Literal:
                        ILiteralNode lit = (ILiteralNode)result;
                        if (lit.DataType == null)
                        {
                            if (!lit.Language.Equals(string.Empty))
                            {
                                return new UriNode(null, UriFactory.Create(RdfSpecsHelper.RdfLangString));
                            }
                            else
                            {
                                return new UriNode(null, UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeString));
                            }
                        }
                        else
                        {
                            return new UriNode(null, lit.DataType);
                        }

                    default:
                        throw new RdfQueryException("Cannot return the Data Type URI of Nodes which are not Literal Nodes");
                }
            }
        }
开发者ID:jmahmud,项目名称:RDFer,代码行数:40,代码来源:DataTypeFunction.cs

示例8: Evaluate

        /// <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);
            if (a == null || b == null) throw new RdfQueryException("Cannot apply division when one/both arguments are null");

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

            try
            {
                switch (type)
                {
                    case SparqlNumericType.Integer:
                    case SparqlNumericType.Decimal:
                        //For Division Integers are treated as decimals
                        decimal d = a.AsDecimal() / b.AsDecimal();
                        if (Decimal.Floor(d).Equals(d) && d >= Int64.MinValue && d <= Int64.MaxValue)
                        {
                            return new LongNode(null, Convert.ToInt64(d));
                        }
                        return new DecimalNode(null, d);
                    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");
                }
            }
            catch (DivideByZeroException)
            {
                throw new RdfQueryException("Cannot evaluate a Division Expression where the divisor is Zero");
            }
        }
开发者ID:jmahmud,项目名称:RDFer,代码行数:40,代码来源:DivisionExpression.cs

示例9: PathEvaluationContext

 /// <summary>
 /// Creates a new Path Evaluation Context
 /// </summary>
 /// <param name="context">SPARQL Evaluation Context</param>
 /// <param name="end">Start point of the Path</param>
 /// <param name="start">End point of the Path</param>
 public PathEvaluationContext(SparqlEvaluationContext context, PatternItem start, PatternItem end)
 {
     this._context = context;
     this._start = start;
     this._end = end;
     if (this._start.VariableName == null && this._end.VariableName == null) this._earlyAbort = true;
 }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:13,代码来源:PathEvaluationContext.cs

示例10: Evaluate

        /// <summary>
        /// Gets the Numeric Value of the function as evaluated in the given Context for the given Binding ID
        /// </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._expr.Evaluate(context, bindingID);
            if (a == null) throw new RdfQueryException("Cannot calculate an arithmetic expression on a null");

            switch (a.NumericType)
            {
                case SparqlNumericType.Integer:
                    return new LongNode(null, Math.Abs(a.AsInteger()));

                case SparqlNumericType.Decimal:
                    return new DecimalNode(null, Math.Abs(a.AsDecimal()));

                case SparqlNumericType.Float:
                    try
                    {
                        return new FloatNode(null, Convert.ToSingle(Math.Abs(a.AsDouble())));
                    }
                    catch (RdfQueryException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        throw new RdfQueryException("Unable to cast absolute value of float to a float", ex);
                    }

                case SparqlNumericType.Double:
                    return new DoubleNode(null, Math.Abs(a.AsDouble()));

                default:
                    throw new RdfQueryException("Cannot evalute an Arithmetic Expression when the Numeric Type of the expression cannot be determined");
            }
        }
开发者ID:jmahmud,项目名称:RDFer,代码行数:40,代码来源:AbsFunction.cs

示例11: NumericValue

        /// <summary>
        /// Gets the Numeric Value of the function as evaluated in the given Context for the given Binding ID
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingID">Binding ID</param>
        /// <returns></returns>
        public override object NumericValue(SparqlEvaluationContext context, int bindingID)
        {
            if (this._expr is ISparqlNumericExpression)
            {
                ISparqlNumericExpression a = (ISparqlNumericExpression)this._expr;

                switch (a.NumericType(context, bindingID))
                {
                    case SparqlNumericType.Integer:
                        return Math.Abs(a.IntegerValue(context, bindingID));

                    case SparqlNumericType.Decimal:
                        return Math.Abs(a.DecimalValue(context, bindingID));

                    case SparqlNumericType.Float:
                        return (float)Math.Abs(a.DoubleValue(context, bindingID));

                    case SparqlNumericType.Double:
                        return Math.Abs(a.DoubleValue(context, bindingID));
                        
                    default:
                        throw new RdfQueryException("Cannot evalute an Arithmetic Expression when the Numeric Type of the expression cannot be determined");
                }
            }
            else
            {
                throw new RdfQueryException("Cannot evalute an Arithmetic Expression where the sub-expression is not a Numeric Expressions");
            }
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:35,代码来源:XPathNumericFunctions.cs

示例12: DescribeInternal

        /// <summary>
        /// Generates the Description for each of the Nodes to be described
        /// </summary>
        /// <param name="handler">RDF Handler</param>
        /// <param name="context">SPARQL Evaluation Context</param>
        /// <param name="nodes">Nodes to be described</param>
        protected override void DescribeInternal(IRdfHandler handler, SparqlEvaluationContext context, IEnumerable<INode> nodes)
        {
            //Rewrite Blank Node IDs for DESCRIBE Results
            Dictionary<String, INode> bnodeMapping = new Dictionary<string, INode>();

            //Get Triples for this Subject
            Queue<INode> bnodes = new Queue<INode>();
            HashSet<INode> expandedBNodes = new HashSet<INode>();
            INode rdfsLabel = handler.CreateUriNode(UriFactory.Create(NamespaceMapper.RDFS + "label"));
            foreach (INode n in nodes)
            {
                //Get Triples where the Node is the Subject
                foreach (Triple t in context.Data.GetTriplesWithSubject(n))
                {
                    if (t.Object.NodeType == NodeType.Blank)
                    {
                        if (!expandedBNodes.Contains(t.Object)) bnodes.Enqueue(t.Object);
                    }
                    if (!handler.HandleTriple((this.RewriteDescribeBNodes(t, bnodeMapping, handler)))) ParserHelper.Stop();
                }

                //Compute the Blank Node Closure for this Subject
                while (bnodes.Count > 0)
                {
                    INode bsubj = bnodes.Dequeue();
                    if (expandedBNodes.Contains(bsubj)) continue;
                    expandedBNodes.Add(bsubj);

                    foreach (Triple t2 in context.Data.GetTriplesWithSubjectPredicate(bsubj, rdfsLabel))
                    {
                        if (!handler.HandleTriple((this.RewriteDescribeBNodes(t2, bnodeMapping, handler)))) ParserHelper.Stop();
                    }
                }
            }
        }
开发者ID:jmahmud,项目名称:RDFer,代码行数:41,代码来源:LabelledDescription.cs

示例13: Evaluate

        /// <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._expr.Evaluate(context, bindingID);
            if (a == null) throw new RdfQueryException("Cannot apply unary minus to a null");

            switch (a.NumericType)
            {
                case SparqlNumericType.Integer:
                    return new LongNode(null, -1 * a.AsInteger());

                case SparqlNumericType.Decimal:
                    decimal decvalue = a.AsDecimal();
                    if (decvalue == Decimal.Zero)
                    {
                        return new DecimalNode(null, Decimal.Zero);
                    }
                    else
                    {
                        return new DecimalNode(null, -1 * decvalue);
                    }
                case SparqlNumericType.Float:
                    float fltvalue = a.AsFloat();
                    if (Single.IsNaN(fltvalue))
                    {
                        return new FloatNode(null, Single.NaN);
                    }
                    else if (Single.IsPositiveInfinity(fltvalue))
                    {
                        return new FloatNode(null, Single.NegativeInfinity);
                    }
                    else if (Single.IsNegativeInfinity(fltvalue))
                    {
                        return new FloatNode(null, Single.PositiveInfinity);
                    }
                    else
                    {
                        return new FloatNode(null, -1.0f * fltvalue);
                    }
                case SparqlNumericType.Double:
                    double dblvalue = a.AsDouble();
                    if (Double.IsNaN(dblvalue))
                    {
                        return new DoubleNode(null, Double.NaN);
                    }
                    else if (Double.IsPositiveInfinity(dblvalue))
                    {
                        return new DoubleNode(null, Double.NegativeInfinity);
                    }
                    else if (Double.IsNegativeInfinity(dblvalue))
                    {
                        return new DoubleNode(null, Double.PositiveInfinity);
                    }
                    else
                    {
                        return new DoubleNode(null, -1.0 * dblvalue);
                    }
                default:
                    throw new RdfQueryException("Cannot evalute an Arithmetic Expression when the Numeric Type of the expression cannot be determined");
            }
        }
开发者ID:jmahmud,项目名称:RDFer,代码行数:66,代码来源:MinusExpression.cs

示例14: Evaluate

        /// <summary>
        /// Evaluates a Filter in the given Evaluation Context
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        public override void Evaluate(SparqlEvaluationContext 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 is ignored

                    try
                    {
                        if (!this._filter.Expression.EffectiveBooleanValue(context, 0))
                        {
                            context.OutputMultiset = new NullMultiset();
                            return;
                        }
                    }
                    catch
                    {
                        context.OutputMultiset = new NullMultiset();
                        return;
                    }
                }
            }
            else
            {
                this._filter.Evaluate(context);
            }
            context.OutputMultiset = new IdentityMultiset();
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:38,代码来源:FilterPattern.cs

示例15: NumericValue

        /// <summary>
        /// Gets the Numeric Value of the Function as evaluated in the given Context for the given Binding ID
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingID">Binding ID</param>
        /// <returns></returns>
        public override object NumericValue(SparqlEvaluationContext context, int bindingID)
        {
            if (this._expr is ISparqlNumericExpression)
            {
                ISparqlNumericExpression a = (ISparqlNumericExpression)this._expr;

                SparqlNumericType type = a.NumericType(context, bindingID);
                switch (type)
                {
                    case SparqlNumericType.Integer:
                        return this.IntegerValueInternal(a.IntegerValue(context, bindingID));
                    case SparqlNumericType.Decimal:
                        return this.DecimalValueInternal(a.DecimalValue(context, bindingID));
                    case SparqlNumericType.Double:
                        return this.DoubleValueInternal(a.DoubleValue(context, bindingID));
                    case SparqlNumericType.NaN:
                    default:
                        throw new RdfQueryException("Unable to evaluate a Leviathan Numeric Expression since the inner expression did not evaluate to a Numeric Value");
                }
            }
            else
            {
                throw new RdfQueryException("Unable to evaluate a Leviathan Numeric Expression since the inner expression is not a Numeric Expression");
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:31,代码来源:LeviathanNumericFunctions.cs


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