Пример #1
0
        public void SparqlUpdateTimeout()
        {
            String update = "CREATE GRAPH <http://example.org/1>; LOAD <http://www.dotnetrdf.org/configuration#>; CREATE GRAPH <http://example.org/2>";
            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(update);

            cmds.Timeout = 1;

            TripleStore store = new TripleStore();
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.Fail("Expected a SparqlUpdateTimeoutException");
            }
            catch (SparqlUpdateTimeoutException timeoutEx)
            {
                TestTools.ReportError("Timeout", timeoutEx);
                Console.WriteLine();
                Console.WriteLine("Execution Time: " + cmds.UpdateExecutionTime.Value.ToString());

                Assert.IsFalse(store.HasGraph(new Uri("http://example.org/1")), "Graph 1 should not exist");
                Assert.IsFalse(store.HasGraph(new Uri("http://example.org/2")), "Graph 2 should not exist");
            }
        }
Пример #2
0
        public void SparqlUpdateDeleteWithBind()
        {
            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

            g.LoadFromFile("resources\\rvesse.ttl");
            store.Add(g);

            int origTriples = g.Triples.Count;

            SparqlParameterizedString command = new SparqlParameterizedString();

            command.Namespaces.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/"));
            command.CommandText = "DELETE { ?x foaf:mbox ?y } WHERE { ?x foaf:mbox ?email . BIND(?email AS ?y) }";

            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString(command);

            InMemoryDataset          dataset   = new InMemoryDataset(store, g.BaseUri);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.NotEqual(origTriples, g.Triples.Count);
            Assert.False(g.GetTriplesWithPredicate(g.CreateUriNode(new Uri("http://xmlns.com/foaf/0.1/mbox"))).Any(), "Expected triples to have been deleted");
        }
Пример #3
0
        public void SparqlUpdateInsertDataCombination()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();

            command.Namespaces.AddNamespace("ex", new Uri("http://example.org/"));
            command.CommandText = "INSERT DATA { ex:a ex:b ex:c GRAPH <http://example.org/graph> { ex:a ex:b ex:c } }";

            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString(command);

            Assert.IsFalse(cmds.Commands.All(cmd => cmd.AffectsSingleGraph), "Commands should report that they do not affect a single Graph");
            Assert.IsTrue(cmds.Commands.All(cmd => cmd.AffectsGraph(null)), "Commands should report that they affect the Default Graph");
            Assert.IsTrue(cmds.Commands.All(cmd => cmd.AffectsGraph(new Uri("http://example.org/graph"))), "Commands should report that they affect the named Graph");

            InMemoryDataset          dataset   = new InMemoryDataset();
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Graph g = new Graph();

            g.NamespaceMap.Import(command.Namespaces);
            Triple t = new Triple(g.CreateUriNode("ex:a"), g.CreateUriNode("ex:b"), g.CreateUriNode("ex:c"));

            IGraph def = dataset[null];

            Assert.AreEqual(1, def.Triples.Count, "Should be 1 Triple in the Default Graph");
            Assert.IsTrue(def.ContainsTriple(t), "Should have the inserted Triple in the Default Graph");

            IGraph ex = dataset[new Uri("http://example.org/graph")];

            Assert.AreEqual(1, ex.Triples.Count, "Should be 1 Triple in the Named Graph");
            Assert.IsTrue(ex.ContainsTriple(t), "Should have the inserted Triple in the Named Graph");
        }
Пример #4
0
        private void TestDeleteDataThenInsertDataRollback()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();
            IGraph         g       = dataset.GetModifiableGraph(TestGraphUri);

            g.Assert(new Triple(g.CreateUriNode(new Uri("ex:subj")), g.CreateUriNode(new Uri("ex:pred")), g.CreateUriNode(new Uri("ex:obj"))));

            String updates = "DELETE DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; CREATE GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.True(false, "Did not thrown a SparqlUpdateException as expected");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx);
            }

            Assert.False(dataset[TestGraphUri].IsEmpty, "Graph should not be empty as the Discard() should reverse first the insert then the delete so the end results should be the triple still being in the Graph");
        }
Пример #5
0
        public void SparqlUpdateDeleteWithFilter()
        {
            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

            g.LoadFromFile("rvesse.ttl");
            store.Add(g);

            int origTriples = g.Triples.Count;

            SparqlParameterizedString command = new SparqlParameterizedString();

            command.Namespaces.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/"));
            command.CommandText = "DELETE { ?x foaf:mbox ?email } WHERE { ?x foaf:mbox ?email . FILTER(REGEX(STR(?email), 'dotnetrdf\\.org')) }";

            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString(command);

            InMemoryDataset          dataset   = new InMemoryDataset(store, g.BaseUri);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.AreNotEqual(origTriples, g.Triples.Count, "Expected triples to have been deleted");
            Assert.IsFalse(g.GetTriplesWithPredicate(g.CreateUriNode(new Uri("http://xmlns.com/foaf/0.1/mbox"))).Where(t => t.Object.ToString().Contains("dotnetrdf.org")).Any(), "Expected triples to have been deleted");
        }
Пример #6
0
        public void SparqlUpdateInsertWithBind()
        {
            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

            g.LoadFromFile("rvesse.ttl");
            store.Add(g);

            int origTriples = g.Triples.Count;

            SparqlParameterizedString command = new SparqlParameterizedString();

            command.Namespaces.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/"));
            command.CommandText = "INSERT { ?x foaf:mbox_sha1sum ?hash } WHERE { ?x foaf:mbox ?email . BIND(SHA1(STR(?email)) AS ?hash) }";

            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString(command);

            InMemoryDataset          dataset   = new InMemoryDataset(store, g.BaseUri);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.AreNotEqual(origTriples, g.Triples.Count, "Expected new triples to have been added");
            Assert.IsTrue(g.GetTriplesWithPredicate(g.CreateUriNode(new Uri("http://xmlns.com/foaf/0.1/mbox_sha1sum"))).Any(), "Expected new triples to have been added");
        }
        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");
        }
