예제 #1
0
        public void StorageStardogSaveToNamedGraphOverwrite()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            Graph g = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = new Uri("http://example.org/namedGraph");
            stardog.SaveGraph(g);

            Graph h = new Graph();

            stardog.LoadGraph(h, new Uri("http://example.org/namedGraph"));

            Assert.Equal(g, h);

            Graph i = new Graph();

            i.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.LeviathanFunctionLibrary.ttl");
            i.BaseUri = new Uri("http://example.org/namedGraph");
            stardog.SaveGraph(i);

            Graph j = new Graph();

            stardog.LoadGraph(j, "http://example.org/namedGraph");

            Assert.NotEqual(g, j);
            Assert.Equal(i, j);
        }
예제 #2
0
        public void StorageStardogSaveToNamedGraphOverwrite()
        {
            try
            {
                //Options.UseBomForUtf8 = false;
                Options.HttpDebugging = true;

                StardogConnector stardog = StardogTests.GetConnection();;
                Graph            g       = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                g.BaseUri = new Uri("http://example.org/namedGraph");
                stardog.SaveGraph(g);

                Graph h = new Graph();
                stardog.LoadGraph(h, new Uri("http://example.org/namedGraph"));

                Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph");

                Graph i = new Graph();
                i.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.LeviathanFunctionLibrary.ttl");
                i.BaseUri = new Uri("http://example.org/namedGraph");
                stardog.SaveGraph(i);

                Graph j = new Graph();
                stardog.LoadGraph(j, "http://example.org/namedGraph");

                Assert.AreNotEqual(g, j, "Retrieved Graph should not be equal to overwritten Graph");
                Assert.AreEqual(i, j, "Retrieved Graph should be equal to Saved Graph");
            }
            finally
            {
                Options.HttpDebugging = false;
                //Options.UseBomForUtf8 = true;
            }
        }
예제 #3
0
        public void StorageStardogSparqlUpdate3()
        {
            StardogConnector stardog = StardogTests.GetConnection();
            IGraph           g;

            Console.WriteLine("Dropping graph");
            stardog.Update("DROP SILENT GRAPH <http://example.org/stardog/update/3>");
            Console.WriteLine("Dropped graph");
            Thread.Sleep(2500);
            g = new Graph();
            stardog.LoadGraph(g, "http://example.org/stardog/update/3");
            Assert.True(g.IsEmpty, "Graph should be empty after DROP command");

            Console.WriteLine("Inserting data");
            IGraph newData = new Graph();

            newData.BaseUri = new Uri("http://example.org/stardog/update/3");
            newData.Assert(newData.CreateUriNode(new Uri("http://x")), newData.CreateUriNode(new Uri("http://y")),
                           newData.CreateUriNode(new Uri("http://z")));
            stardog.SaveGraph(newData);
            Console.WriteLine("Inserted data");
            g = new Graph();
            stardog.LoadGraph(g, "http://example.org/stardog/update/3");
            Assert.False(g.IsEmpty, "Graph should not be empty");
            Assert.Equal(1, g.Triples.Count);
        }
예제 #4
0
        public void StorageStardogReasoningByQuery2()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            if (stardog.Reasoning == StardogReasoningMode.DatabaseControlled)
            {
                throw new SkipTestException(
                          "Version of Stardog being tested does not support configuring reasoning mode at connection level");
            }

            Graph g = new Graph();

            g.LoadFromFile("resources\\stardog-reasoning-test.rdf");
            g.BaseUri = new Uri("http://www.reasoningtest.com/");
            stardog.SaveGraph(g);

            String query = "Select ?building where { ?building <http://www.reasoningtest.com#hasLocation> ?room.}";

            Console.WriteLine(query);
            Console.WriteLine();

            SparqlResultSet resultsWithNoReasoning = stardog.Query(query, false) as SparqlResultSet;

            Assert.Null(resultsWithNoReasoning);
            if (resultsWithNoReasoning != null)
            {
                Console.WriteLine("Results With No Reasoning");
                Assert.True(false, "There should not be any reasoning results !");
            }
            else
            {
                Assert.True(true, "No SPARQL Results returned ! Success.");
            }
        }
예제 #5
0
        public void StorageStardogLoadNamedGraph()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            // Ensure graph exists
            Graph g = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = new Uri("http://example.org/graph");
            stardog.SaveGraph(g);

            // Load it back from the store
            Graph h = new Graph();

            stardog.LoadGraph(h, new Uri("http://example.org/graph"));

            NTriplesFormatter formatter = new NTriplesFormatter();

            foreach (Triple t in h.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }

            Assert.False(h.IsEmpty);
            Assert.Equal(g, h);
        }
