public void StorageVirtuosoLoadGraphWithNullHandler() { NTriplesFormatter formatter = new NTriplesFormatter(); VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Console.WriteLine("Got the Virtuoso Manager OK"); //Add the Test Date to Virtuoso Graph testData = new Graph(); FileLoader.Load(testData, "resources\\Turtle.ttl"); testData.BaseUri = new Uri("http://example.org/virtuoso/tests/null"); manager.SaveGraph(testData); Console.WriteLine("Saved the Test Data to Virtuoso"); NullHandler handler = new NullHandler(); manager.LoadGraph(handler, testData.BaseUri); } finally { if (manager != null) { manager.Dispose(); } } }
public void StorageVirtuosoBlankNodeDelete() { //First ensure data is present in the store VirtuosoManager manager = VirtuosoTest.GetConnection(); try { manager.DeleteGraph("http://localhost/deleteBNodeTest"); Graph g = new Graph(); Triple t = new Triple(g.CreateBlankNode(), g.CreateUriNode("rdf:type"), g.CreateUriNode(UriFactory.Create("http://example.org/object"))); g.Assert(t); manager.UpdateGraph("http://localhost/deleteBNodeTest", t.AsEnumerable(), null); Object results = manager.Query("ASK WHERE { GRAPH <http://localhost/deleteBNodeTest> { ?s a <http://example.org/object> } }"); if (results is SparqlResultSet) { TestTools.ShowResults(results); Assert.IsTrue(((SparqlResultSet)results).Result, "Expected a true result"); //Now we've ensured data is present we can first load the graph and then try to delete the given triple Graph h = new Graph(); manager.LoadGraph(h, "http://localhost/deleteBNodeTest"); Assert.AreEqual(g, h, "Graphs should be equal"); //Then we can go ahead and delete the triples from this graph manager.UpdateGraph("http://localhost/deleteBNodeTest", null, h.Triples); Graph i = new Graph(); manager.LoadGraph(i, "http://localhost/deleteBNodeTest"); Assert.IsTrue(i.IsEmpty, "Graph should be empty"); Assert.AreNotEqual(h, i); Assert.AreNotEqual(g, i); } else { Assert.Fail("Didn't get a SPARQL Result Set as expected"); } } finally { if (manager != null) { manager.Dispose(); } } }
public void StorageVirtuosoRelativeUris() { VirtuosoManager virtuoso = VirtuosoTest.GetConnection(); try { //Load in our Test Graph Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); g.BaseUri = new Uri("/storage/virtuoso/relative", UriKind.Relative); virtuoso.SaveGraph(g); // Load it back out again Graph h = new Graph(); virtuoso.LoadGraph(h, g.BaseUri); Assert.IsFalse(h.IsEmpty, "Graph loaded via relative URI should not be empty"); Assert.AreEqual(g, h); Console.WriteLine("Loading with relative URI works OK"); Console.WriteLine(); // Load it back out using marshalled URI Uri u = new Uri("virtuoso-relative:/storage/virtuoso/relative"); h = new Graph(); virtuoso.LoadGraph(h, u); Assert.IsFalse(h.IsEmpty, "Graph loaded via marshalled URI should not be empty"); Assert.AreEqual(g, h); Console.WriteLine("Loading with marshalled URI works OK"); } finally { virtuoso.Dispose(); } }
public void StorageVirtuosoUpdateGraph() { VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Console.WriteLine("Got the Virtuoso Manager OK"); //Make some Triples to add to the Graph Graph g = new Graph(); g.BaseUri = new Uri("http://example.org/"); g.NamespaceMap.AddNamespace(String.Empty, g.BaseUri); List <Triple> additions = new List <Triple>(); additions.Add(new Triple(g.CreateUriNode(":seven"), g.CreateUriNode("rdf:type"), g.CreateUriNode(":addedTriple"))); List <Triple> removals = new List <Triple>(); removals.Add(new Triple(g.CreateUriNode(":five"), g.CreateUriNode(":property"), g.CreateUriNode(":value"))); //Try to Update manager.UpdateGraph(g.BaseUri, additions, removals); Console.WriteLine("Updated OK"); //Retrieve to see what's in the Graph Graph h = new Graph(); manager.LoadGraph(h, g.BaseUri); Console.WriteLine("Retrieved OK"); Console.WriteLine("Graph contents are:"); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString()); } Assert.IsTrue(h.Triples.Contains(additions[0]), "Added Triple should be in the retrieved Graph"); Assert.IsFalse(h.Triples.Contains(removals[0]), "Removed Triple should not be in the retrieved Graph"); } finally { if (manager != null) { manager.Dispose(); } } }
public void StorageVirtuosoQueryRegex() { VirtuosoManager manager = VirtuosoTest.GetConnection(); try { //Create the Test Graph Graph g = new Graph(); g.BaseUri = new Uri("http://example.org/VirtuosoRegexTest"); INode subj1 = g.CreateUriNode(new Uri("http://example.org/one")); INode subj2 = g.CreateUriNode(new Uri("http://example.org/two")); INode pred = g.CreateUriNode(new Uri("http://example.org/predicate")); INode obj1 = g.CreateLiteralNode("search term"); INode obj2 = g.CreateLiteralNode("no term"); g.Assert(subj1, pred, obj1); g.Assert(subj2, pred, obj2); manager.SaveGraph(g); Graph h = new Graph(); manager.LoadGraph(h, g.BaseUri); Assert.AreEqual(g, h, "Graphs should be equal"); String query = "SELECT * FROM <" + g.BaseUri.ToString() + "> WHERE { ?s ?p ?o . FILTER(REGEX(STR(?o), 'search', 'i')) }"; SparqlResultSet results = manager.Query(query) as SparqlResultSet; if (results == null) { Assert.Fail("Did not get a Result Set as expected"); } Console.WriteLine("Results obtained via VirtuosoManager.Query()"); TestTools.ShowResults(results); Assert.AreEqual(1, results.Count); SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://localhost:8890/sparql")); SparqlResultSet results2 = endpoint.QueryWithResultSet(query); Console.WriteLine("Results obtained via SparqlRemoteEndpoint.QueryWithResultSet()"); TestTools.ShowResults(results2); Assert.AreEqual(1, results2.Count); } finally { if (manager != null) { manager.Dispose(); } } }
public void StorageVirtuosoEncoding() { //Get the Virtuoso Manager VirtuosoManager manager = VirtuosoTest.GetConnection(); try { //Make the Test Graph Graph g = new Graph(); g.BaseUri = new Uri("http://example.org/VirtuosoEncodingTest"); IUriNode encodedString = g.CreateUriNode(new Uri("http://example.org/encodedString")); ILiteralNode encodedText = g.CreateLiteralNode("William Jørgensen"); g.Assert(new Triple(g.CreateUriNode(), encodedString, encodedText)); Console.WriteLine("Test Graph created OK"); TestTools.ShowGraph(g); //Save to Virtuoso Console.WriteLine(); Console.WriteLine("Saving to Virtuoso"); manager.SaveGraph(g); //Load back from Virtuoso Console.WriteLine(); Console.WriteLine("Retrieving from Virtuoso"); Graph h = new Graph(); manager.LoadGraph(h, new Uri("http://example.org/VirtuosoEncodingTest")); TestTools.ShowGraph(h); Assert.AreEqual(g, h, "Graphs should be equal"); } finally { if (manager != null) { manager.Dispose(); } } }
public override void Write(Stream fs, Uri graph, RdfSerializationFormat format) { using (VirtuosoManager manager = new VirtuosoManager(CreateConnectionString())) { using (VDS.RDF.Graph g = new VDS.RDF.Graph()) { manager.LoadGraph(g, graph); StreamWriter streamWriter = new StreamWriter(fs, Encoding.UTF8); switch (format) { case RdfSerializationFormat.RdfXml: { VDS.RDF.Writing.RdfXmlWriter xmlWriter = new VDS.RDF.Writing.RdfXmlWriter(); xmlWriter.Save(g, streamWriter); break; } } } } }
public void StorageVirtuosoLoadGraph() { NTriplesFormatter formatter = new NTriplesFormatter(); VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Console.WriteLine("Got the Virtuoso Manager OK"); //Add the Test Date to Virtuoso Graph testData = new Graph(); FileLoader.Load(testData, @"resources\MergePart1.ttl"); testData.BaseUri = new Uri("http://localhost/VirtuosoTest"); manager.SaveGraph(testData); testData = new Graph(); FileLoader.Load(testData, @"resources\Turtle.ttl"); testData.BaseUri = new Uri("http://localhost/TurtleImportTest"); manager.SaveGraph(testData); Console.WriteLine("Saved the Test Data to Virtuoso"); //Try loading it back again Graph g = new Graph(); manager.LoadGraph(g, "http://localhost/VirtuosoTest"); Console.WriteLine("Load Operation completed without errors"); Assert.AreNotEqual(0, g.Triples.Count); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); Console.WriteLine("Loading a larger Graph"); Graph h = new Graph(); manager.LoadGraph(h, "http://localhost/TurtleImportTest"); Console.WriteLine("Load operation completed without errors"); Assert.AreNotEqual(0, h.Triples.Count); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); Console.WriteLine("Loading same Graph again to ensure loading is repeatable"); Graph i = new Graph(); manager.LoadGraph(i, "http://localhost/TurtleImportTest"); Console.WriteLine("Load operation completed without errors"); Assert.AreEqual(h.Triples.Count, i.Triples.Count); Assert.AreEqual(h, i); } finally { if (manager != null) { manager.Dispose(); } } }
public void StorageVirtuosoBlankNodePersistence() { //Create our Test Graph Graph g = new Graph(); g.BaseUri = new Uri("http://example.org/bnodes/"); g.NamespaceMap.AddNamespace(String.Empty, g.BaseUri); IBlankNode b = g.CreateBlankNode("blank"); IUriNode rdfType = g.CreateUriNode("rdf:type"); IUriNode bnode = g.CreateUriNode(":BlankNode"); g.Assert(new Triple(b, rdfType, bnode)); Assert.AreEqual(1, g.Triples.Count, "Should only be 1 Triple in the Test Graph"); //Connect to Virtuoso VirtuosoManager manager = VirtuosoTest.GetConnection(); try { //Save Graph manager.SaveGraph(g); //Retrieve Graph h = new Graph(); Graph i = new Graph(); manager.LoadGraph(h, g.BaseUri); manager.LoadGraph(i, g.BaseUri); Assert.AreEqual(1, h.Triples.Count, "Retrieved Graph should only contain 1 Triple"); Assert.AreEqual(1, i.Triples.Count, "Retrieved Graph should only contain 1 Triple"); Console.WriteLine("Contents of Retrieved Graph:"); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString()); } Console.WriteLine(); TestTools.CompareGraphs(h, i, true); //Save back again manager.SaveGraph(h); //Retrieve again Graph j = new Graph(); manager.LoadGraph(j, g.BaseUri); Console.WriteLine("Contents of Retrieved Graph (Retrieved after saving original Retrieval):"); foreach (Triple t in j.Triples) { Console.WriteLine(t.ToString()); } Console.WriteLine(); TestTools.CompareGraphs(h, j, false); TestTools.CompareGraphs(i, j, false); //Save back yet again manager.SaveGraph(j); //Retrieve yet again Graph k = new Graph(); manager.LoadGraph(k, g.BaseUri); Console.WriteLine("Contents of Retrieved Graph (Retrieved after saving second Retrieval):"); foreach (Triple t in k.Triples) { Console.WriteLine(t.ToString()); } Console.WriteLine(); TestTools.CompareGraphs(j, k, false); } finally { if (manager != null) { manager.Dispose(); } } }
public void StorageVirtuosoDeleteGraph() { VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Console.WriteLine("Got the Virtuoso Manager OK"); //Load in our Test Graph TurtleParser ttlparser = new TurtleParser(); Graph g = new Graph(); ttlparser.Load(g, "resources\\Turtle.ttl"); g.BaseUri = new Uri("http://example.org/deleteMe"); Console.WriteLine(); Console.WriteLine("Loaded Test Graph OK"); Console.WriteLine("Test Graph contains:"); Assert.IsFalse(g.IsEmpty, "Test Graph should be non-empty"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString()); } Console.WriteLine(); //Try to save to Virtuoso manager.SaveGraph(g); Console.WriteLine("Saved OK"); Console.WriteLine(); //Try to retrieve Graph h = new Graph(); manager.LoadGraph(h, "http://example.org/deleteMe"); Assert.IsFalse(h.IsEmpty, "Retrieved Graph should be non-empty"); Console.WriteLine("Retrieved the Graph from Virtuoso OK"); Console.WriteLine("Retrieved Graph contains:"); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString()); } //Try to delete manager.DeleteGraph("http://example.org/deleteMe"); Graph i = new Graph(); manager.LoadGraph(i, "http://example.org/deleteMe"); Assert.IsTrue(i.IsEmpty, "Retrieved Graph should be empty as it should have been deleted from the Store"); } finally { if (manager != null) { manager.Dispose(); } } }
public void StorageVirtuosoSaveGraph() { NTriplesFormatter formatter = new NTriplesFormatter(); VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Console.WriteLine("Got the Virtuoso Manager OK"); //Load in our Test Graph Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); g.BaseUri = new Uri("http://example.org/storage/virtuoso/save"); Console.WriteLine(); Console.WriteLine("Loaded Test Graph OK"); Console.WriteLine("Test Graph contains:"); Assert.IsFalse(g.IsEmpty, "Test Graph should be non-empty"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); //Try to save to Virtuoso manager.SaveGraph(g); Console.WriteLine("Saved OK"); Console.WriteLine(); //Try to retrieve Graph h = new Graph(); manager.LoadGraph(h, g.BaseUri); Assert.IsFalse(h.IsEmpty, "Retrieved Graph should be non-empty"); Console.WriteLine("Retrieved the Graph from Virtuoso OK"); Console.WriteLine("Retrieved Graph contains:"); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString(formatter)); } Assert.AreEqual(g.Triples.Count, h.Triples.Count, "Graph should have same number of Triples before and after saving"); GraphDiffReport diff = h.Difference(g); if (!diff.AreEqual) { TestTools.ShowDifferences(diff); } Console.WriteLine(); Assert.AreEqual(g, h, "Graphs should be equal"); } finally { if (manager != null) { manager.Dispose(); } } }