public void CanBuildUnionWithGraphPatternBuilders() { // Define two pattern builders which will be used to generate triple patterns for a UNION expression. GraphPatternBuilder patternBuilder0 = new GraphPatternBuilder(); GraphPatternBuilder patternBuilder1 = new GraphPatternBuilder(); IQueryBuilder queryBuilder0 = QueryBuilder .Ask() .Union(patternBuilder0, patternBuilder1); // Add some triple patterns after the UNION was added to the query. patternBuilder0.Where(p => p.Subject("s0").Predicate("p0").ObjectLiteral(0)); patternBuilder1.Where(p => p.Subject("s1").Predicate("p1").ObjectLiteral(1)); SparqlQuery q0 = queryBuilder0.BuildQuery(); Assert.Single(q0.RootGraphPattern.ChildGraphPatterns); Assert.True(q0.RootGraphPattern.ChildGraphPatterns.First().IsUnion); Assert.Equal(2, q0.RootGraphPattern.ChildGraphPatterns.First().ChildGraphPatterns.Count()); // Now add other triples to the query after the query was already build. patternBuilder1.Where(p => p.Subject("s1").Predicate("p2").ObjectLiteral(2)); SparqlQuery q1 = queryBuilder0.BuildQuery(); Assert.Single(q1.RootGraphPattern.ChildGraphPatterns); Assert.True(q1.RootGraphPattern.ChildGraphPatterns.First().IsUnion); Assert.Equal(2, q1.RootGraphPattern.ChildGraphPatterns.First().ChildGraphPatterns.Count()); Assert.Contains(q1.RootGraphPattern.ChildGraphPatterns.First().ChildGraphPatterns, p => p.ToString().Contains("p2")); }
public void ShouldAllowCreatingUnionOfTwoGraphPatterns() { // given _builder.Where(t => t.Subject("s").Predicate("p").Object("o")); // when var unionBuilder = _builder.Union(union => union.Where(t => t.Subject("x").Predicate("y").Object("z"))); var graphPattern = ((GraphPatternBuilder)unionBuilder).BuildGraphPattern(_namespaceMapper.Object); // then Assert.IsTrue(graphPattern.IsUnion); Assert.AreEqual(2, graphPattern.ChildGraphPatterns.Count); Assert.AreEqual(1, graphPattern.ChildGraphPatterns[0].TriplePatterns.Count); Assert.AreEqual(1, graphPattern.ChildGraphPatterns[1].TriplePatterns.Count); Assert.AreEqual(3, graphPattern.ChildGraphPatterns[0].Variables.Count()); Assert.AreEqual(3, graphPattern.ChildGraphPatterns[1].Variables.Count()); }
/// <inheritdoc /> public IGraphPatternBuilder Child(IQueryBuilder queryBuilder) { SparqlQuery subquery = queryBuilder.BuildQuery(); GraphPatternBuilder childBuilder = new GraphPatternBuilder(); childBuilder.Where(new SubQueryPattern(subquery)); _childGraphPatternBuilders.Add(childBuilder); return(this); }
IGraphPatternBuilder IAssignmentVariableNamePart <IGraphPatternBuilder> .As(string variableName) { _graphPatternBuilder.Where(mapper => new ITriplePattern[] { new BindPattern(variableName, BuildAssignmentExpression(mapper)) }); return(_graphPatternBuilder); }
public IDescribeGraphPatternBuilder Where(params ITriplePattern[] triplePatterns) { _builder.Where(triplePatterns); return(this); }