本文整理汇总了C#中ISparqlExpression.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ISparqlExpression.ToString方法的具体用法?C# ISparqlExpression.ToString怎么用?C# ISparqlExpression.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISparqlExpression
的用法示例。
在下文中一共展示了ISparqlExpression.ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatExpression
/// <summary>
/// Formats a SPARQL Expression
/// </summary>
/// <param name="expr">SPARQL Expression</param>
/// <returns></returns>
protected virtual String FormatExpression(ISparqlExpression expr)
{
StringBuilder output = new StringBuilder();
try
{
switch (expr.Type)
{
case SparqlExpressionType.Aggregate:
if (expr is AggregateExpressionTerm)
{
AggregateExpressionTerm agg = (AggregateExpressionTerm)expr;
output.Append(this.FormatAggregate(agg.Aggregate));
}
else if (expr is NonNumericAggregateExpressionTerm)
{
NonNumericAggregateExpressionTerm nonNumAgg = (NonNumericAggregateExpressionTerm)expr;
output.Append(this.FormatAggregate(nonNumAgg.Aggregate));
}
else
{
output.Append(expr.ToString());
}
break;
case SparqlExpressionType.BinaryOperator:
ISparqlExpression lhs = expr.Arguments.First();
ISparqlExpression rhs = expr.Arguments.Skip(1).First();
//Format the Expression wrapping the LHS and/or RHS in brackets if required
//to ensure that ordering of operators is preserved
if (lhs.Type == SparqlExpressionType.BinaryOperator)
{
output.Append('(');
output.Append(this.FormatExpression(lhs));
output.Append(')');
}
else
{
output.Append(this.FormatExpression(lhs));
}
output.Append(' ');
output.Append(expr.Functor);
output.Append(' ');
if (rhs.Type == SparqlExpressionType.BinaryOperator)
{
output.Append('(');
output.Append(this.FormatExpression(rhs));
output.Append(')');
}
else
{
output.Append(this.FormatExpression(rhs));
}
break;
case SparqlExpressionType.Function:
//Show either a Keyword/URI/QName as appropriate
if (SparqlSpecsHelper.IsFunctionKeyword(expr.Functor))
{
output.Append(expr.Functor);
}
else
{
String funcQname;
if (this._qnameMapper.ReduceToQName(expr.Functor, out funcQname))
{
output.Append(funcQname);
}
else
{
output.Append('<');
output.Append(this.FormatUri(expr.Functor));
output.Append('>');
}
}
//Add Arguments list
output.Append('(');
List<ISparqlExpression> args = expr.Arguments.ToList();
for (int i = 0; i < args.Count; i++)
{
output.Append(this.FormatExpression(args[i]));
if (i < args.Count - 1)
{
output.Append(", ");
}
}
output.Append(')');
break;
case SparqlExpressionType.GraphOperator:
output.Append(expr.Functor);
output.Append(' ');
//.........这里部分代码省略.........