Пример #8
0
        public void SparqlUpdateInsertCommand3()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();

            command.Namespaces.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            command.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            command.CommandText  = "INSERT { ?s rdf:type ?class } USING NAMED <http://example.org/temp> WHERE { ?s a ?type . ?type rdfs:subClassOf+ ?class };";
            command.CommandText += "INSERT { ?s ?property ?value } USING NAMED <http://example.org/temp> WHERE {?s ?p ?value . ?p rdfs:subPropertyOf+ ?property };";
            command.CommandText += "INSERT { ?s rdf:type rdfs:Class } USING NAMED <http://example.org/temp> WHERE { ?s rdfs:subClassOf ?class };";
            command.CommandText += "INSERT { ?s rdf:type rdf:Property } USING NAMED <http://example.org/temp> WHERE { ?s rdfs:subPropertyOf ?property };";

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

            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/temp");
            store.Add(g);

            SparqlUpdateParser       parser    = new SparqlUpdateParser();
            SparqlUpdateCommandSet   cmds      = parser.ParseFromString(command);
            InMemoryDataset          dataset   = new InMemoryDataset(store);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            dataset.SetDefaultGraph((Uri)null);
            processor.ProcessCommandSet(cmds);

            IGraph def = store[null];

            TestTools.ShowGraph(def);
            Assert.IsTrue(def.IsEmpty, "Graph should be empty as the commands only used USING NAMED (so shouldn't have changed the dataset) and the Active Graph for the dataset was empty so there should have been nothing matched to generate insertions from");
        }
Пример #9
0
        public void SparqlUpdateCopyCommand3()
        {
            IGraph g = new Graph();

            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = null;

            IGraph h = new Graph();

            FileLoader.Load(h, "Turtle.ttl");
            h.BaseUri = new Uri("http://example.org/destination");

            TripleStore store = new TripleStore();

            store.Add(g);
            store.Add(h);

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

            SparqlUpdateParser     parser   = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("COPY DEFAULT TO GRAPH <http://example.org/destination>");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            processor.ProcessCommandSet(commands);

            g = store[null];
            h = store[new Uri("http://example.org/destination")];
            Assert.IsFalse(g.IsEmpty, "Source Graph should not be empty");
            Assert.IsFalse(h.IsEmpty, "Destination Graph should not be empty");
            Assert.AreEqual(g, h, "Graphs should now be equal");
        }
Пример #10
0
        public void SparqlUpdateAddCommand2()
        {
            IGraph g = new Graph();

            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/source");

            IGraph h = new Graph();

            FileLoader.Load(h, "Turtle.ttl");
            h.BaseUri = null;

            TripleStore store = new TripleStore();

            store.Add(g);
            store.Add(h);

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

            SparqlUpdateParser     parser   = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("ADD GRAPH <http://example.org/source> TO DEFAULT");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            processor.ProcessCommandSet(commands);

            g = store[new Uri("http://example.org/source")];
            h = store[null];
            Assert.IsFalse(g.IsEmpty, "Source Graph should not be empty");
            Assert.IsFalse(h.IsEmpty, "Destination Graph should not be empty");
            Assert.IsTrue(h.HasSubGraph(g), "Destination Graph should have Source Graph as a subgraph");
        }
Пример #11
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);
        }
        private void TestUpdate(IInMemoryQueryableStore store, IGraph expected, String update)
        {
            SparqlUpdateCommandSet cmds = this._updateParser.ParseFromString(update);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            processor.ProcessCommandSet(cmds);

            Assert.IsTrue(store.HasGraph(null), "Store should have a default unnamed Graph");
            IGraph result = store.Graph(null);
            
            NTriplesFormatter formatter = new NTriplesFormatter();
            Console.WriteLine("Result Data");
            foreach (Triple t in result.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }
            Console.WriteLine();

            Console.WriteLine("Expected Data");
            foreach (Triple t in expected.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }
            Console.WriteLine();

            Assert.AreEqual(expected, result, "Graphs should be equal");
        }
Пример #13
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
        }
        private void TestCreateGraphCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "CREATE GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            processor.ProcessCommandSet(cmds);

            Assert.IsTrue(dataset.HasGraph(TestGraphUri), "Graph should exist");
        }
Пример #15
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();
        }
Пример #16
0
        private void TestInsertDataSequenceCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { } }; INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }";

            SparqlUpdateCommandSet   cmds      = this._parser.ParseFromString(updates);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.True(dataset.HasGraph(TestGraphUri), "Graph should exist");
            Assert.Equal(1, dataset[TestGraphUri].Triples.Count);
        }
Пример #17
0
        public void SparqlUpdateInsertCommand2()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();

            command.Namespaces.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            command.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            command.CommandText  = "INSERT { ?s rdf:type ?class } USING <http://example.org/temp> WHERE { ?s a ?type . ?type rdfs:subClassOf+ ?class };";
            command.CommandText += "INSERT { ?s ?property ?value } USING <http://example.org/temp> WHERE {?s ?p ?value . ?p rdfs:subPropertyOf+ ?property };";
            command.CommandText += "INSERT { ?s rdf:type rdfs:Class } USING <http://example.org/temp> WHERE { ?s rdfs:subClassOf ?class };";
            command.CommandText += "INSERT { ?s rdf:type rdf:Property } USING <http://example.org/temp> WHERE { ?s rdfs:subPropertyOf ?property };";

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

            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/temp");
            store.Add(g);
            int origTriples = g.Triples.Count;

            SparqlUpdateParser       parser    = new SparqlUpdateParser();
            SparqlUpdateCommandSet   cmds      = parser.ParseFromString(command);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            processor.ProcessCommandSet(cmds);

            Assert.AreEqual(origTriples, g.Triples.Count, "Triples in input Graph shouldn't have changed as INSERTs should have gone to the default graph");

            IGraph def = store[null];

            TestTools.ShowGraph(def);
            Console.WriteLine();

            //Apply a RDFS reasoner over the original input and output it into another graph
            //Should be equivalent to the default Graph
            Graph        h        = new Graph();
            RdfsReasoner reasoner = new RdfsReasoner();

            reasoner.Apply(g, h);

            TestTools.ShowGraph(h);

            GraphDiffReport report = h.Difference(def);

            if (!report.AreEqual)
            {
                TestTools.ShowDifferences(report);

                Assert.IsTrue(report.RemovedTriples.Count() == 1, "Should have only 1 missing Triple (due to rdfs:domain inference which is hard to encode in an INSERT command)");
            }
        }
Пример #18
0
        private void TestLoadCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "LOAD <http://www.dotnetrdf.org/configuration#> INTO GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.True(dataset.HasGraph(TestGraphUri), "Graph should exist");
        }
