Esempio n. 1
0
        public void SparqlPropertyPathEvaluationDuplicates()
        {
            IGraph g = new Graph();

            g.LoadFromFile("resources\\schema-org.ttl");

            SparqlQueryParser parser    = new SparqlQueryParser();
            SparqlQuery       q         = parser.ParseFromFile("resources\\schema-org.rq");
            SparqlQuery       qDistinct = parser.ParseFromFile("resources\\schema-org.rq");

            qDistinct.QueryType = SparqlQueryType.SelectDistinct;

            InMemoryDataset         dataset   = new InMemoryDataset(g);
            LeviathanQueryProcessor processor = new LeviathanQueryProcessor(dataset);

            SparqlResultSet results = processor.ProcessQuery(q) as SparqlResultSet;

            Assert.NotNull(results);
            Assert.False(results.IsEmpty);
            SparqlResultSet resultsDistinct = processor.ProcessQuery(qDistinct) as SparqlResultSet;

            Assert.NotNull(resultsDistinct);
            Assert.False(resultsDistinct.IsEmpty);

            Assert.Equal(resultsDistinct.Count, results.Count);
        }
Esempio n. 2
0
        public void SparqlFunctionsNow()
        {
            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery       q      = parser.ParseFromFile("resources\\now01.rq");

            Console.WriteLine("ToString Output:");
            Console.WriteLine(q.ToString());
            Console.WriteLine();

            SparqlFormatter formatter = new SparqlFormatter();

            Console.WriteLine("SparqlFormatter Output:");
            Console.WriteLine(formatter.Format(q));

            TripleStore             store     = new TripleStore();
            LeviathanQueryProcessor processor = new LeviathanQueryProcessor(store);
            SparqlResultSet         results   = processor.ProcessQuery(q) as SparqlResultSet;

            if (results != null)
            {
                Assert.IsTrue(results.Result, "Result should be true");
            }
            else
            {
                Assert.Fail("Expected a non-null result");
            }
        }
Esempio n. 3
0
        public void SparqlAnton()
        {
            Graph g = new Graph();

            FileLoader.Load(g, "anton.rdf");

            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery       query  = parser.ParseFromFile("anton.rq");

            Object results = g.ExecuteQuery(query);

            if (results is SparqlResultSet)
            {
                SparqlResultSet rset = (SparqlResultSet)results;
                foreach (SparqlResult r in rset)
                {
                    Console.WriteLine(r);
                }
                Assert.AreEqual(1, rset.Count, "Should be exactly 1 result");
            }
            else
            {
                Assert.Fail("Query should have returned a Result Set");
            }
        }
Esempio n. 4
0
        public void SparqlParsingNestedGraphPatternFirstItem2()
        {
            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery       q      = parser.ParseFromFile("resources\\childgraphpattern2.rq");

            Console.WriteLine(q.ToString());
            Console.WriteLine();
            Console.WriteLine(q.ToAlgebra().ToString());
        }
Esempio n. 5
0
        private static void RunSparqlAnalyzer(Options opts)
        {
            VDS.RDF.Options.AlgebraOptimisation = false;
            var parser = new SparqlQueryParser(SparqlQuerySyntax.Sparql_1_1);
            var query  = opts.Query != null?
                         parser.ParseFromString(opts.Query) :
                             parser.ParseFromFile(opts.File);

            var algebra = query.ToAlgebra();

            Console.WriteLine(query.ToString());
            Console.WriteLine(algebra.ToString());
        }
Esempio n. 6
0
        public void SparqlEvaluationMultipleOptionals2()
        {
            TripleStore store = new TripleStore();

            store.LoadFromFile("resources\\multiple-options.trig");

            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery       query  = parser.ParseFromFile("resources\\multiple-optionals-alternate.rq");

            LeviathanQueryProcessor processor = new LeviathanQueryProcessor(store);
            Object results = processor.ProcessQuery(query);

            if (results is SparqlResultSet)
            {
                TestTools.ShowResults(results);
            }
            else
            {
                Assert.Fail("Expected a SPARQL Result Set");
            }
        }
