/// <summary> /// Converts the Algebra back to a SPARQL Query /// </summary> /// <returns></returns> public SparqlQuery ToQuery() { SparqlQuery q = new SparqlQuery(); q.RootGraphPattern = this.ToGraphPattern(); q.Optimise(); return q; }
/// <summary> /// Converts the Algebra back to a SPARQL Query /// </summary> /// <returns></returns> public SparqlQuery ToQuery() { SparqlQuery q = new SparqlQuery(); q.RootGraphPattern = ToGraphPattern(); q.AddVariable(_graphVar, true); q.Optimise(); return(q); }
/// <summary> /// Converts the Algebra back to a SPARQL Query. /// </summary> /// <returns></returns> public SparqlQuery ToQuery() { var q = new SparqlQuery { RootGraphPattern = ToGraphPattern() }; q.Optimise(); return(q); }
/// <summary> /// Converts the Algebra back to a SPARQL Query /// </summary> /// <returns></returns> public SparqlQuery ToQuery() { SparqlQuery q = new SparqlQuery(); q.RootGraphPattern = this.ToGraphPattern(); q.Optimise(); return q; }
internal static INode ToSpinRdf(this SparqlQuery query, IGraph g) { INode root = g.CreateBlankNode(); SpinVariableTable varTable = new SpinVariableTable(g); //Ensure the Query is optimised so that all the elements are placed in Graph Patterns //so we can serialized them OK query.Optimise(); switch (query.QueryType) { case SparqlQueryType.Ask: g.Assert(root, RDF.PropertyType, SP.ClassAsk); break; case SparqlQueryType.Construct: g.Assert(root, RDF.PropertyType, SP.ClassConstruct); break; case SparqlQueryType.Describe: case SparqlQueryType.DescribeAll: throw new SpinException("DESCRIBE queries cannot be represented in SPIN RDF Syntax"); case SparqlQueryType.Select: case SparqlQueryType.SelectAll: case SparqlQueryType.SelectAllDistinct: case SparqlQueryType.SelectAllReduced: case SparqlQueryType.SelectDistinct: case SparqlQueryType.SelectReduced: g.Assert(root, RDF.PropertyType, SP.ClassSelect); break; case SparqlQueryType.Unknown: throw new SpinException("Unknown query types cannot be represented in SPIN RDF Syntax"); } //Process the WHERE clause g.Assert(root, SP.PropertyWhere, query.RootGraphPattern.ToSpinRdf(g, varTable)); //Add Variables for a SELECT query if (SparqlSpecsHelper.IsSelectQuery(query.QueryType)) { switch (query.QueryType) { case SparqlQueryType.Select: case SparqlQueryType.SelectDistinct: case SparqlQueryType.SelectReduced: //Only Add Variables for SELECTs with explicit variable lists INode vars = g.CreateBlankNode(); g.Assert(root, SP.PropertyResultVariables, vars); //Get the Variables and generate the Nodes we'll use to help represent them List <SparqlVariable> vs = query.Variables.Where(v => v.IsResultVariable).ToList(); for (int i = 0; i < vs.Count; i++) { SparqlVariable v = vs[i]; INode var = varTable[v.Name]; g.Assert(vars, RDF.PropertyFirst, var); if (i < vs.Count - 1) { INode temp = g.CreateBlankNode(); g.Assert(vars, RDF.PropertyRest, temp); vars = temp; } // TODO check that was commented before modifications //g.Assert(var, RDF.type, SP.Variable); if (v.IsAggregate) { g.Assert(var, SP.PropertyAs, g.CreateLiteralNode(v.Name, XSD.string_.Uri)); g.Assert(var, SP.PropertyExpression, v.Aggregate.ToSpinRdf(g, varTable)); } else if (v.IsProjection) { g.Assert(var, SP.PropertyAs, g.CreateLiteralNode(v.Name, XSD.string_.Uri)); //TODO check for this //g.Assert(var, SP.expression, v.Projection.ToSpinRdf(query.RootGraphPattern, g, varTable)); } else { g.Assert(var, SP.PropertyVarName, g.CreateLiteralNode(v.Name, XSD.string_.Uri)); } } g.Assert(vars, RDF.PropertyRest, RDF.Nil); break; } } //Add DISTINCT/REDUCED modifiers if appropriate if (query.HasDistinctModifier) { switch (query.QueryType) { case SparqlQueryType.SelectAllDistinct: case SparqlQueryType.SelectDistinct: g.Assert(root, SP.PropertyDistinct, RDFUtil.TRUE); break; case SparqlQueryType.SelectAllReduced: case SparqlQueryType.SelectReduced: g.Assert(root, SP.PropertyReduced, RDFUtil.TRUE); break; } } //Add LIMIT and/or OFFSET if appropriate if (query.Limit > -1) { g.Assert(root, SP.PropertyLimit, query.Limit.ToLiteral(g)); } if (query.Offset > 0) { g.Assert(root, SP.PropertyOffset, query.Offset.ToLiteral(g)); } //Add ORDER BY if appropriate if (query.OrderBy != null) { g.Assert(root, SP.PropertyOrderBy, query.OrderBy.ToSpinRdf(g, varTable)); } //Add GROUP BY and HAVING if (query.GroupBy != null) { throw new SpinException("GROUP BY clauses are not yet representable in SPIN RDF Syntax"); } if (query.Having != null) { throw new SpinException("HAVING clauses are not yet representable in SPIN RDF Syntax"); } return(root); }
/// <summary> /// Converts the Algebra back to a SPARQL Query /// </summary> /// <returns></returns> public SparqlQuery ToQuery() { SparqlQuery q = new SparqlQuery(); q.RootGraphPattern = this.ToGraphPattern(); q.AddVariable(this._graphVar, true); q.Optimise(); return q; }