Пример #19
0
        private void TestInsertDataThenDropCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subject> <ex:predicate> <ex:object> } }; DROP GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.False(dataset.HasGraph(TestGraphUri), "Graph should not exist as the Flush() should cause it to be removed from the Dataset");
        }
Пример #20
0
        private void TestInsertDataThenDeleteDataCommit()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; DELETE DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.True(dataset[TestGraphUri].IsEmpty, "Graph should be empty as the Flush() should persist first the insert then the delete");
        }
Пример #21
0
        private void TestCreateGraphCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "CREATE GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.True(dataset.HasGraph(TestGraphUri), "Graph should exist");
        }
Пример #22
0
        private void TestDropGraphCommit()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "DROP GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.False(dataset.HasGraph(TestGraphUri), "Graph should not exist");
        }
Пример #23
0
        public void SparqlUpdateChangesNotReflectedInOriginalGraph1()
        {
            //Test Case originally submitted by Tomasz Pluskiewicz

            // given
            IGraph sourceGraph = new Graph();

            sourceGraph.LoadFromString(@"@prefix ex: <http://www.example.com/> .
ex:Subject ex:hasObject ex:Object .");

            IGraph expectedGraph = new Graph();

            expectedGraph.LoadFromString(@"@prefix ex: <http://www.example.com/> .
ex:Subject ex:hasBlank [ ex:hasObject ex:Object ] .");


            //IMPORTANT - Because we create the dataset without an existing store it
            //creates a new triple store internally which has a single unnamed graph
            //Then when we add another unnamed graph it merges into that existing graph,
            //this is why the update does not apply to the added graph but rather to
            //the merged graph that is internal to the dataset
            ISparqlDataset dataset = new InMemoryDataset(true);

            dataset.AddGraph(sourceGraph);

            // when
            var command = new SparqlParameterizedString
            {
                CommandText = @"PREFIX ex: <http://www.example.com/>
DELETE { ex:Subject ex:hasObject ex:Object . }
INSERT { ex:Subject ex:hasBlank [ ex:hasObject ex:Object ] . }
WHERE { ?s ?p ?o . }"
            };
            SparqlUpdateCommandSet   cmds      = new SparqlUpdateParser().ParseFromString(command);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.Single(dataset.Graphs);

            IGraph g = dataset.Graphs.First();

            Assert.Equal(2, g.Triples.Count);
            Assert.False(ReferenceEquals(g, sourceGraph), "Result Graph should not be the Source Graph");
            Assert.Equal(1, sourceGraph.Triples.Count);
            Assert.NotEqual(expectedGraph, sourceGraph);
        }
Пример #24
0
        public void SparqlUpdateInsertCommand()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();

            command.Namespaces.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            command.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            command.CommandText  = "INSERT { ?s rdf:type ?class } WHERE { ?s a ?type . ?type rdfs:subClassOf+ ?class };";
            command.CommandText += "INSERT { ?s ?property ?value } WHERE {?s ?p ?value . ?p rdfs:subPropertyOf+ ?property };";
            command.CommandText += "INSERT { ?s rdf:type rdfs:Class } WHERE { ?s rdfs:subClassOf ?class };";
            command.CommandText += "INSERT { ?s rdf:type rdf:Property } WHERE { ?s rdfs:subPropertyOf ?property };";

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

            FileLoader.Load(g, "InferenceTest.ttl");
            g.Retract(g.Triples.Where(t => !t.IsGroundTriple).ToList());
            g.BaseUri = null;
            store.Add(g);

            SparqlUpdateParser       parser    = new SparqlUpdateParser();
            SparqlUpdateCommandSet   cmds      = parser.ParseFromString(command);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            processor.ProcessCommandSet(cmds);

            TestTools.ShowGraph(g);
            Console.WriteLine();

            //Now reload the test data and apply an RDFS reasoner over it
            //This should give us a Graph equivalent to the one created by the previous INSERT commands
            Graph h = new Graph();

            FileLoader.Load(h, "InferenceTest.ttl");
            h.Retract(h.Triples.Where(t => !t.IsGroundTriple).ToList());
            RdfsReasoner reasoner = new RdfsReasoner();

            reasoner.Apply(h);

            GraphDiffReport diff = h.Difference(g);

            if (!diff.AreEqual)
            {
                TestTools.ShowDifferences(diff);
            }

            Assert.AreEqual(h, g, "Graphs should be equal");
        }
Пример #25
0
        private void TestDeleteDataThenInsertDataCommit()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();
            IGraph         g       = dataset.GetModifiableGraph(TestGraphUri);

            g.Assert(new Triple(g.CreateUriNode(new Uri("ex:subj")), g.CreateUriNode(new Uri("ex:pred")), g.CreateUriNode(new Uri("ex:obj"))));
            dataset.Flush();

            String updates = "DELETE DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.False(dataset[TestGraphUri].IsEmpty, "Graph should not be empty as the Flush() should persist first the delete then the insert so the end results should be the triple still being in the Graph");
        }
Пример #26
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")));
        }
Пример #27
0
        public void SparqlUpdateWithDefaultQueryProcessor()
        {
            Graph g = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = null;
            TripleStore store = new TripleStore();

            store.Add(g);
            InMemoryDataset dataset = new InMemoryDataset(store);

            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString("DELETE { ?s a ?type } WHERE { ?s a ?type }");

            ISparqlUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);
        }