Esempio n. 7
0
        public void SparqlAnton()
        {
            Graph g = new Graph();

            FileLoader.Load(g, "resources\\anton.rdf");

            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery       query  = parser.ParseFromFile("resources\\anton.rq");

            Object results = g.ExecuteQuery(query);

            Assert.IsAssignableFrom <SparqlResultSet>(results);
            if (results is SparqlResultSet)
            {
                SparqlResultSet rset = (SparqlResultSet)results;
                foreach (SparqlResult r in rset)
                {
                    Console.WriteLine(r);
                }
                Assert.Equal(1, rset.Count);
            }
        }
Esempio n. 8
0
        public void ParsingSuiteRdfA10()
        {
            String[] wantOutput = {  };
            bool     outputAll  = false;

            String[] skipTests =
            {
                "0002.xhtml",
                "0003.xhtml",
                "0004.xhtml",
                "0005.xhtml",
                "0016.xhtml",
                "0022.xhtml",
                "0024.xhtml",
                "0028.xhtml",
                "0043.xhtml",
                "0044.xhtml",
                "0045.xhtml",
                "0095.xhtml",
                "0096.xhtml",
                "0097.xhtml",
                "0098.xhtml",
                "0122.xhtml",
                "0123.xhtml",
                "0124.xhtml",
                "0125.xhtml",
                "0126.xhtml"
            };

            String[] skipCheck =
            {
                "0011.xhtml",
                "0092.xhtml",
                "0094.xhtml",
                "0100.xhtml",
                "0101.xhtml",
                "0102.xhtml",
                "0103.xhtml"
            };

            String[] falseTests =
            {
                "0042.xhtml",
                "0086.xhtml",
                "0095.xhtml",
                "0096.xhtml",
                "0097.xhtml",
                "0107.xhtml",
                "0116.xhtml",
                "0122.xhtml",
                "0125.xhtml"
            };

            try
            {
                int        testsPassed = 0;
                int        testsFailed = 0;
                String[]   files       = Directory.GetFiles("resources\\rdfa\\");
                RdfAParser parser      = new RdfAParser(RdfASyntax.AutoDetectLegacy);
                //XHtmlPlusRdfAParser parser = new XHtmlPlusRdfAParser();
                parser.Warning += parser_Warning;
                SparqlQueryParser queryparser = new SparqlQueryParser();
                bool      passed, passDesired;
                Graph     g = new Graph();
                Stopwatch timer = new Stopwatch();
                long      totalTime    = 0;
                long      totalTriples = 0;

                foreach (String file in files)
                {
                    timer.Reset();

                    if (skipTests.Contains(Path.GetFileName(file)))
                    {
                        _testOutputHelper.WriteLine("## Skipping Test of File " + Path.GetFileName(file));
                        _testOutputHelper.WriteLine("");
                        continue;
                    }

                    if (Path.GetExtension(file) != ".html" && Path.GetExtension(file) != ".xhtml")
                    {
                        continue;
                    }

                    _testOutputHelper.WriteLine("## Testing File " + Path.GetFileName(file));
                    _testOutputHelper.WriteLine("# Test Started at " + DateTime.Now);

                    passed      = false;
                    passDesired = true;

                    try
                    {
                        g = new Graph
                        {
                            BaseUri = new Uri("http://www.w3.org/2006/07/SWD/RDFa/testsuite/xhtml1-testcases/" +
                                              Path.GetFileName(file))
                        };
                        if (Path.GetFileNameWithoutExtension(file).StartsWith("bad"))
                        {
                            passDesired = false;
                            _testOutputHelper.WriteLine("# Desired Result = Parsing Failed");
                        }
                        else
                        {
                            _testOutputHelper.WriteLine("# Desired Result = Parses OK");
                        }

                        timer.Start();
                        parser.Load(g, file);
                        timer.Stop();

                        _testOutputHelper.WriteLine("Parsing took " + timer.ElapsedMilliseconds + "ms");

                        passed = true;
                        _testOutputHelper.WriteLine("Parsed OK");

                        if (outputAll || wantOutput.Contains(Path.GetFileName(file)))
                        {
                            NTriplesWriter writer = new NTriplesWriter();
                            writer.Save(g, "rdfa_tests\\" + Path.GetFileNameWithoutExtension(file) + ".out");
                        }
                    }
                    catch (IOException ioEx)
                    {
                        reportError("IO Exception", ioEx);
                    }
                    catch (RdfParseException parseEx)
                    {
                        reportError("Parsing Exception", parseEx);
                    }
                    catch (RdfException rdfEx)
                    {
                        reportError("RDF Exception", rdfEx);
                    }
                    catch (Exception ex)
                    {
                        reportError("Other Exception", ex);
                    }
                    finally
                    {
                        timer.Stop();

                        //Write the Triples to the Output
                        foreach (Triple t in g.Triples)
                        {
                            _testOutputHelper.WriteLine(t.ToString());
                        }

                        //Now we run the Test SPARQL (if present)
                        if (File.Exists("rdfa_tests/" + Path.GetFileNameWithoutExtension(file) + ".sparql"))
                        {
                            if (skipCheck.Contains(Path.GetFileName(file)))
                            {
                                _testOutputHelper.WriteLine("## Skipping Check of File " + Path.GetFileName(file));
                                _testOutputHelper.WriteLine("");
                            }
                            else
                            {
                                try
                                {
                                    SparqlQuery q       = queryparser.ParseFromFile("rdfa_tests/" + Path.GetFileNameWithoutExtension(file) + ".sparql");
                                    Object      results = g.ExecuteQuery(q);
                                    if (results is SparqlResultSet)
                                    {
                                        //The Result is the result of the ASK Query
                                        if (falseTests.Contains(Path.GetFileName(file)))
                                        {
                                            passed = !((SparqlResultSet)results).Result;
                                        }
                                        else
                                        {
                                            passed = ((SparqlResultSet)results).Result;
                                        }
                                    }
                                }
                                catch
                                {
                                    passed = false;
                                }
                            }
                        }

                        if (passed && passDesired)
                        {
                            //Passed and we wanted to Pass
                            testsPassed++;
                            _testOutputHelper.WriteLine("# Result = Test Passed");
                            totalTime    += timer.ElapsedMilliseconds;
                            totalTriples += g.Triples.Count;
                        }
                        else if (!passed && passDesired)
                        {
                            //Failed when we should have Passed
                            testsFailed++;
                            _testOutputHelper.WriteLine("# Result = Test Failed");
                        }
                        else if (passed && !passDesired)
                        {
                            //Passed when we should have Failed
                            testsFailed++;
                            _testOutputHelper.WriteLine("# Result = Test Failed");
                        }
                        else
                        {
                            //Failed and we wanted to Fail
                            testsPassed++;
                            _testOutputHelper.WriteLine("# Result = Test Passed");
                        }

                        _testOutputHelper.WriteLine("# Triples Generated = " + g.Triples.Count());
                        _testOutputHelper.WriteLine("# Test Ended at " + DateTime.Now);
                    }

                    _testOutputHelper.WriteLine("");
                }

                _testOutputHelper.WriteLine(testsPassed + " Tests Passed");
                _testOutputHelper.WriteLine(testsFailed + " Tests Failed");
                _testOutputHelper.WriteLine("");
                _testOutputHelper.WriteLine($"Total Parsing Time was {totalTime} ms");
                if (totalTime > 1000)
                {
                    _testOutputHelper.WriteLine(" (" + totalTime / 1000d + " seconds)");
                }
                _testOutputHelper.WriteLine("Average Parsing Speed was " + totalTriples / (totalTime / 1000d) + " triples/second");

                if (testsFailed > 0)
                {
                    Assert.True(false, testsFailed + " Tests Failed");
                }
            }
            catch (Exception ex)
            {
                reportError("Other Exception", ex);
                throw;
            }
        }
        public SparqlResultSet QueryFromFile(string filePath)
        {
            SparqlQuery query = _sqlQueryParser.ParseFromFile(filePath);

            return((SparqlResultSet)_processor.ProcessQuery(query));
        }
