Ejemplo n.º 1
0
        public void SparqlUpdateDeleteWithGraphClause2()
        {
            Graph g = new Graph();

            g.Assert(g.CreateUriNode(UriFactory.Create("http://subject")), g.CreateUriNode(UriFactory.Create("http://predicate")), g.CreateUriNode(UriFactory.Create("http://object")));
            Graph h = new Graph();

            h.Merge(g);
            h.BaseUri = UriFactory.Create("http://subject");

            InMemoryDataset dataset = new InMemoryDataset(g);

            dataset.AddGraph(h);
            dataset.Flush();

            Assert.Equal(2, dataset.GraphUris.Count());

            String updates = "DELETE { GRAPH ?s { ?s ?p ?o } } INSERT { GRAPH ?o { ?s ?p ?o } } WHERE { ?s ?p ?o }";
            SparqlUpdateCommandSet commands = new SparqlUpdateParser().ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(commands);

            Assert.Equal(3, dataset.GraphUris.Count());
            Assert.True(dataset.HasGraph(UriFactory.Create("http://subject")));
            Assert.True(dataset.HasGraph(UriFactory.Create("http://object")));
            Assert.Equal(0, dataset[UriFactory.Create("http://subject")].Triples.Count);
        }
Ejemplo n.º 2
0
        public void SparqlUpdateDeleteCommandWithNoMatchingGraphAndChildGraphPatterns()
        {
            var dataset        = new InMemoryDataset();
            var updateGraphUri = new Uri("http://example.org/g2");
            var updateGraph    = new Graph {
                BaseUri = updateGraphUri
            };

            updateGraph.Assert(new Triple(updateGraph.CreateUriNode(new Uri("http://example.org/s")),
                                          updateGraph.CreateUriNode(new Uri("http://example.org/p")),
                                          updateGraph.CreateUriNode(new Uri("http://example.org/o"))));
            dataset.AddGraph(updateGraph);

            var egGraph = new Uri("http://example.org/graph");

            dataset.HasGraph(egGraph).Should().BeFalse();
            var processor = new LeviathanUpdateProcessor(dataset);
            var cmdSet    = new SparqlUpdateParser().ParseFromString(
                "WITH <" + egGraph +
                "> DELETE { GRAPH <http://example.org/g2> { <http://example.org/s> <http://example.org/p> <http://example.org/o> }} WHERE {}");

            processor.ProcessCommandSet(cmdSet);

            dataset.HasGraph(egGraph).Should().BeFalse(because: "Update command should not create an empty graph for a DELETE operation");
            dataset[updateGraphUri].IsEmpty.Should()
            .BeTrue("Triples should be deleted by child graph pattern");
        }
Ejemplo n.º 3
0
        public void SparqlUpdateDeleteCommandWithNoMatchingGraph()
        {
            var dataset = new InMemoryDataset();
            var egGraph = new Uri("http://example.org/graph");

            dataset.HasGraph(egGraph).Should().BeFalse();
            var processor = new LeviathanUpdateProcessor(dataset);
            var cmdSet    = new SparqlUpdateParser().ParseFromString(
                "WITH <" + egGraph + "> DELETE {} WHERE {}");

            processor.ProcessCommandSet(cmdSet);
            dataset.HasGraph(egGraph).Should().BeFalse();
        }
Ejemplo n.º 4
0
        public void SparqlUpdateInsertCommandWithNoMatchingGraph()
        {
            var dataset = new InMemoryDataset();
            var egGraph = new Uri("http://example.org/graph");

            dataset.HasGraph(egGraph).Should().BeFalse();
            var processor = new LeviathanUpdateProcessor(dataset);
            var cmdSet    = new SparqlUpdateParser().ParseFromString(
                "WITH <" + egGraph + "> INSERT {} WHERE {}");

            processor.ProcessCommandSet(cmdSet);
            dataset.HasGraph(egGraph).Should().BeFalse(); // No triples got added

            cmdSet = new SparqlUpdateParser().ParseFromString(
                "WITH <" + egGraph + "> INSERT { <http://example.org/s> <http://example.org/p> <http://example.org/o> } WHERE {}");
            processor.ProcessCommandSet(cmdSet);
            dataset.HasGraph(egGraph).Should().BeTrue(); // Triples got added
        }
Ejemplo n.º 5
0
        public void SparqlUpdateInsertWithGraphClause1()
        {
            Graph g = new Graph();

            g.Assert(g.CreateUriNode(UriFactory.Create("http://subject")), g.CreateUriNode(UriFactory.Create("http://predicate")), g.CreateUriNode(UriFactory.Create("http://object")));

            InMemoryDataset dataset = new InMemoryDataset(g);

            String updates = "INSERT { GRAPH ?s { ?s ?p ?o } } WHERE { ?s ?p ?o }";
            SparqlUpdateCommandSet commands = new SparqlUpdateParser().ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(commands);

            Assert.Equal(2, dataset.GraphUris.Count());
            Assert.True(dataset.HasGraph(UriFactory.Create("http://subject")));
        }