Пример #28
0
        public void SparqlUpdateChangesNotReflectedInOriginalGraph2()
        {
            //Test Case originally submitted by Tomasz Pluskiewicz

            // given
            IGraph sourceGraph = new Graph();

            sourceGraph.LoadFromString(@"@prefix ex: <http://www.example.com/> .
ex:Subject ex:hasObject ex:Object .");

            IGraph expectedGraph = new Graph();

            expectedGraph.LoadFromString(@"@prefix ex: <http://www.example.com/> .
ex:Subject ex:hasBlank [ ex:hasObject ex:Object ] .");

            TripleStore store = new TripleStore();

            store.Add(sourceGraph);
            ISparqlDataset dataset = new InMemoryDataset(store, sourceGraph.BaseUri);

            // when
            var command = new SparqlParameterizedString
            {
                CommandText = @"PREFIX ex: <http://www.example.com/>
DELETE { ex:Subject ex:hasObject ex:Object . }
INSERT { ex:Subject ex:hasBlank [ ex:hasObject ex:Object ] . }
WHERE { ?s ?p ?o . }"
            };
            SparqlUpdateCommandSet   cmds      = new SparqlUpdateParser().ParseFromString(command);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.Single(dataset.Graphs);

            IGraph g = dataset.Graphs.First();

            Assert.Equal(2, g.Triples.Count);
            Assert.True(ReferenceEquals(g, sourceGraph), "Result Graph should be the Source Graph");
            Assert.Equal(2, sourceGraph.Triples.Count);
            Assert.Equal(expectedGraph, sourceGraph);
        }
        private void TestCreateGraphRollback()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "CREATE GRAPH <" + TestGraphUri.ToString() + ">; CREATE GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.Fail("Did not thrown a SparqlUpdateException as expected");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx, false);
            }

            Assert.IsFalse(dataset.HasGraph(TestGraphUri), "Graph should not exist as the Discard() should cause it to be removed from the Dataset");

        }
Пример #30
0
        private void TestDropGraphRollback()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "DROP GRAPH <" + TestGraphUri.ToString() + ">; DROP GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.True(false, "Did not thrown a SparqlUpdateException as expected");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx);
            }

            Assert.True(dataset.HasGraph(TestGraphUri), "Graph should exist as the Discard() should ensure it was still in the Dataset");
        }
Пример #31
0
        private void TestCreateGraphRollback()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "CREATE GRAPH <" + TestGraphUri.ToString() + ">; CREATE GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.True(false, "Did not thrown a SparqlUpdateException as expected");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx);
            }

            Assert.False(dataset.HasGraph(TestGraphUri), "Graph should not exist as the Discard() should cause it to be removed from the Dataset");
        }
Пример #32
0
        private void TestInsertDataThenDeleteDataRollback()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; DELETE DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; CREATE GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.True(false, "Did not thrown a SparqlUpdateException as expected");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx);
            }

            Assert.True(dataset[TestGraphUri].IsEmpty, "Graph should be empty as the Discard() should reverse first the delete then the insert");
        }
Пример #33
0
        private void TestCreateDropSequenceRollback2()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "DROP GRAPH <" + TestGraphUri.ToString() + ">; CREATE GRAPH <" + TestGraphUri.ToString() + ">; DROP GRAPH <" + TestGraphUri.ToString() + ">; DROP GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.True(false, "Expected SPARQL Update Exception was not thrown");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx);
            }

            Assert.True(dataset.HasGraph(TestGraphUri), "Graph should not exist");
        }
Пример #34
0
        public void SparqlUpdateTimeout()
        {
            String update = "CREATE GRAPH <http://example.org/1>; LOAD <http://www.dotnetrdf.org/configuration#>; CREATE GRAPH <http://example.org/2>";
            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(update);
            cmds.Timeout = 1;

            TripleStore store = new TripleStore();
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.Fail("Expected a SparqlUpdateTimeoutException");
            }
            catch (SparqlUpdateTimeoutException timeoutEx)
            {
                TestTools.ReportError("Timeout", timeoutEx, false);
                Console.WriteLine();
                Console.WriteLine("Execution Time: " + cmds.UpdateExecutionTime.Value.ToString());

                Assert.IsFalse(store.HasGraph(new Uri("http://example.org/1")), "Graph 1 should not exist");
                Assert.IsFalse(store.HasGraph(new Uri("http://example.org/2")), "Graph 2 should not exist");

            }
        }
        private void TestDropThenInsertDataRollback()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "DROP GRAPH <" + TestGraphUri.ToString() + ">; INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subject> <ex:predicate> <ex:object> } }; CREATE GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.Fail("Did not thrown a SparqlUpdateException as expected");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx, false);
            }

            Assert.IsTrue(dataset.HasGraph(TestGraphUri), "Graph should not exist as the Discard() should cause it to be removed from the Dataset");
            Assert.IsTrue(dataset[TestGraphUri].IsEmpty, "Graph should be empty as the Discard() should have reversed the INSERT DATA");
        }