Esempio n. 10
0
        static void DoQuery(Dictionary <String, String> arguments)
        {
            SparqlRemoteEndpoint endpoint;
            bool verbose = arguments.ContainsKey("verbose") || arguments.ContainsKey("v");

            if (verbose)
            {
                Options.HttpDebugging = true;
            }

            //First get the Server to which we are going to connect
            try
            {
                if (arguments.ContainsKey("server") && !arguments["server"].Equals(String.Empty))
                {
                    endpoint = new SparqlRemoteEndpoint(new Uri(arguments["server"]));
                }
                else if (arguments.ContainsKey("service") && !arguments["service"].Equals(String.Empty))
                {
                    endpoint = new SparqlRemoteEndpoint(new Uri(arguments["service"]));
                }
                else
                {
                    Console.Error.WriteLine("soh: Error: Required --server/--service argument not present");
                    Environment.Exit(-1);
                    return;
                }
            }
            catch (UriFormatException uriEx)
            {
                Console.Error.WriteLine("soh: Error: Malformed SPARQL Endpoint URI");
                Console.Error.WriteLine(uriEx.Message);
                Environment.Exit(-1);
                return;
            }
            if (verbose)
            {
                Console.Error.WriteLine("soh: SPARQL Endpoint for URI " + endpoint.Uri + " created OK");
            }

            //Then decide where to get the query to execute from
            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery       query;

            try
            {
                if (arguments.ContainsKey("query") && !arguments["query"].Equals(String.Empty))
                {
                    query = parser.ParseFromFile(arguments["query"]);
                }
                else if (arguments.ContainsKey("file") && !arguments["file"].Equals(String.Empty))
                {
                    query = parser.ParseFromFile(arguments["file"]);
                }
                else if (arguments.ContainsKey("$1") && !arguments["$1"].Equals(String.Empty))
                {
                    query = parser.ParseFromString(arguments["$1"]);
                }
                else
                {
                    Console.Error.WriteLine("soh: Error: Required SPARQL Query not found - may be specified as --file/--query FILE or as final argument");
                    Environment.Exit(-1);
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("soh: Error: Error Parsing SPARQL Query");
                Console.Error.WriteLine(ex.Message);
                Environment.Exit(-1);
                return;
            }

            if (verbose)
            {
                Console.Error.WriteLine("soh: Parsed Query OK");
                Console.Error.WriteLine("soh: dotNetRDF's interpretation of the Query:");
                SparqlFormatter formatter = new SparqlFormatter();
                Console.Error.WriteLine(formatter.Format(query));
                Console.Error.WriteLine("soh: Submitting Query");
            }

            try
            {
                using (HttpWebResponse response = endpoint.QueryRaw(query.ToString()))
                {
                    MimeTypeDefinition definition = MimeTypesHelper.GetDefinitions(response.ContentType).FirstOrDefault();
                    Encoding           enc;
                    if (definition != null)
                    {
                        enc = definition.Encoding;
                    }
                    else if (!response.ContentEncoding.Equals(String.Empty))
                    {
                        enc = Encoding.GetEncoding(response.ContentEncoding);
                    }
                    else if (response.ContentType.Contains("charset="))
                    {
                        enc = Encoding.GetEncoding(response.ContentType.Substring(response.ContentType.IndexOf('=') + 1));
                    }
                    else
                    {
                        enc = Console.OutputEncoding;
                    }

                    if (verbose)
                    {
                        Console.Error.WriteLine("soh: Got Response from SPARQL Endpoint OK");
                        Console.Error.WriteLine("soh: Content-Type: " + response.ContentType);
                        Console.Error.WriteLine("soh: Content-Encoding: " + enc.WebName);
                    }

                    String requestedType = arguments.ContainsKey("accept") ? arguments["accept"] : null;

                    if (requestedType == null || response.ContentType.StartsWith(requestedType, StringComparison.OrdinalIgnoreCase))
                    {
                        //If no --accept (OR matches servers content type) then just return whatever the server has given us
                        using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                        {
                            using (StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(), enc))
                            {
                                while (!reader.EndOfStream)
                                {
                                    writer.WriteLine(reader.ReadLine());
                                }
                                writer.Close();
                            }
                            reader.Close();
                        }
                    }
                    else
                    {
                        if (verbose)
                        {
                            Console.Error.WriteLine("soh: Warning: Retrieved Content Type '" + response.ContentType + "' does not match your desired Content Type '" + requestedType + "' so dotNetRDF will not attempt to transcode the response into your desired format");
                        }

                        //Requested Type Doesn't match servers returned type so parse then serialize
                        MimeTypeDefinition outputDefinition;
                        try
                        {
                            ISparqlResultsReader sparqlParser = MimeTypesHelper.GetSparqlParser(response.ContentType);
                            SparqlResultSet      results      = new SparqlResultSet();
                            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                            {
                                sparqlParser.Load(results, reader);
                                reader.Close();
                            }

                            outputDefinition = MimeTypesHelper.GetDefinitions(requestedType).FirstOrDefault(d => d.CanWriteSparqlResults || d.CanWriteRdf);
                            if (outputDefinition == null)
                            {
                                throw new RdfWriterSelectionException("No MIME Type Definition for the MIME Type '" + requestedType + "' was found that can write SPARQL Results/RDF");
                            }
                            ISparqlResultsWriter writer = outputDefinition.GetSparqlResultsWriter();
                            Console.OutputEncoding = outputDefinition.Encoding;
                            writer.Save(results, new StreamWriter(Console.OpenStandardOutput(), outputDefinition.Encoding));
                        }
                        catch (RdfParserSelectionException)
                        {
                            try
                            {
                                IRdfReader rdfParser = MimeTypesHelper.GetParser(response.ContentType);
                                Graph      g         = new Graph();
                                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                                {
                                    rdfParser.Load(g, reader);
                                    reader.Close();
                                }

                                outputDefinition = MimeTypesHelper.GetDefinitions(requestedType).FirstOrDefault(d => d.CanWriteRdf);
                                if (outputDefinition == null)
                                {
                                    throw new RdfWriterSelectionException("No MIME Type Definition for the MIME Type '" + requestedType + "' was found that can write RDF");
                                }
                                IRdfWriter writer = outputDefinition.GetRdfWriter();
                                Console.OutputEncoding = outputDefinition.Encoding;
                                writer.Save(g, new StreamWriter(Console.OpenStandardOutput(), outputDefinition.Encoding));
                            }
                            catch (Exception ex)
                            {
                                //For any other exception show a warning
                                Console.Error.WriteLine("soh: Warning: You wanted results in the format '" + requestedType + "' but the server returned '" + response.ContentType + "' and dotNetRDF was unable to translate the response into your desired format.");
                                Console.Error.WriteLine(ex.Message);
                            }
                        }
                        catch (Exception ex)
                        {
                            //For any other exception show a warning
                            Console.Error.WriteLine("soh: Warning: You wanted results in the format '" + requestedType + "' but the server returned '" + response.ContentType + "' and dotNetRDF was unable to translate the response into your desired format.");
                            Console.Error.WriteLine(ex.Message);
                        }
                    }


                    response.Close();
                }

                if (verbose)
                {
                    Console.Error.WriteLine("soh: Query Completed OK");
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("soh: Error: Error while making the SPARQL Query");
                Console.Error.WriteLine(ex.Message);
                Environment.Exit(-1);
                return;
            }
        }
        private int ProcessEvaluationTest(SparqlQueryParser parser, Triple commentDef, String queryFile, String dataFile, List <String> dataFiles, String resultFile)
        {
            Console.WriteLine("# Processing Evaluation Test " + Path.GetFileName(queryFile));

            if (commentDef != null)
            {
                Console.WriteLine(commentDef.Object.ToString());
                Console.WriteLine();
            }

            if (dataFiles.Contains(dataFile))
            {
                dataFiles.Remove(dataFile);
            }
            if (queryFile.StartsWith("file:///"))
            {
                queryFile = queryFile.Substring(8);
            }
            if (dataFile != null && dataFile.StartsWith("file:///"))
            {
                dataFile = dataFile.Substring(8);
            }
            if (resultFile.StartsWith("file:///"))
            {
                resultFile = resultFile.Substring(8);
            }

            Console.WriteLine("Query File is " + queryFile);
            if (evaluationTestOverride.Any(x => queryFile.EndsWith(x)))
            {
                Console.WriteLine();
                Console.WriteLine("# Test Result = Manually overridden to Pass (Test Passed)");
                testsPassed++;
                testsEvaluationPassed++;
                return(1);
            }
            if (dataFile != null)
            {
                Console.WriteLine("Default Graph File is " + dataFile);
            }
            foreach (String file in dataFiles)
            {
                Console.WriteLine("Uses Named Graph File " + file);
            }
            Console.WriteLine("Expected Result File is " + resultFile);
            Console.WriteLine();

            SparqlQuery query;

            try
            {
                query = parser.ParseFromFile(queryFile);

                Console.WriteLine(query.ToString());
                Console.WriteLine();
                Console.WriteLine("Formatted with SparqlFormatter");
                SparqlFormatter formatter = new SparqlFormatter(query.NamespaceMap);
                Console.WriteLine(formatter.Format(query));
                Console.WriteLine();

                try
                {
                    Console.WriteLine(query.ToAlgebra().ToString());
                    Console.WriteLine();
                }
                catch
                {
                    //Do Nothing
                }
            }
            catch (RdfParseException parseEx)
            {
                this.ReportError("Query Parser Error", parseEx);
                testsFailed++;
                testsEvaluationFailed++;
                Console.WriteLine("# Test Result = Unable to parse query (Test Failed)");
                return(-1);
            }

            IInMemoryQueryableStore store;

            if (dataFile != null)
            {
                store = new TripleStore();
            }
            else
            {
                store = new WebDemandTripleStore();
            }

            //Load Default Graph
            Graph defaultGraph = new Graph();

            try
            {
                if (dataFile != null)
                {
                    FileLoader.Load(defaultGraph, dataFile);
                }
                store.Add(defaultGraph);
            }
            catch (RdfParseException parseEx)
            {
                this.ReportError("Parser Error", parseEx);
                testsFailed++;
                testsEvaluationFailed++;
                Console.WriteLine("# Test Result = Unable to parse Default Graph (Test Failed)");
                return(-1);
            }

            //Load Named Graphs
            try
            {
                foreach (String graphFile in dataFiles)
                {
                    Graph namedGraph = new Graph();
                    if (graphFile.StartsWith("file:///"))
                    {
                        FileLoader.Load(namedGraph, graphFile.Substring(8));
                    }
                    else
                    {
                        FileLoader.Load(namedGraph, graphFile);
                    }
                    store.Add(namedGraph);
                }
            }
            catch (RdfParseException parseEx)
            {
                this.ReportError("Parser Error", parseEx);
                testsFailed++;
                testsEvaluationFailed++;
                Console.WriteLine("# Test Result - Unable to parse Named Graph (Test Failed)");
                return(-1);
            }

            //Create a Dataset and then Set Graphs
            //ISparqlDataset dataset = new InMemoryQuadDataset(store);
            ISparqlDataset dataset = new InMemoryDataset(store);

            if (!query.DefaultGraphs.Any())
            {
                query.AddDefaultGraph(defaultGraph.BaseUri);
            }
            if (!query.NamedGraphs.Any())
            {
                foreach (String namedGraphUri in dataFiles)
                {
                    query.AddNamedGraph(new Uri(namedGraphUri));
                }
            }

            //Try and get the result
            Object results = null;

            try
            {
                LeviathanQueryProcessor processor = new LeviathanQueryProcessor(dataset);
                results = processor.ProcessQuery(query);
            }
            catch (RdfQueryException queryEx)
            {
                this.ReportError("Query Error", queryEx);
                testsFailed++;
                testsEvaluationFailed++;
                Console.WriteLine("# Test Result - Query execution failed (Test Failed)");
                return(-1);
            }
            catch (Exception ex)
            {
                this.ReportError("Other Error", ex);
                testsFailed++;
                testsEvaluationFailed++;
                Console.WriteLine("# Test Result - Query failed (Test Failed)");
                return(-1);
            }

            if (results == null)
            {
                testsFailed++;
                testsEvaluationFailed++;
                Console.WriteLine("# Test Result - No result was returned from the Query (Test Failed)");
                return(-1);
            }

            //Load in the expected results
            if (results is SparqlResultSet)
            {
                //Save our Results so we can manually compare as needed
                SparqlResultSet ourResults = (SparqlResultSet)results;
                SparqlXmlWriter writer     = new SparqlXmlWriter();
                writer.Save(ourResults, resultFile + ".out");
                SparqlResultSet expectedResults = new SparqlResultSet();

                if (resultFile.EndsWith(".srx"))
                {
                    try
                    {
                        SparqlXmlParser resultSetParser = new SparqlXmlParser();
                        resultSetParser.Load(expectedResults, resultFile);
                    }
                    catch (RdfParseException parseEx)
                    {
                        this.ReportError("Result Set Parser Error", parseEx);
                        testsIndeterminate++;
                        testsEvaluationIndeterminate++;
                        Console.WriteLine("# Test Result - Error loading expected Result Set (Test Indeterminate)");
                        return(0);
                    }
                }
                else if (resultFile.EndsWith(".ttl") || resultFile.EndsWith(".rdf"))
                {
                    try
                    {
                        SparqlRdfParser resultSetParser = new SparqlRdfParser();
                        resultSetParser.Load(expectedResults, resultFile);
                    }
                    catch (RdfParseException parseEx)
                    {
                        this.ReportError("Result Set Parser Error", parseEx);
                        testsIndeterminate++;
                        testsEvaluationIndeterminate++;
                        Console.WriteLine("# Test Result - Error loading expected Result Set (Test Indeterminate)");
                        return(0);
                    }
                }
                else
                {
                    testsIndeterminate++;
                    testsEvaluationIndeterminate++;
                    Console.WriteLine("# Test Result - Unable to load the expected Result Set (Test Indeterminate)");
                    return(0);
                }

                try
                {
                    ourResults.Trim();
                    expectedResults.Trim();
                    if (ourResults.Equals(expectedResults))
                    {
                        testsPassed++;
                        testsEvaluationPassed++;
                        Console.WriteLine("# Test Result - Result Set as expected (Test Passed)");
                        return(1);
                    }
                    else
                    {
                        Console.WriteLine("Final Query");
                        Console.WriteLine(query.ToString());
                        Console.WriteLine();
                        this.ShowTestData(store);
                        this.ShowResultSets(ourResults, expectedResults);
                        testsFailed++;
                        testsEvaluationFailed++;
                        Console.WriteLine("# Test Result - Result Set not as expected (Test Failed)");
                        return(-1);
                    }
                }
                catch (NotImplementedException)
                {
                    this.ShowResultSets(ourResults, expectedResults);
                    testsIndeterminate++;
                    testsEvaluationIndeterminate++;
                    Console.WriteLine("# Test Result - Unable to establish if Result Set was as expected (Test Indeterminate)");
                    return(0);
                }
            }
            else if (results is Graph)
            {
                if (resultFile.EndsWith(".ttl"))
                {
                    //Save our Results so we can manually compare as needed
                    Graph ourResults = (Graph)results;
                    CompressingTurtleWriter writer = new CompressingTurtleWriter();
                    writer.Save(ourResults, resultFile + ".out");

                    try
                    {
                        Graph        expectedResults = new Graph();
                        TurtleParser ttlparser       = new TurtleParser();
                        ttlparser.Load(expectedResults, resultFile);

                        try
                        {
                            if (ourResults.Equals(expectedResults))
                            {
                                testsPassed++;
                                testsEvaluationPassed++;
                                Console.WriteLine("# Test Result - Graph as expected (Test Passed)");
                                return(1);
                            }
                            else
                            {
                                this.ShowTestData(store);
                                this.ShowGraphs(ourResults, expectedResults);
                                testsFailed++;
                                testsEvaluationFailed++;
                                Console.WriteLine("# Test Result - Graph not as expected (Test Failed)");
                                return(-1);
                            }
                        }
                        catch (NotImplementedException)
                        {
                            this.ShowGraphs(ourResults, expectedResults);
                            testsIndeterminate++;
                            testsEvaluationIndeterminate++;
                            Console.WriteLine("# Test Result - Unable to establish if Graph was as expected (Test Indeterminate)");
                            return(0);
                        }
                    }
                    catch (RdfParseException parseEx)
                    {
                        this.ReportError("Graph Parser Error", parseEx);
                        testsIndeterminate++;
                        testsEvaluationIndeterminate++;
                        Console.WriteLine("# Test Result - Error loading expected Graph (Test Indeterminate)");
                        return(0);
                    }
                }
                else
                {
                    testsIndeterminate++;
                    testsEvaluationIndeterminate++;
                    Console.WriteLine("# Test Result - Unable to load expected Graph (Test Indeterminate)");
                    return(0);
                }
            }
            else
            {
                testsFailed++;
                testsEvaluationFailed++;
                Console.WriteLine("# Test Result - Didn't produce a Graph as expected (Test Failed)");
                return(-1);
            }
        }
        private void ProcessSyntaxTest(SparqlQueryParser parser, String queryFile, bool shouldParse)
        {
            if (queryFile.StartsWith("file:///"))
            {
                queryFile = queryFile.Substring(8);
            }

            bool error = false;

            try
            {
                Console.WriteLine("# Processing Syntax Test " + Path.GetFileName(queryFile));
                Console.Write("# Result Expected = ");
                if (shouldParse)
                {
                    Console.WriteLine("Parses OK");
                }
                else
                {
                    Console.WriteLine("Parsing Fails");
                }

                SparqlQuery q = parser.ParseFromFile(queryFile);

                Console.WriteLine(q.ToString());
                Console.WriteLine();

                Console.WriteLine("Formatted with SparqlFormatter");
                SparqlFormatter formatter = new SparqlFormatter(q.NamespaceMap);
                Console.WriteLine(formatter.Format(q));
                Console.WriteLine();
            }
            catch (RdfParseException parseEx)
            {
                this.ReportError("Parser Error", parseEx);
                error = true;
            }
            catch (Exception ex)
            {
                this.ReportError("Other Error", ex);
                error = true;
            }
            finally
            {
                Console.Write("# Result = ");
                if (error)
                {
                    if (shouldParse)
                    {
                        Console.WriteLine(" Parsing Failed when should have parsed (Test Failed)");
                        testsFailed++;
                        testsSyntaxFailed++;
                    }
                    else
                    {
                        Console.WriteLine(" Parsing Failed as expected (Test Passed)");
                        testsPassed++;
                        testsSyntaxPassed++;
                    }
                }
                else
                {
                    if (shouldParse)
                    {
                        Console.WriteLine(" Parsed OK as expected (Test Passed)");
                        testsPassed++;
                        testsSyntaxPassed++;
                    }
                    else
                    {
                        Console.WriteLine(" Parsed OK when should have failed (Test Failed)");
                        testsFailed++;
                        testsSyntaxFailed++;
                    }
                }
                Console.WriteLine(new String('-', 150));
            }
        }