public void SparqlFilterShouldGetPlaced()
        {
            // given
            var query = new SparqlQuery {
                QueryType = SparqlQueryType.SelectDistinct
            };

            query.AddVariable(new SparqlVariable("s", true));
            query.RootGraphPattern = new GraphPattern();
            var subj          = new VariablePattern("s");
            var rdfType       = new NodeMatchPattern(new UriNode(null, new Uri(RdfSpecsHelper.RdfType)));
            var type          = new VariablePattern("type");
            var triplePattern = new TriplePattern(subj, rdfType, type);

            query.RootGraphPattern.AddTriplePattern(triplePattern);
            query.RootGraphPattern.AddFilter(new UnaryExpressionFilter(new InFunction(new VariableTerm("type"), new[]
            {
                new ConstantTerm(new UriNode(null, new Uri("http://example.com/Type1"))),
                new ConstantTerm(new UriNode(null, new Uri("http://example.com/Type2"))),
                new ConstantTerm(new UriNode(null, new Uri("http://example.com/Type3")))
            })));

            // when
            var algebra = (Distinct)query.ToAlgebra();

            // then
            Assert.True(algebra.InnerAlgebra is Select);
            Assert.True(((Select)algebra.InnerAlgebra).InnerAlgebra is Filter);
        }
Beispiel #2
0
        public void SparqlFormattingOptionalAtRoot()
        {
            SparqlQuery q = new SparqlQuery {
                QueryType = SparqlQueryType.Select
            };

            q.AddVariable(new SparqlVariable("s", true));

            GraphPattern gp = new GraphPattern();

            gp.IsOptional = true;
            gp.AddTriplePattern(new TriplePattern(new VariablePattern("s"), new VariablePattern("p"), new VariablePattern("o")));
            q.RootGraphPattern = gp;

            String toStr = q.ToString();

            Console.WriteLine("ToString() Form:");
            Console.WriteLine(toStr);
            Assert.Equal(2, toStr.ToCharArray().Where(c => c == '{').Count());
            Assert.Equal(2, toStr.ToCharArray().Where(c => c == '}').Count());
            Console.WriteLine();

            SparqlFormatter formatter = new SparqlFormatter();
            String          fmtStr    = formatter.Format(q);

            Console.WriteLine("SparqlFormatter Form:");
            Console.WriteLine(fmtStr);
            Assert.Equal(2, fmtStr.ToCharArray().Where(c => c == '{').Count());
            Assert.Equal(2, fmtStr.ToCharArray().Where(c => c == '}').Count());
        }