Пример #36
0
        public void SparqlUpdateDeleteDataCombination()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();
            command.Namespaces.AddNamespace("ex", new Uri("http://example.org/"));
            command.CommandText = "DELETE DATA { ex:a ex:b ex:c GRAPH <http://example.org/graph> { ex:a ex:b ex:c } }";

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds = parser.ParseFromString(command);

            Assert.IsFalse(cmds.Commands.All(cmd => cmd.AffectsSingleGraph), "Commands should report that they do not affect a single Graph");
            Assert.IsTrue(cmds.Commands.All(cmd => cmd.AffectsGraph(null)), "Commands should report that they affect the Default Graph");
            Assert.IsTrue(cmds.Commands.All(cmd => cmd.AffectsGraph(new Uri("http://example.org/graph"))), "Commands should report that they affect the named Graph");

            InMemoryDataset dataset = new InMemoryDataset();
            IGraph def = new Graph();
            def.NamespaceMap.Import(command.Namespaces);
            def.Assert(new Triple(def.CreateUriNode("ex:a"), def.CreateUriNode("ex:b"), def.CreateUriNode("ex:c")));
            dataset.AddGraph(def);
            IGraph ex = new Graph();
            ex.BaseUri = new Uri("http://example.org/graph");
            ex.NamespaceMap.Import(command.Namespaces);
            ex.Assert(new Triple(ex.CreateUriNode("ex:a"), ex.CreateUriNode("ex:b"), ex.CreateUriNode("ex:c")));
            dataset.AddGraph(ex);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            processor.ProcessCommandSet(cmds);

            Graph g = new Graph();
            g.NamespaceMap.Import(command.Namespaces);
            Triple t = new Triple(g.CreateUriNode("ex:a"), g.CreateUriNode("ex:b"), g.CreateUriNode("ex:c"));

            def = dataset[null];
            Assert.AreEqual(0, def.Triples.Count, "Should be 0 Triples in the Default Graph");
            Assert.IsFalse(def.ContainsTriple(t), "Should not have the deleted Triple in the Default Graph");

            ex = dataset[new Uri("http://example.org/graph")];
            Assert.AreEqual(0, ex.Triples.Count, "Should be 0 Triples in the Named Graph");
            Assert.IsFalse(ex.ContainsTriple(t), "Should not have the deleted Triple in the Named Graph");

        }
        private int ProcessUpdateEvaluationTest(IGraph manifest, INode testNode)
        {
            try
            {
                IUriNode utData = manifest.CreateUriNode("ut:data");
                IUriNode utGraph = manifest.CreateUriNode("ut:graph");
                IUriNode utGraphData = manifest.CreateUriNode("ut:graphData");
                IUriNode rdfsLabel = manifest.CreateUriNode("rdfs:label");

                //Get the test name and comment
                String name = manifest.GetTriplesWithSubjectPredicate(testNode, manifest.CreateUriNode("mf:name")).Select(t => t.Object).First().ToString();
                String comment = manifest.GetTriplesWithSubjectPredicate(testNode, manifest.CreateUriNode("rdfs:comment")).Select(t => t.Object).First().ToString();

                //Get the test action and file
                INode actionNode = manifest.GetTriplesWithSubjectPredicate(testNode, manifest.CreateUriNode("mf:action")).Select(t => t.Object).First();
                String updateFile = manifest.GetTriplesWithSubjectPredicate(actionNode, manifest.CreateUriNode("ut:request")).Select(t => t.Object).First().ToString();

                Console.WriteLine("# Processing Update Evaluation Test " + updateFile);
                Console.WriteLine(name);
                Console.WriteLine(comment);
                Console.WriteLine();

                if (evaluationTestOverride.Any(x => updateFile.EndsWith(x)))
                {
                    Console.WriteLine();
                    Console.WriteLine("# Test Result = Manually overridden to Pass (Test Passed)");
                    testsPassed++;
                    testsEvaluationPassed++;
                    return 1;
                }

                //Parse the Update
                SparqlUpdateParser parser = new SparqlUpdateParser();
                SparqlUpdateCommandSet cmds;
                try
                {
                    if (updateFile.StartsWith("file:///"))
                    {
                        updateFile = updateFile.Substring(8);
                    }
                    cmds = parser.ParseFromFile(updateFile);

                    Console.WriteLine("Update Commands:");
                    Console.WriteLine(cmds.ToString());
                }
                catch (Exception ex)
                {
                    this.ReportError("Error Parsing Update Commands", ex);

                    Console.WriteLine("# Test Result - Update Command failed to pass (Test Failed)");
                    testsEvaluationFailed++;
                    testsFailed++;
                    return -1;
                }

                //Build the Initial Dataset
                InMemoryDataset dataset = new InMemoryDataset(new TripleStore());
                try
                {
                    foreach (Triple t in manifest.GetTriplesWithSubjectPredicate(actionNode, utData))
                    {
                        Console.WriteLine("Uses Default Graph File " + t.Object.ToString());
                        Graph g = new Graph();
                        UriLoader.Load(g, ((IUriNode)t.Object).Uri);
                        g.BaseUri = null;
                        dataset.AddGraph(g);
                    }
                    foreach (Triple t in manifest.GetTriplesWithSubjectPredicate(actionNode, utGraphData))
                    {
                        Graph g = new Graph();
                        INode dataNode = manifest.GetTriplesWithSubjectPredicate(t.Object, utData).Concat(manifest.GetTriplesWithSubjectPredicate(t.Object, utGraph)).Select(x => x.Object).FirstOrDefault();
                        UriLoader.Load(g, ((IUriNode)dataNode).Uri);
                        INode nameNode = manifest.GetTriplesWithSubjectPredicate(t.Object, rdfsLabel).Select(x => x.Object).FirstOrDefault();
                        g.BaseUri = new Uri(nameNode.ToString());
                        Console.WriteLine("Uses Named Graph File " + dataNode.ToString() + " named as " + nameNode.ToString());
                        dataset.AddGraph(g);
                    }
                }
                catch (Exception ex)
                {
                    this.ReportError("Error Building Initial Dataset", ex);
                    Console.WriteLine("# Test Result - Unable to build Initial Dataset (Test Indeterminate)");
                    testsEvaluationIndeterminate++;
                    testsIndeterminate++;
                    return 0;
                }
                Console.WriteLine();

                //Try running the Update
                try
                {
                    LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

                    //Since all Tests assume that the WHERE is limited to the unnamed default graph unless specified
                    //then must set this to be the Active Graph for the dataset
                    dataset.SetDefaultGraph(dataset[null]);

                    //Try the Update
                    processor.ProcessCommandSet(cmds);

                    dataset.ResetDefaultGraph();
                }
                catch (SparqlUpdateException updateEx)
                {
                    //TODO: Some Update tests might be to test cases where a failure should occur
                    this.ReportError("Unexpected Error while performing Update", updateEx);
                    Console.WriteLine("# Test Result - Update Failed (Test Failed)");
                    testsEvaluationFailed++;
                    testsFailed++;
                    return -1;
                }
                catch (Exception ex)
                {
                    this.ReportError("Unexpected Error while performing Update", ex);
                    Console.WriteLine("# Test Result - Update Failed (Test Failed)");
                    testsEvaluationFailed++;
                    testsFailed++;
                    return -1;
                }

                //Build the Result Dataset
                INode resultNode = manifest.GetTriplesWithSubjectPredicate(testNode, manifest.CreateUriNode("mf:result")).Select(t => t.Object).First();
                InMemoryDataset resultDataset = new InMemoryDataset(new TripleStore());
                try
                {
                    foreach (Triple t in manifest.GetTriplesWithSubjectPredicate(resultNode, utData))
                    {
                        Console.WriteLine("Uses Result Default Graph File " + t.Object.ToString());
                        Graph g = new Graph();
                        UriLoader.Load(g, ((IUriNode)t.Object).Uri);
                        g.BaseUri = null;
                        resultDataset.AddGraph(g);
                    }
                    foreach (Triple t in manifest.GetTriplesWithSubjectPredicate(resultNode, utGraphData))
                    {
                        Graph g = new Graph();
                        INode dataNode = manifest.GetTriplesWithSubjectPredicate(t.Object, utData).Concat(manifest.GetTriplesWithSubjectPredicate(t.Object, utGraph)).Select(x => x.Object).FirstOrDefault();
                        UriLoader.Load(g, ((IUriNode)dataNode).Uri);
                        INode nameNode = manifest.GetTriplesWithSubjectPredicate(t.Object, rdfsLabel).Select(x => x.Object).FirstOrDefault();
                        g.BaseUri = new Uri(nameNode.ToString());
                        Console.WriteLine("Uses Result Named Graph File " + dataNode.ToString() + " named as " + nameNode.ToString());
                        resultDataset.AddGraph(g);
                    }
                    
                    //Do this just to ensure that if the Result Dataset doesn't have a default unnamed graph it will
                    //have one
                    LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(resultDataset);
                }
                catch (Exception ex)
                {
                    this.ReportError("Error Building Result Dataset", ex);
                    Console.WriteLine("# Test Result - Unable to build Result Dataset (Test Indeterminate)");
                    testsEvaluationIndeterminate++;
                    testsIndeterminate++;
                    return 0;
                }
                Console.WriteLine();

                //Now compare the two datasets to see if the tests passes
                foreach (Uri u in resultDataset.GraphUris)
                {
                    if (dataset.HasGraph(u))
                    {
                        if (!resultDataset[u].Equals(dataset[u]))
                        {
                            this.ShowGraphs(dataset[u], resultDataset[u]);

                            Console.WriteLine("# Test Result - Expected Result Dataset Graph '" + this.ToSafeString(u) + "' is different from the Graph with that name in the Updated Dataset (Test Failed)");
                            testsEvaluationFailed++;
                            testsFailed++;
                            return -1;
                        }
                    }
                    else
                    {
                        Console.WriteLine("# Test Result - Expected Result Dataset has Graph '" + this.ToSafeString(u) + "' which is not present in the Updated Dataset (Test Failed)");
                        testsEvaluationFailed++;
                        testsFailed++;
                        return -1;
                    }
                }
                foreach (Uri u in dataset.GraphUris)
                {
                    if (!resultDataset.HasGraph(u))
                    {
                        Console.WriteLine("# Test Result - Updated Dataset has additional Graph '" + this.ToSafeString(u) + "' which is not present in the Expected Result Dataset (Test Failed)");
                    }
                }

                Console.WriteLine("# Test Result - Updated Dataset matches Expected Result Dataset (Test Passed)");
                testsEvaluationPassed++;
                testsPassed++;
                return 1;
            }
            catch (Exception ex)
            {
                this.ReportError("Unexpected Error", ex);
                Console.WriteLine("# Test Result - Unexpected Error (Test Failed)");
                testsEvaluationFailed++;
                testsFailed++;
                return -1;
            }
        }
        private void TestInsertDataThenDeleteDataCommit()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; DELETE DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            processor.ProcessCommandSet(cmds);

            Assert.IsTrue(dataset[TestGraphUri].IsEmpty, "Graph should be empty as the Flush() should persist first the insert then the delete");
        }
