Ejemplo n.º 1
0
        public void SparqlJsonResultSet()
        {
            Console.WriteLine("Tests that JSON Parser parses language specifiers correctly");

            String query = "PREFIX rdfs: <" + NamespaceMapper.RDFS + ">\nSELECT DISTINCT ?comment WHERE {?s rdfs:comment ?comment}";

            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

            FileLoader.Load(g, "json.owl");
            store.Add(g);

            Object results = store.ExecuteQuery(query);

            if (results is SparqlResultSet)
            {
                SparqlResultSet rset = (SparqlResultSet)results;

                //Serialize to both XML and JSON Results format
                SparqlXmlWriter xmlwriter = new SparqlXmlWriter();
                xmlwriter.Save(rset, "results.xml");
                SparqlJsonWriter jsonwriter = new SparqlJsonWriter();
                jsonwriter.Save(rset, "results.json");

                //Read both back in
                SparqlXmlParser xmlparser = new SparqlXmlParser();
                SparqlResultSet r1        = new SparqlResultSet();
                xmlparser.Load(r1, "results.xml");
                Console.WriteLine("Result Set after XML serialization and reparsing contains:");
                foreach (SparqlResult r in r1)
                {
                    Console.WriteLine(r.ToString());
                }
                Console.WriteLine();

                SparqlJsonParser jsonparser = new SparqlJsonParser();
                SparqlResultSet  r2         = new SparqlResultSet();
                jsonparser.Load(r2, "results.json");
                Console.WriteLine("Result Set after JSON serialization and reparsing contains:");
                foreach (SparqlResult r in r2)
                {
                    Console.WriteLine(r.ToString());
                }
                Console.WriteLine();

                Assert.AreEqual(r1, r2, "Results Sets should be equal");

                Console.WriteLine("Result Sets were equal as expected");
            }
            else
            {
                Assert.Fail("Query did not return a Result Set");
            }
        }
Ejemplo n.º 2
0
        public void SparqlBNodeIDsInResults()
        {
            SparqlXmlParser xmlparser = new SparqlXmlParser();
            SparqlResultSet results   = new SparqlResultSet();

            xmlparser.Load(results, "resources\\bnodes.srx");

            TestTools.ShowResults(results);
            Assert.Equal(results.Results.Distinct().Count(), 1);

            SparqlJsonParser jsonparser = new SparqlJsonParser();

            results = new SparqlResultSet();
            jsonparser.Load(results, "resources\\bnodes.json");

            TestTools.ShowResults(results);
            Assert.Equal(results.Results.Distinct().Count(), 1);
        }
Ejemplo n.º 3
0
        public void SparqlBNodeIDsInResults()
        {
            SparqlXmlParser xmlparser = new SparqlXmlParser();
            SparqlResultSet results   = new SparqlResultSet();

            xmlparser.Load(results, "bnodes.srx");

            TestTools.ShowResults(results);
            Assert.AreEqual(results.Results.Distinct().Count(), 1, "All Results should be the same as they should all generate same BNode");

            SparqlJsonParser jsonparser = new SparqlJsonParser();

            results = new SparqlResultSet();
            jsonparser.Load(results, "bnodes.json");

            TestTools.ShowResults(results);
            Assert.AreEqual(results.Results.Distinct().Count(), 1, "All Results should be the same as they should all generate same BNode");
        }
        public void ParsingResultSetHandlerImplicitSparqlJson()
        {
            this.EnsureTestData("test.srj");

            SparqlJsonParser parser  = new SparqlJsonParser();
            SparqlResultSet  results = new SparqlResultSet();

            parser.Load(results, "test.srj");

            NTriplesFormatter formatter = new NTriplesFormatter();

            foreach (SparqlResult r in results)
            {
                Console.WriteLine(r.ToString(formatter));
            }

            Assert.False(results.IsEmpty, "Result Set should not be empty");
            Assert.Equal(SparqlResultsType.VariableBindings, results.ResultsType);
        }