Пример #1
0
 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);
         }
     }
 }
Пример #2
0
        public IInlineDataBuilder Values(Action <IBindingTupleBuilder> buildWith)
        {
            var builder = new BindingTupleBuilder(_variables);

            buildWith(builder);
            _bindingsPattern.AddTuple(builder.GetTuple());
            return(this);
        }
Пример #3
0
 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);
 }