예제 #6
0
        public void StorageStardogReasoningByQuery1()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            Skip.If(stardog.Reasoning == StardogReasoningMode.DatabaseControlled,
                    "Version of Stardog being tested does not support configuring reasoning mode at connection level");

            Graph g = new Graph();

            g.LoadFromFile("resources\\stardog-reasoning-test.rdf");
            g.BaseUri = new Uri("http://www.reasoningtest.com/");
            stardog.SaveGraph(g);

            String query = "Select ?building where { ?building <http://www.reasoningtest.com#hasLocation> ?room.}";

            Console.WriteLine(query);
            Console.WriteLine();

            SparqlResultSet resultsWithReasoning = stardog.Query(query, true) as SparqlResultSet;

            Assert.NotNull(resultsWithReasoning);
            if (resultsWithReasoning != null)
            {
                Console.WriteLine("Results With Reasoning");
                TestTools.ShowResults(resultsWithReasoning);
                Assert.True(true, "Reasoning By Query OK !");
            }
            else
            {
                Assert.True(false, "Did not get a SPARQL Result Set as expected");
            }
        }
예제 #7
0
        public void StorageStardogDeleteNamedGraph()
        {
            try
            {
                //Options.UseBomForUtf8 = false;

                StardogConnector stardog = StardogTests.GetConnection();;
                Graph            g       = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                g.BaseUri = new Uri("http://example.org/tempGraph");
                stardog.SaveGraph(g);

                Graph h = new Graph();
                stardog.LoadGraph(h, new Uri("http://example.org/tempGraph"));

                if (g.Triples.Count == h.Triples.Count)
                {
                    Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph");
                }
                else
                {
                    Assert.IsTrue(h.HasSubGraph(g), "Retrieved Graph should have the Saved Graph as a subgraph");
                }

                stardog.DeleteGraph("http://example.org/tempGraph");
                Graph i = new Graph();
                stardog.LoadGraph(i, new Uri("http://example.org/tempGraph"));

                Assert.IsTrue(i.IsEmpty, "Retrieved Graph should be empty since it has been deleted");
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
            }
        }
예제 #8
0
        public void StorageStardogUpdateNamedGraphRemoveTriples()
        {
            try
            {
                //Options.UseBomForUtf8 = false;

                StardogConnector stardog = StardogTests.GetConnection();;
                Graph            g       = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                g.BaseUri = new Uri("http://example.org/graph");
                stardog.SaveGraph(g);

                INode rdfType = g.CreateUriNode(new Uri(VDS.RDF.Parsing.RdfSpecsHelper.RdfType));

                stardog.UpdateGraph(g.BaseUri, null, g.GetTriplesWithPredicate(rdfType));
                g.Retract(g.GetTriplesWithPredicate(rdfType).ToList());

                Graph h = new Graph();
                stardog.LoadGraph(h, new Uri("http://example.org/graph"));

                if (g.Triples.Count == h.Triples.Count)
                {
                    Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph");
                }
                else
                {
                    Assert.IsTrue(h.HasSubGraph(g), "Retrieved Graph should have the Saved Graph as a subgraph");
                }
                Assert.IsFalse(h.GetTriplesWithPredicate(rdfType).Any(), "Retrieved Graph should not contain any rdf:type Triples");
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
            }
        }
예제 #9
0
        public void StorageStardogSaveToDefaultGraph()
        {
            try
            {
                //Options.UseBomForUtf8 = false;

                StardogConnector stardog = StardogTests.GetConnection();;
                Graph            g       = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                g.BaseUri = null;
                stardog.SaveGraph(g);

                Graph h = new Graph();
                stardog.LoadGraph(h, (Uri)null);
                Console.WriteLine("Retrieved " + h.Triples.Count + " Triple(s) from Stardog");

                if (g.Triples.Count == h.Triples.Count)
                {
                    Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph");
                }
                else
                {
                    Assert.IsTrue(h.HasSubGraph(g), "Retrieved Graph should have the Saved Graph as a subgraph");
                }
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
            }
        }
예제 #10
0
        public void StorageStardogReasoningQL()
        {
            StardogConnector stardog = StardogTests.GetConnection();

            if (stardog.Reasoning == StardogReasoningMode.DatabaseControlled)
            {
                Assert.Inconclusive(
                    "Version of Stardog being tested does not support configuring reasoning mode at connection level");
            }

            Graph g = new Graph();

            g.LoadFromFile("resources\\InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/reasoning");
            stardog.SaveGraph(g);

            String query = "PREFIX rdfs: <" + NamespaceMapper.RDFS +
                           "> SELECT * WHERE { { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } UNION { GRAPH <http://example.org/reasoning> { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } } }";

            Console.WriteLine(query);
            Console.WriteLine();

            SparqlResultSet resultsNoReasoning = stardog.Query(query) as SparqlResultSet;

            if (resultsNoReasoning != null)
            {
                Console.WriteLine("Results without Reasoning");
                TestTools.ShowResults(resultsNoReasoning);
            }
            else
            {
                Assert.Fail("Did not get a SPARQL Result Set as expected");
            }

            stardog.Reasoning = StardogReasoningMode.QL;
            SparqlResultSet resultsWithReasoning = stardog.Query(query) as SparqlResultSet;

            if (resultsWithReasoning != null)
            {
                Console.WriteLine("Results with Reasoning");
                TestTools.ShowResults(resultsWithReasoning);
            }
            else
            {
                Assert.Fail("Did not get a SPARQL Result Set as expected");
            }

            Assert.IsTrue(resultsWithReasoning.Count >= resultsNoReasoning.Count,
                          "Reasoning should yield as many if not more results");
        }
