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(); } } }
private Uri ReadQuadFormat(TextReader reader, Uri graph, RdfSerializationFormat format, bool update) { using (VirtuosoManager manager = new VirtuosoManager(CreateConnectionString())) { using (VDS.RDF.ThreadSafeTripleStore store = new VDS.RDF.ThreadSafeTripleStore()) { VDS.RDF.Parsing.TriGParser parser = new TriGParser(); parser.Load(store, reader); foreach (var g in store.Graphs) { if (update) { manager.UpdateGraph(g.BaseUri, g.Triples, new Triple[] { }); } else { manager.SaveGraph(g); } } } } return(graph); }
private Uri ReadRemoteTripleFormat(Uri graph, Uri location, RdfSerializationFormat format) { using (VirtuosoManager manager = new VirtuosoManager(CreateConnectionString())) { using (VDS.RDF.Graph g = new VDS.RDF.Graph()) { UriLoader.Load(g, location); g.BaseUri = graph; manager.SaveGraph(g); } } return(graph); }
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 StorageVirtuosoTightSaveLoop() { VirtuosoManager virtuoso = VirtuosoTest.GetConnection(); try { for (int i = 0; i < 1000; i++) { IGraph g = new Graph(); g.Assert(g.CreateBlankNode(), g.CreateUriNode("rdf:type"), g.CreateUriNode(new Uri("http://example.org/Type"))); g.BaseUri = new Uri("http://example.org/graphs/" + i); virtuoso.SaveGraph(g); } } finally { virtuoso.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(); } } }
private Uri ReadTripleFormat(TextReader reader, Uri graphUri, RdfSerializationFormat format, bool update) { using (VirtuosoManager manager = new VirtuosoManager(CreateConnectionString())) { using (VDS.RDF.Graph graph = new VDS.RDF.Graph()) { dotNetRDFStore.TryParse(reader, graph, format); graph.BaseUri = graphUri; if (update) { manager.UpdateGraph(graphUri, graph.Triples, new Triple[] { }); } else { manager.SaveGraph(graph); } } } return(graphUri); }
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 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(); } } }