public static string GetProjectedName(this ISparqlAggregate aggregate, string variableName) { string name = variableName; string functor = aggregate.Functor.ToLowerInvariant(); return(string.Format("{0}_{1}", name, functor)); }
/// <summary> /// Formats a SPARQL Aggregate /// </summary> /// <param name="agg">SPARQL Aggregate</param> /// <returns></returns> protected virtual String FormatAggregate(ISparqlAggregate agg) { StringBuilder output = new StringBuilder(); if (SparqlSpecsHelper.IsAggregateFunctionKeyword(agg.Functor)) { output.Append(agg.Functor); } else { String aggQName; if (this._qnameMapper.ReduceToQName(agg.Functor, out aggQName)) { output.Append(aggQName); } else { output.Append('<'); output.Append(this.FormatUri(agg.Functor)); output.Append('>'); } } output.Append('('); List <ISparqlExpression> args = agg.Arguments.ToList(); for (int i = 0; i < args.Count; i++) { output.Append(this.FormatExpression(args[i])); if (i < args.Count - 1 && !(args[i] is DistinctModifier)) { output.Append(", "); } } output.Append(')'); return(output.ToString()); }
internal static INode ToSpinRdf(this ISparqlAggregate aggregate, IGraph g, SpinVariableTable varTable) { INode a = g.CreateBlankNode(); INode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); if (aggregate is AverageAggregate) { g.Assert(a, rdfType, g.CreateUriNode(new Uri(SpinClassAvg))); } else if (aggregate is CountAggregate) { g.Assert(a, rdfType, g.CreateUriNode(new Uri(SpinClassCount))); } else if (aggregate is MaxAggregate) { g.Assert(a, rdfType, g.CreateUriNode(new Uri(SpinClassMax))); } else if (aggregate is MinAggregate) { g.Assert(a, rdfType, g.CreateUriNode(new Uri(SpinClassMin))); } else if (aggregate is SumAggregate) { g.Assert(a, rdfType, g.CreateUriNode(new Uri(SpinClassSum))); } else if (aggregate is GroupConcatAggregate) { throw new SpinException("GROUP_CONCAT aggregates are not yet representable in SPIN RDF Syntax"); } else if (aggregate is SampleAggregate) { throw new SpinException("SAMPLE aggregates are not yet representable in SPIN RDF Syntax"); } g.Assert(a, g.CreateUriNode(new Uri(SpinPropertyExpression)), aggregate.Expression.ToSpinRdf(g, varTable)); return(a); }
/// <summary> /// Creates a new Sparql Variable which is an Aggregate. /// </summary> /// <param name="name">Variable Name (with leading ?/$ removed).</param> /// <param name="aggregate">Aggregate Function.</param> /// <remarks>All Aggregate Variables are automatically considered as Result Variables.</remarks> public SparqlVariable(String name, ISparqlAggregate aggregate) : this(name, true) { _aggregate = aggregate; }
/// <summary> /// Creates a new Aggregate Expression Term that uses the given Aggregate. /// </summary> /// <param name="aggregate">Aggregate.</param> public AggregateTerm(ISparqlAggregate aggregate) : base(null) { _aggregate = aggregate; }
/// <summary> /// Formats a SPARQL Aggregate /// </summary> /// <param name="agg">SPARQL Aggregate</param> /// <returns></returns> protected virtual String FormatAggregate(ISparqlAggregate agg) { StringBuilder output = new StringBuilder(); if (SparqlSpecsHelper.IsAggregateFunctionKeyword(agg.Functor)) { output.Append(agg.Functor); } else { String aggQName; if (this._qnameMapper.ReduceToQName(agg.Functor, out aggQName)) { output.Append(aggQName); } else { output.Append('<'); output.Append(this.FormatUri(agg.Functor)); output.Append('>'); } } output.Append('('); List<ISparqlExpression> args = agg.Arguments.ToList(); for (int i = 0; i < args.Count; i++) { output.Append(this.FormatExpression(args[i])); if (i < args.Count - 1 && !(args[i] is DistinctModifierExpression)) { output.Append(", "); } } output.Append(')'); return output.ToString(); }
/// <summary> /// Creates a new Sparql Variable which is an Aggregate /// </summary> /// <param name="name">Variable Name (with leading ?/$ removed)</param> /// <param name="aggregate">Aggregate Function</param> /// <remarks>All Aggregate Variables are automatically considered as Result Variables</remarks> public SparqlVariable(String name, ISparqlAggregate aggregate) : this(name, true) { this._aggregate = aggregate; }
/// <summary> /// Creates a new non-numeric Aggregate Expression Term /// </summary> /// <param name="agg"></param> public NonNumericAggregateExpressionTerm(ISparqlAggregate agg) { this._aggregate = agg; }
/// <summary> /// Creates a new Aggregate Expression Term that uses the given Aggregate /// </summary> /// <param name="aggregate">Aggregate</param> public AggregateExpressionTerm(ISparqlAggregate aggregate) : base(null) { this._aggregate = aggregate; }
/// <summary> /// Creates a new Aggregate Expression Term that uses the given Aggregate /// </summary> /// <param name="aggregate">Aggregate</param> public AggregateTerm(ISparqlAggregate aggregate) : base(null) { this._aggregate = aggregate; }
public static SparqlVariable AsSparqlVariable(this ISparqlAggregate aggregate) { string variableName = aggregate.Expression.Variables.First(); return(new SparqlVariable(aggregate.GetProjectedName(variableName), aggregate)); }