Пример #39
0
        public void SparqlUpdateMoveCommand3()
        {
            IGraph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = null;

            IGraph h = new Graph();
            FileLoader.Load(h, "Turtle.ttl");
            h.BaseUri = new Uri("http://example.org/destination");

            TripleStore store = new TripleStore();
            store.Add(g);
            store.Add(h);

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

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("MOVE DEFAULT TO GRAPH <http://example.org/destination>");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            processor.ProcessCommandSet(commands);

            g = store.HasGraph(null) ? store.Graph(null) : null;
            h = store.Graph(new Uri("http://example.org/destination"));
            Assert.IsFalse(h.IsEmpty, "Destination Graph should not be empty");
            Assert.IsFalse(g == null, "Default Graph should still exist");
            Assert.IsTrue(g.IsEmpty, "Source Graph (the Default Graph) should be Empty");

            Graph orig = new Graph();
            FileLoader.Load(orig, "InferenceTest.ttl");
            Assert.AreEqual(orig, h, "Destination Graph should be equal to the original contents of the Source Graph");
        }
Пример #40
0
        public void SparqlUpdateCopyCommand2()
        {
            IGraph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/source");

            IGraph h = new Graph();
            FileLoader.Load(h, "Turtle.ttl");
            h.BaseUri = null;

            TripleStore store = new TripleStore();
            store.Add(g);
            store.Add(h);

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

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("COPY GRAPH <http://example.org/source> TO DEFAULT");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            processor.ProcessCommandSet(commands);

            g = store.Graph(new Uri("http://example.org/source"));
            h = store.Graph(null);
            Assert.IsFalse(g.IsEmpty, "Source Graph should not be empty");
            Assert.IsFalse(h.IsEmpty, "Destination Graph should not be empty");
            Assert.AreEqual(g, h, "Graphs should now be equal");
        }
        private void TestInsertDataThenDropCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subject> <ex:predicate> <ex:object> } }; DROP GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            processor.ProcessCommandSet(cmds);

            Assert.IsFalse(dataset.HasGraph(TestGraphUri), "Graph should not exist as the Flush() should cause it to be removed from the Dataset");
        }
Пример #42
0
        public void SparqlUpdateInsertCommand()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();
            command.Namespaces.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            command.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            command.CommandText = "INSERT { ?s rdf:type ?class } WHERE { ?s a ?type . ?type rdfs:subClassOf+ ?class };";
            command.CommandText += "INSERT { ?s ?property ?value } WHERE {?s ?p ?value . ?p rdfs:subPropertyOf+ ?property };";
            command.CommandText += "INSERT { ?s rdf:type rdfs:Class } WHERE { ?s rdfs:subClassOf ?class };";
            command.CommandText += "INSERT { ?s rdf:type rdf:Property } WHERE { ?s rdfs:subPropertyOf ?property };";

            TripleStore store = new TripleStore();
            Graph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.Retract(g.Triples.Where(t => !t.IsGroundTriple));
            g.BaseUri = null;
            store.Add(g);

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds = parser.ParseFromString(command);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            processor.ProcessCommandSet(cmds);

            TestTools.ShowGraph(g);
            Console.WriteLine();

            //Now reload the test data and apply an RDFS reasoner over it
            //This should give us a Graph equivalent to the one created by the previous INSERT commands
            Graph h = new Graph();
            FileLoader.Load(h, "InferenceTest.ttl");
            h.Retract(h.Triples.Where(t => !t.IsGroundTriple));
            RdfsReasoner reasoner = new RdfsReasoner();
            reasoner.Apply(h);

            GraphDiffReport diff = h.Difference(g);
            if (!diff.AreEqual)
            {
                TestTools.ShowDifferences(diff);
            }

            Assert.AreEqual(h, g, "Graphs should be equal");            
        }
