private IEnumerable <SparqlQuery> GetRemoteQueries(SparqlEvaluationContext context, ISet[] bindings) { if (bindings.Length == 0) { // No pre-bound variables/BINDINGS clause so just return the query yield return(GetRemoteQuery(context)); } else { // Split bindings in chunks and inject them foreach (var chunk in bindings.ChunkBy(100)) { var vars = chunk.SelectMany(x => x.Variables).Distinct(); var data = new BindingsPattern(vars); foreach (var set in chunk) { var tuple = new BindingTuple( new List <string>(set.Variables), new List <PatternItem>(set.Values.Select(x => new NodeMatchPattern(x)))); data.AddTuple(tuple); } var sparqlQuery = GetRemoteQuery(context); sparqlQuery.RootGraphPattern.AddInlineData(data); yield return(sparqlQuery); } } }
/// <summary> /// Creates a new BINDINGS modifier /// </summary> /// <param name="bindings">Bindings</param> public Bindings(BindingsPattern bindings) { if (bindings == null) { throw new ArgumentNullException("bindings", "Bindings cannot be null"); } _bindings = bindings; }
/// <summary> /// Creates a new BINDINGS modifier /// </summary> /// <param name="bindings">Bindings</param> public Bindings(BindingsPattern bindings) { if (bindings == null) { throw new ArgumentNullException("Null Bindings"); } this._bindings = bindings; }
public void InsertValuesClause() { var g = new Graph(); g.LoadFromFile("resources\\rvesse.ttl"); var parser = new SparqlQueryParser(); SparqlQuery startingQuery = parser.ParseFromString("SELECT * WHERE { <http://www.dotnetrdf.org/people#rvesse> ?p ?o }"); var bindingVars = new List<string> {"p"}; var binding = new BindingsPattern(bindingVars); binding.AddTuple(new BindingTuple(bindingVars, new List<PatternItem> { new NodeMatchPattern(g.CreateUriNode(UriFactory.Create("http://xmlns.com/foaf/0.1/name"))) })); binding.AddTuple(new BindingTuple(bindingVars, new List<PatternItem> { new NodeMatchPattern(g.CreateUriNode(UriFactory.Create("http://xmlns.com/foaf/0.1/givenname"))) })); startingQuery.RootGraphPattern.AddInlineData(binding); g.ExecuteQuery(startingQuery).Should().BeAssignableTo<SparqlResultSet>().Which.Count.Should().Be(2); }
/// <summary> /// Formats the Inline Data portion of a Query /// </summary> /// <param name="data">Inline Data</param> /// <returns></returns> protected virtual String FormatInlineData(BindingsPattern data) { StringBuilder output = new StringBuilder(); output.Append("VALUES ( "); foreach (String var in data.Variables) { output.Append("?" + var); output.Append(' '); } output.Append(')'); if (data.Variables.Any()) { output.AppendLine(); } output.Append('{'); bool multipleTuples = data.Tuples.Count() > 1; if (multipleTuples) { output.AppendLine(); } foreach (BindingTuple tuple in data.Tuples) { if (tuple.IsEmpty) { if (multipleTuples) { output.AppendLineIndented("()", 2); } else { output.Append(" () "); } continue; } if (multipleTuples) { output.AppendIndented("(", 2); } else { output.Append("("); } foreach (String var in data.Variables) { output.Append(' '); if (tuple[var] == null) { output.AppendLine(SparqlSpecsHelper.SparqlKeywordUndef); } else { output.Append(this.Format(tuple[var], null)); } } if (multipleTuples) { output.AppendLine(")"); } else { output.Append(')'); } } output.AppendLine("}"); return(output.ToString()); }
public InlineDataBuilder(IEnumerable <string> variables) { _variables = variables.ToList(); _bindingsPattern = new BindingsPattern(_variables); }
public static BindingsPatternAssertions Should(this BindingsPattern pattern) { return(new BindingsPatternAssertions(pattern)); }
/// <summary> /// Creates a new BINDINGS modifier /// </summary> /// <param name="bindings">Bindings</param> /// <param name="pattern">Pattern</param> public Bindings(BindingsPattern bindings, ISparqlAlgebra pattern) { this._bindings = bindings; this._pattern = pattern; }