Esempio n. 1
0
        /// <summary>
        /// Gets the String representation of the Algebra
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            String filter = _filter.ToString();

            filter = filter.Substring(7, filter.Length - 8);
            return("LeftJoin(" + _lhs.ToString() + ", " + _rhs.ToString() + ", " + filter + ")");
        }
Esempio n. 2
0
        public void FullTextOptimiserComplex3()
        {
            SparqlQuery    q       = this.TestOptimisation("SELECT * WHERE { ?s pf:textMatch 'value' . BIND(STR(?s) AS ?str) }");
            ISparqlAlgebra algebra = q.ToAlgebra();

            Assert.DoesNotContain("PropertyFunction(Extend(", algebra.ToString());
        }
Esempio n. 3
0
        public void SparqlSequenceUpdateThenQuery2()
        {
            InMemoryDataset          dataset         = new InMemoryDataset();
            LeviathanUpdateProcessor updateProcessor = new LeviathanUpdateProcessor(dataset);
            LeviathanQueryProcessor  queryProcessor  = new LeviathanQueryProcessor(dataset);

            Assert.Equal(1, dataset.Graphs.Count());

            SparqlUpdateCommandSet updates = this._updateParser.ParseFromFile("resources\\sparql\\protocol\\update_dataset_default_graphs.ru");

            updateProcessor.ProcessCommandSet(updates);

            Assert.Equal(5, dataset.Graphs.Count());
            Assert.Equal(2, dataset[UriFactory.Create("http://example.org/protocol-update-dataset-graphs-test/")].Triples.Count());

            SparqlQuery query = this._queryParser.ParseFromFile("resources\\sparql\\protocol\\update_dataset_default_graphs.rq");

            ISparqlAlgebra algebra = query.ToAlgebra();

            Console.WriteLine(algebra.ToString());

            SparqlResultSet results = queryProcessor.ProcessQuery(query) as SparqlResultSet;

            Assert.NotNull(results);
            Assert.Equal(SparqlResultsType.Boolean, results.ResultsType);
            Assert.True(results.Result);
        }
Esempio n. 4
0
        private void RunTest(ISparqlPath path, IEnumerable <String> expectedOperators)
        {
            VariablePattern      x       = new VariablePattern("?x");
            VariablePattern      y       = new VariablePattern("?y");
            PathTransformContext context = new PathTransformContext(x, y);

            Console.WriteLine("Path: " + path.ToString());

            ISparqlAlgebra algebra = path.ToAlgebra(context);
            String         result  = algebra.ToString();

            Console.WriteLine("Algebra: " + result);

            try
            {
                GraphPattern gp = algebra.ToGraphPattern();
                Console.WriteLine("GraphPattern:");
                Console.WriteLine(this._formatter.Format(gp));
                Console.WriteLine();
            }
            catch
            {
                Console.WriteLine("Algebra not translatable to a GraphPattern");
            }

            foreach (String op in expectedOperators)
            {
                if (result.Contains(op))
                {
                    continue;
                }
                Console.WriteLine("Expected Operator '" + op + "' missing");
                Assert.True(false, "Expected Operator '" + op + "' missing");
            }
        }
Esempio n. 5
0
        public void FullTextOptimiserComplex4()
        {
            SparqlQuery    q       = this.TestOptimisation("SELECT * WHERE { (?s ?score) pf:textMatch 'value' . BIND(STR(?s) AS ?str) }");
            ISparqlAlgebra algebra = q.ToAlgebra();

            Assert.IsFalse(algebra.ToString().Contains("PropertyFunction(Extend("));
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the String representation of the FILTER.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            String filter = _filter.ToString();

            filter = filter.Substring(7, filter.Length - 8);
            return(GetType().Name + "(" + _pattern.ToString() + ", " + filter + ")");
        }
        private string TranslateSparqlToSQL(SparqlQuery query)
        {
            //Do Handler null checks before evaluating the query
            if (query == null)
            {
                throw new ArgumentNullException("query", "Cannot evaluate a null query");
            }

            //Reset Query Timers
            query.QueryExecutionTime = null;

            //Convert to Algebra and execute the Query
            //SparqlEvaluationContext context = this.GetContext(query);

            ISparqlAlgebra algebra = query.ToAlgebra();

            Console.WriteLine(algebra.ToString());
            //result = context.Evaluate(algebra); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            return(ProcessAlgebra(algebra));
        }
        private void TestStrictOptimiser(String query, String[] expectedOperators)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            Console.WriteLine("Query:");
            Console.WriteLine(this._formatter.Format(q));
            Console.WriteLine();

            q.AlgebraOptimisers = new IAlgebraOptimiser[] { this._optimiser };
            ISparqlAlgebra algebra = q.ToAlgebra();
            String         output  = algebra.ToString();

            Console.WriteLine("Algebra:");
            Console.WriteLine(output);
            Console.WriteLine();

            foreach (String op in expectedOperators)
            {
                Assert.True(output.Contains(op), "Should have contained " + op + " Operator");
            }
        }