Пример #43
0
 /// <inheritdoc />
 void IUpdateableTripleStore.ExecuteUpdate(SparqlUpdateCommandSet updates)
 {
     lock (Locker)
     {
         LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(this);
         processor.ProcessCommandSet(updates);
         Write();
     }
 }
Пример #44
0
        public void SparqlDatasetDefaultGraphManagementWithUpdate3()
        {
            TripleStore store = new TripleStore();
            Graph g = new Graph();
            g.BaseUri = new Uri("http://example.org/graph");
            store.Add(g);
            Graph h = new Graph();
            h.BaseUri = new Uri("http://example.org/someOtherGraph");
            store.Add(h);

            InMemoryDataset dataset = new InMemoryDataset(store, h.BaseUri);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds = parser.ParseFromString("LOAD <http://www.dotnetrdf.org/configuration#> INTO GRAPH <http://example.org/graph>; LOAD <http://www.dotnetrdf.org/configuration#> INTO GRAPH <http://example.org/someOtherGraph>");

            processor.ProcessCommandSet(cmds);

            Assert.IsFalse(g.IsEmpty, "First Graph should not be empty as should have been filled by the first LOAD command");
            Assert.IsFalse(h.IsEmpty, "Second Graph should not be empty as should not have been filled by the second LOAD command");
            Assert.AreEqual(g, h, "Graphs should be equal");
        }
        private void TestInsertDataSequenceCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { } }; INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            processor.ProcessCommandSet(cmds);

            Assert.IsTrue(dataset.HasGraph(TestGraphUri), "Graph should exist");
            Assert.AreEqual(1, dataset[TestGraphUri].Triples.Count, "Expected 1 Triple");
        }
Пример #46
0
        public void SparqlUpdateInsertCommand4()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();
            command.Namespaces.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            command.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            command.CommandText = "INSERT { ?s rdf:type ?class } USING NAMED <http://example.org/temp> WHERE { GRAPH ?g { ?s a ?type . ?type rdfs:subClassOf+ ?class } };";
            command.CommandText += "INSERT { ?s ?property ?value } USING NAMED <http://example.org/temp> WHERE { GRAPH ?g { ?s ?p ?value . ?p rdfs:subPropertyOf+ ?property } };";
            command.CommandText += "INSERT { ?s rdf:type rdfs:Class } USING NAMED <http://example.org/temp> WHERE { GRAPH ?g { ?s rdfs:subClassOf ?class } };";
            command.CommandText += "INSERT { ?s rdf:type rdf:Property } USING NAMED <http://example.org/temp> WHERE { GRAPH ?g { ?s rdfs:subPropertyOf ?property } };";

            TripleStore store = new TripleStore();
            Graph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/temp");
            store.Add(g);

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds = parser.ParseFromString(command);
            InMemoryDataset dataset = new InMemoryDataset(store);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            dataset.SetDefaultGraph(store.Graph(null));
            processor.ProcessCommandSet(cmds);

            IGraph def = store.Graph(null);
            TestTools.ShowGraph(def);

            //Apply a RDFS reasoner over the original input and output it into another graph
            //Should be equivalent to the default Graph
            Graph h = new Graph();
            RdfsReasoner reasoner = new RdfsReasoner();
            reasoner.Apply(g, h);

            TestTools.ShowGraph(h);

            GraphDiffReport report = h.Difference(def);
            if (!report.AreEqual)
            {
                TestTools.ShowDifferences(report);

                Assert.IsTrue(report.RemovedTriples.Count() == 1, "Should have only 1 missing Triple (due to rdfs:domain inference which is hard to encode in an INSERT command)");
            }
        }
        private void TestDeleteDataThenInsertDataRollback()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();
            IGraph g = dataset.GetModifiableGraph(TestGraphUri);
            g.Assert(new Triple(g.CreateUriNode(new Uri("ex:subj")), g.CreateUriNode(new Uri("ex:pred")), g.CreateUriNode(new Uri("ex:obj"))));

            String updates = "DELETE DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; CREATE GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.Fail("Did not thrown a SparqlUpdateException as expected");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx, false);
            }

            Assert.IsFalse(dataset[TestGraphUri].IsEmpty, "Graph should not be empty as the Discard() should reverse first the insert then the delete so the end results should be the triple still being in the Graph");
        }
        private void TestDeleteDataThenInsertDataCommit()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();
            IGraph g = dataset.GetModifiableGraph(TestGraphUri);
            g.Assert(new Triple(g.CreateUriNode(new Uri("ex:subj")), g.CreateUriNode(new Uri("ex:pred")), g.CreateUriNode(new Uri("ex:obj"))));
            dataset.Flush();

            String updates = "DELETE DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            processor.ProcessCommandSet(cmds);

            Assert.IsFalse(dataset[TestGraphUri].IsEmpty, "Graph should not be empty as the Flush() should persist first the delete then the insert so the end results should be the triple still being in the Graph");
        }
        private void TestInsertDataThenDeleteDataRollback()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; DELETE DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; CREATE GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.Fail("Did not thrown a SparqlUpdateException as expected");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx, false);
            }

            Assert.IsTrue(dataset[TestGraphUri].IsEmpty, "Graph should be empty as the Discard() should reverse first the delete then the insert");
        }
Пример #50
0
        public void SparqlDatasetDefaultGraphManagementWithUpdate()
        {
            TripleStore store = new TripleStore();
            Graph g = new Graph();
            store.Add(g);
            Graph h = new Graph();
            h.BaseUri = new Uri("http://example.org/someOtherGraph");
            store.Add(h);

            InMemoryDataset dataset = new InMemoryDataset(store, h.BaseUri);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds = parser.ParseFromString("LOAD <http://www.dotnetrdf.org/configuration#>");

            processor.ProcessCommandSet(cmds);

            Assert.IsTrue(g.IsEmpty, "Graph with null URI (normally the default Graph) should be empty as the Default Graph for the Dataset should have been a named Graph so this Graph should not have been filled by the LOAD Command");
            Assert.IsFalse(h.IsEmpty, "Graph with name should be non-empty as it should have been the Default Graph for the Dataset and so filled by the LOAD Command");
        }
        private void TestDropGraphRollback()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "DROP GRAPH <" + TestGraphUri.ToString() + ">; DROP GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.Fail("Did not thrown a SparqlUpdateException as expected");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx, false);
            }

            Assert.IsTrue(dataset.HasGraph(TestGraphUri), "Graph should exist as the Discard() should ensure it was still in the Dataset");
        }