예제 #11
0
        public void StorageStardogReasoningQL()
        {
            try
            {
                //Options.UseBomForUtf8 = false;
                Options.HttpDebugging = true;

                StardogConnector stardog = StardogTests.GetConnection();;

                Graph g = new Graph();
                g.LoadFromFile("InferenceTest.ttl");
                g.BaseUri = new Uri("http://example.org/reasoning");
                stardog.SaveGraph(g);

                String query = "PREFIX rdfs: <" + NamespaceMapper.RDFS + "> SELECT * WHERE { { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } UNION { GRAPH <http://example.org/reasoning> { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } } }";
                Console.WriteLine(query);
                Console.WriteLine();

                SparqlResultSet resultsNoReasoning = stardog.Query(query) as SparqlResultSet;
                if (resultsNoReasoning != null)
                {
                    Console.WriteLine("Results without Reasoning");
                    TestTools.ShowResults(resultsNoReasoning);
                }
                else
                {
                    Assert.Fail("Did not get a SPARQL Result Set as expected");
                }

                stardog.Reasoning = StardogReasoningMode.QL;
                SparqlResultSet resultsWithReasoning = stardog.Query(query) as SparqlResultSet;
                if (resultsWithReasoning != null)
                {
                    Console.WriteLine("Results with Reasoning");
                    TestTools.ShowResults(resultsWithReasoning);
                }
                else
                {
                    Assert.Fail("Did not get a SPARQL Result Set as expected");
                }

                Assert.IsTrue(resultsWithReasoning.Count >= resultsNoReasoning.Count, "Reasoning should yield as many if not more results");
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
                Options.HttpDebugging = false;
            }
        }
예제 #12
0
        public void StorageStardogAmpersandsInDataTest()
        {
            try
            {
                Options.HttpDebugging = true;

                StardogConnector stardog = StardogTests.GetConnection();;

                //Save the Graph
                Graph  g        = new Graph();
                String fragment = "@prefix : <http://example.org/> . [] :string \"This has & ampersands in it\" .";
                g.LoadFromString(fragment);
                g.BaseUri = new Uri("http://example.org/ampersandGraph");

                Console.WriteLine("Original Graph:");
                TestTools.ShowGraph(g);

                stardog.SaveGraph(g);

                //Retrieve and check it round trips
                Graph h = new Graph();
                stardog.LoadGraph(h, g.BaseUri);

                Console.WriteLine("Graph as retrieved from Stardog:");
                TestTools.ShowGraph(h);

                Assert.AreEqual(g, h, "Graphs should be equal");

                //Now try to delete the data from this Graph
                GenericUpdateProcessor processor = new GenericUpdateProcessor(stardog);
                SparqlUpdateParser     parser    = new SparqlUpdateParser();
                processor.ProcessCommandSet(parser.ParseFromString("WITH <http://example.org/ampersandGraph> DELETE WHERE { ?s ?p ?o }"));

                Graph i = new Graph();
                stardog.LoadGraph(i, g.BaseUri);

                Console.WriteLine("Graph as retrieved after the DELETE WHERE:");
                TestTools.ShowGraph(i);

                Assert.AreNotEqual(g, i, "Graphs should not be equal");
                Assert.AreNotEqual(h, i, "Graphs should not be equal");
            }
            finally
            {
                Options.HttpDebugging = false;
            }
        }
예제 #13
0
        public void StorageStardogLoadDefaultGraph()
        {
            StardogConnector stardog = StardogTests.GetConnection();
            Graph            g       = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = null;
            stardog.SaveGraph(g);

            Graph h = new Graph();

            stardog.LoadGraph(h, (Uri)null);

            NTriplesFormatter formatter = new NTriplesFormatter();

            foreach (Triple t in h.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }

            Assert.False(h.IsEmpty);
        }
예제 #14
0
        public void StorageStardogSaveToNamedGraph()
        {
            try
            {
                //Options.UseBomForUtf8 = false;

                StardogConnector stardog = StardogTests.GetConnection();;
                Graph            g       = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                g.BaseUri = new Uri("http://example.org/graph");
                stardog.SaveGraph(g);

                Graph h = new Graph();
                stardog.LoadGraph(h, new Uri("http://example.org/graph"));

                Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph");
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
            }
        }
예제 #15
0
        public void StorageStardogSaveToNamedGraph2()
        {
            try
            {
                //Options.UseBomForUtf8 = false;

                StardogConnector stardog = StardogTests.GetConnection();

                Graph g = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                Uri u = new Uri("http://example.org/graph/" + DateTime.Now.Ticks);
                g.BaseUri = u;
                stardog.SaveGraph(g);

                Graph h = new Graph();
                stardog.LoadGraph(h, u);

                Assert.Equal(g, h);
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
            }
        }