Esempio n. 9
0
        public void SparqlBindScope6()
        {
            String query = @"PREFIX : <http://example.org>
SELECT *
WHERE
{
  {
    GRAPH ?g { :s :p ?o }
    BIND (?g AS ?in)
  }
  UNION
  {
    :s :p ?o .
    BIND('default' AS ?in)
  }
}";

            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery       q      = parser.ParseFromString(query);

            Console.WriteLine(q.ToString());

            ISparqlAlgebra algebra = q.ToAlgebra();

            Console.WriteLine(algebra.ToString());
            Assert.IsInstanceOfType(algebra, typeof(Select));

            algebra = ((IUnaryOperator)algebra).InnerAlgebra;
            Assert.IsInstanceOfType(algebra, typeof(Union));

            IUnion         union = (Union)algebra;
            ISparqlAlgebra lhs   = union.Lhs;

            Assert.IsInstanceOfType(lhs, typeof(Extend));

            ISparqlAlgebra rhs = union.Rhs;

            Assert.IsInstanceOfType(rhs, typeof(Join));
        }
Esempio n. 10
0
        public void SparqlBindScope5()
        {
            String query = @"PREFIX : <http://example.org>
SELECT *
WHERE
{
  GRAPH ?g { :s :p ?o }
  BIND (?g AS ?in)
}";

            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery       q      = parser.ParseFromString(query);

            Console.WriteLine(q.ToString());

            ISparqlAlgebra algebra = q.ToAlgebra();

            Console.WriteLine(algebra.ToString());
            Assert.IsInstanceOfType(algebra, typeof(Select));

            algebra = ((IUnaryOperator)algebra).InnerAlgebra;
            Assert.IsInstanceOfType(algebra, typeof(Extend));
        }
Esempio n. 11
0
        public void FullTextOptimiserComplex5()
        {
            //Actual test case from FTXT-364
            String         query   = @"PREFIX rdf: <" + NamespaceMapper.RDF + @">
PREFIX rdfs: <" + NamespaceMapper.RDFS + @">
PREFIX my: <http://example.org/my#>

SELECT DISTINCT ?result ?isWebSite WHERE {
        _:sparql-autos2 rdf:rest rdf:nil .
        _:sparql-autos1 rdf:rest _:sparql-autos2 .
        _:sparql-autos2 rdf:first ?score .
        _:sparql-autos1 pf:textMatch _:sparql-autos3 .
        _:sparql-autos1 rdf:first ?result .
        BIND(IF (EXISTS { ?result a my:PersonalSite . } , true , false) AS ?isWebSite) .
        _:sparql-autos3 rdf:first 'securite~' .
        _:sparql-autos3 rdf:rest rdf:nil .
       ?result a my:Organization .
       ?result rdfs:label ?label .
    } ORDER BY DESC(?isWebSite) DESC(?score) ASC(?label)";
            SparqlQuery    q       = this.TestOptimisation(query);
            ISparqlAlgebra algebra = q.ToAlgebra();

            Assert.IsFalse(algebra.ToString().Contains("PropertyFunction(Extend("));
        }
Esempio n. 12
0
 /// <summary>
 /// Gets the String representation of the Algebra.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("OrderBy(" + _pattern.ToString() + ")");
 }
Esempio n. 13
0
 /// <summary>
 /// Gets the String representation of the Algebra
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("ExistsJoin(" + _lhs.ToString() + ", " + _rhs.ToString() + ", " + _mustExist + ")");
 }
Esempio n. 14
0
 /// <summary>
 /// Gets the string represenation of the algebra.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("FilteredProduct(" + _lhs.ToString() + ", " + _rhs.ToString() + ", " + _expr.ToString() + ")");
 }
Esempio n. 15
0
 /// <summary>
 /// Gets the String representation of the Algebra.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("Slice(" + _pattern.ToString() + ", LIMIT " + _limit + ", OFFSET " + _offset + ")");
 }
Esempio n. 16
0
 /// <summary>
 /// Gets the String representation of the Algebra.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("Reduced(" + _pattern.ToString() + ")");
 }
Esempio n. 17
0
 /// <summary>
 /// Gets the String representation of the
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("GroupBy(" + _pattern.ToString() + ")");
 }
Esempio n. 18
0
 /// <summary>
 /// Gets the string representation of the algebra.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("PropertyFunction(" + _algebra.ToString() + "," + _function.FunctionUri + ")");
 }
Esempio n. 19
0
 /// <summary>
 /// Gets the String representation of the Join
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("Join(" + _lhs.ToString() + ", " + _rhs.ToString() + ")");
 }
Esempio n. 20
0
 /// <summary>
 /// Gets the String representation of the Algebra.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("LazyUnion(" + _lhs.ToString() + ", " + _rhs.ToString() + ")");
 }
Esempio n. 21
0
 /// <summary>
 /// Gets the String representation of the Algebra.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("Having(" + _pattern.ToString() + ")");
 }
Esempio n. 22
0
 /// <summary>
 /// Gets the String representation of the Algebra
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("Select(" + _pattern.ToString() + ")");
 }
Esempio n. 23
0
 /// <summary>
 /// Gets the String representation of the Algebra.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("Distinct(" + _pattern.ToString() + ")");
 }
Esempio n. 24
0
 /// <summary>
 /// Gets the String representation of the Algebra
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("Graph(" + _graphSpecifier.Value + ", " + _pattern.ToString() + ")");
 }
 /// <summary>
 /// Gets the String representation of the Algebra
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("ParallelUnion(" + _lhs.ToString() + ", " + _rhs.ToString() + ")");
 }