Пример #52
0
        public void SparqlDatasetDefaultGraphManagementWithUpdate5()
        {
            TripleStore store = new TripleStore();
            Graph g = new Graph();
            g.BaseUri = new Uri("http://example.org/graph");
            store.Add(g);
            Graph h = new Graph();
            h.BaseUri = new Uri("http://example.org/someOtherGraph");
            store.Add(h);

            InMemoryDataset dataset = new InMemoryDataset(store, h.BaseUri);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds = parser.ParseFromString("LOAD <http://www.dotnetrdf.org/configuration#>; WITH <http://example.org/graph> INSERT { ?s a ?type } USING <http://example.org/someOtherGraph> WHERE { ?s a ?type }; DELETE WHERE { ?s a ?type }");

            processor.ProcessCommandSet(cmds);

            Assert.IsFalse(g.IsEmpty, "First Graph should not be empty as should have been filled by the INSERT command");
            Assert.IsFalse(h.IsEmpty, "Second Graph should not be empty as should not have been filled by the  LOAD command");
            Assert.IsFalse(h.HasSubGraph(g), "First Graph should not be a subgraph of the Second Graph as the DELETE should have eliminated the subgraph relationship");
        }
        private void TestDropGraphCommit()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "DROP GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds = parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            processor.ProcessCommandSet(cmds);

            Assert.IsFalse(dataset.HasGraph(TestGraphUri), "Graph should not exist");
        }
        private void TestCreateGraphRollbackWithoutAutoCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "CREATE GRAPH <" + TestGraphUri.ToString() + ">; CREATE GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            processor.AutoCommit = false;
            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.Fail("Did not throw a SparqlUpdateException as expected");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx, false);
            }

            Assert.IsTrue(dataset.HasGraph(TestGraphUri), "Graph should exist as the Transaction has not been committed yet as Auto-Commit is off");

            //Try to Flush() which should error
            try
            {
                processor.Flush();
                Assert.Fail("Did not throw a SparqlUpdateException as expected on call to Flush()");
            }
            catch (SparqlUpdateException upEx)
            {
                Console.WriteLine("Threw error when attempting to Flush() as expected");
                TestTools.ReportError("Update Exception", upEx, false);
            }
            
            //Now discard
            processor.Discard();
            Assert.IsFalse(dataset.HasGraph(TestGraphUri), "Graph should not exist as the Discard() should cause it to be removed from the Dataset");

        }
Пример #55
0
        public void SparqlUpdateInsertCommand3()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();
            command.Namespaces.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            command.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            command.CommandText = "INSERT { ?s rdf:type ?class } USING NAMED <http://example.org/temp> WHERE { ?s a ?type . ?type rdfs:subClassOf+ ?class };";
            command.CommandText += "INSERT { ?s ?property ?value } USING NAMED <http://example.org/temp> WHERE {?s ?p ?value . ?p rdfs:subPropertyOf+ ?property };";
            command.CommandText += "INSERT { ?s rdf:type rdfs:Class } USING NAMED <http://example.org/temp> WHERE { ?s rdfs:subClassOf ?class };";
            command.CommandText += "INSERT { ?s rdf:type rdf:Property } USING NAMED <http://example.org/temp> WHERE { ?s rdfs:subPropertyOf ?property };";

            TripleStore store = new TripleStore();
            Graph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/temp");
            store.Add(g);

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds = parser.ParseFromString(command);
            InMemoryDataset dataset = new InMemoryDataset(store);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            dataset.SetDefaultGraph(store.Graph(null));
            processor.ProcessCommandSet(cmds);

            IGraph def = store.Graph(null);
            TestTools.ShowGraph(def);
            Assert.IsTrue(def.IsEmpty, "Graph should be empty as the commands only used USING NAMED (so shouldn't have changed the dataset) and the Active Graph for the dataset was empty so there should have been nothing matched to generate insertions from");
        }
        private void TestCreateDropSequenceRollback2()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "DROP GRAPH <" + TestGraphUri.ToString() + ">; CREATE GRAPH <" + TestGraphUri.ToString() + ">; DROP GRAPH <" + TestGraphUri.ToString() + ">; DROP GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.Fail("Expected SPARQL Update Exception was not thrown");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx, false);
            }

            Assert.IsTrue(dataset.HasGraph(TestGraphUri), "Graph should not exist");
        }
Пример #57
0
        public void SparqlUpdateAddCommand()
        {
            IGraph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/source");

            IGraph h = new Graph();
            FileLoader.Load(h, "Turtle.ttl");
            h.BaseUri = new Uri("http://example.org/destination");

            TripleStore store = new TripleStore();
            store.Add(g);
            store.Add(h);

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

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("ADD GRAPH <http://example.org/source> TO GRAPH <http://example.org/destination>");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            processor.ProcessCommandSet(commands);

            g = store.Graph(new Uri("http://example.org/source"));
            h = store.Graph(new Uri("http://example.org/destination"));
            Assert.IsFalse(g.IsEmpty, "Source Graph should not be empty");
            Assert.IsFalse(h.IsEmpty, "Destination Graph should not be empty");
            Assert.IsTrue(h.HasSubGraph(g), "Destination Graph should have Source Graph as a subgraph");
        }
        private void TestLoadCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "LOAD <http://www.dotnetrdf.org/configuration#> INTO GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            processor.ProcessCommandSet(cmds);

            Assert.IsTrue(dataset.HasGraph(TestGraphUri), "Graph should exist");
        }
Пример #59
0
        /// <summary>
        /// Constructs Update function for dotNetRDF
        /// </summary>
        /// <returns>Update function</returns>
        public Func<string, object> GetUpdateFunction()
        {
            Func<string, object> func = update =>
            {
                var updProcessor = new LeviathanUpdateProcessor(Dataset);
                updProcessor.ProcessCommandSet(new SparqlUpdateParser().ParseFromString(update));
                return 0;
            };

            return func;
        }