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 StorageVirtuosoBlankNodeInsert() { VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Graph g = new Graph(); Triple t = new Triple(g.CreateBlankNode(), g.CreateUriNode("rdf:type"), g.CreateUriNode(UriFactory.Create("http://example.org/object"))); manager.UpdateGraph("http://localhost/insertBNodeTest", t.AsEnumerable(), null); Object results = manager.Query("ASK WHERE { GRAPH <http://localhost/insertBNodeTest> { ?s a <http:///example.org/object> } }"); if (results is SparqlResultSet) { TestTools.ShowResults(results); Assert.IsTrue(((SparqlResultSet)results).Result, "Expected a true result"); } else { Assert.Fail("Didn't get a SPARQL Result Set as expected"); } } finally { if (manager != null) { manager.Dispose(); } } }
public void StoragePersistentTripleStoreVirtuosoQueryAsk() { VirtuosoManager virtuoso = VirtuosoTest.GetConnection(); this.TestQueryAsk(virtuoso, "ASK WHERE { ?s a ?type }", true); this.TestQueryAsk(virtuoso, "ASK WHERE { ?s <http://example.org/noSuchThing> ?o }", false); }
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); }
public fclsGraphBrowser() { InitializeComponent(); //Connect to Virtuoso this._manager = new VirtuosoManager(Properties.Settings.Default.Server, Properties.Settings.Default.Port, VirtuosoQuadStoreDB, Properties.Settings.Default.Username, Properties.Settings.Default.Password); //Add some fake test data DataTable data = new DataTable(); data.Columns.Add("Subject"); data.Columns.Add("Predicate"); data.Columns.Add("Object"); data.Columns["Subject"].DataType = typeof(INode); data.Columns["Predicate"].DataType = typeof(INode); data.Columns["Object"].DataType = typeof(INode); Graph g = new Graph(); DataRow row = data.NewRow(); row["Subject"] = g.CreateUriNode(new Uri("http://example.org/subject")); row["Predicate"] = g.CreateUriNode(new Uri("http://example.org/predicate")); row["Object"] = g.CreateUriNode(new Uri("http://example.org/object")); data.Rows.Add(row); this.BindGraph(data); }
/// <summary> /// Attempts to load an Object of the given type identified by the given Node and returned as the Type that this loader generates /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Created Object</param> /// <returns>True if the loader succeeded in creating an Object</returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; String server, port, db, user, pwd; int p = -1; //Create the URI Nodes we're going to use to search for things INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer), propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase); //Get Server and Database details server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { server = "localhost"; } db = ConfigurationLoader.GetConfigurationString(g, objNode, propDb); if (db == null) { db = VirtuosoManager.DefaultDB; } //Get Port port = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPort)); if (!Int32.TryParse(port, out p)) { p = VirtuosoManager.DefaultPort; } //Get user credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user == null || pwd == null) { return(false); } //Based on this information create a Manager if possible switch (targetType.FullName) { case NonNativeVirtuosoManager: obj = new NonNativeVirtuosoManager(server, p, db, user, pwd); break; case Virtuoso: //Get Server settings server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } obj = new VirtuosoManager(server, p, db, user, pwd); break; } return(obj != null); }
/// <summary> /// starts connection with the server /// </summary> public static void startConnection() { //Initiating the manager(to be added to constructor?) if (!isConnectionStarted) { //manager = new VirtuosoManager("Server=localhost;Uid=dba;pwd=dba;Connection Timeout=500"); manager = new VirtuosoManager("localhost", 1111, "DB", "dba", "dba"); isConnectionStarted = true; } }
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 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 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 StorageVirtuosoBadQuery() { VirtuosoManager virtuoso = VirtuosoTest.GetConnection(); try { virtuoso.Query("Bad query"); Assert.Fail("Expected an error"); } catch { //Expected so can be ignored Assert.IsFalse(virtuoso.HasOpenConnection, "Connection should be closed"); Assert.IsFalse(virtuoso.HasActiveTransaction, "Should be no active transaction"); } finally { virtuoso.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 StorageVirtuosoBadUpdate() { VirtuosoManager virtuoso = VirtuosoTest.GetConnection(); try { virtuoso.Update("Bad update"); Assert.True(false, "Expected an error"); } catch { //Expected so can be ignored Assert.False(virtuoso.HasOpenConnection, "Connection should be closed"); Assert.False(virtuoso.HasActiveTransaction, "Should be no active transaction"); } finally { virtuoso.Dispose(); } }
public void StorageVirtuosoNativeUpdate() { VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Console.WriteLine("Got the Virtuoso Manager OK"); Object result = null; Console.WriteLine("Now we'll delete a Triple"); //Try a DELETE DATA manager.Update("DELETE DATA FROM <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}"); Console.WriteLine("Triple with subject <http://example.org/seven> should be missing - ASKing for it..."); //Try a SELECT query result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("Now we'll add the Triple back again"); //Try a INSERT DATA manager.Update("INSERT DATA INTO <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}"); Console.WriteLine("Triple with subject <http://example.org/seven> should be restored - ASKing for it again..."); //Try a SELECT query result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}"); CheckQueryResult(result, true); } 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(); } } }
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 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 StorageVirtuosoNativeQueryBifContains2() { VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Console.WriteLine("Got the Virtuoso Manager OK"); Object result = null; //Try a CONSTRUCT query result = manager.Query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . ?o bif:contains 'example' }"); CheckQueryResult(result, false); } finally { if (manager != null) { manager.Dispose(); } } }
public void StorageVirtuosoNativeQueryAndUpdate() { NTriplesFormatter formatter = new NTriplesFormatter(); VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Console.WriteLine("Got the Virtuoso Manager OK"); Object result = null; Console.WriteLine("ASKing if there's any Triples"); //Try an ASK query result = manager.Query("ASK {?s ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("CONSTRUCTing a Graph"); //Try a CONSTRUCT result = manager.Query("CONSTRUCT {?s ?p ?o} FROM <http://example.org/> WHERE {?s ?p ?o}"); CheckQueryResult(result, false); Console.WriteLine("DESCRIBEing a resource"); //Try a DESCRIBE result = manager.Query("DESCRIBE <http://example.org/one>"); CheckQueryResult(result, false); //Try another DESCRIBE result = manager.Query("DESCRIBE <http://example.org/noSuchThing>"); CheckQueryResult(result, false); Console.WriteLine("SELECTing the same Graph"); //Try a SELECT query result = manager.Query("SELECT * FROM <http://example.org/> WHERE {?s ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("SELECTing the same Graph using Project Expressions"); //Try a SELECT query result = manager.Query("SELECT (?s AS ?Subject) (?P as ?Predicate) (?o AS ?Object) FROM <http://example.org/> WHERE {?s ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("Now we'll delete a Triple"); //Try a DELETE DATA manager.Update("DELETE DATA { GRAPH <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".} }"); Console.WriteLine("Triple with subject <http://example.org/seven> should be missing - ASKing for it..."); //Try a SELECT query result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("Now we'll add the Triple back again"); //Try a INSERT DATA manager.Update("INSERT DATA INTO <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}"); Console.WriteLine("Triple with subject <http://example.org/seven> should be restored - ASKing for it again..."); //Try a SELECT query result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("DESCRIBE things which are classes"); //Try a DESCRIBE result = manager.Query("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> DESCRIBE ?s WHERE {?s a rdfs:Class} LIMIT 1"); CheckQueryResult(result, false); Console.WriteLine("Another CONSTRUCT"); //Try a CONSTRUCT result = manager.Query("CONSTRUCT {?s ?p ?o} FROM <http://example.org/> WHERE {?s ?p ?o}"); CheckQueryResult(result, false); Console.WriteLine("COUNT subjects"); //Try a SELECT using an aggregate function result = manager.Query("SELECT COUNT(?s) FROM <http://example.org/> WHERE {?s ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("AVG integer objects"); //Try another SELECT using an aggregate function result = manager.Query("SELECT AVG(?o) FROM <http://example.org/> WHERE {?s ?p ?o. FILTER(DATATYPE(?o) = <http://www.w3.org/2001/XMLSchema#integer>)}"); CheckQueryResult(result, true); Console.WriteLine("AVG decimal objects"); //Try yet another SELECT using an aggregate function result = manager.Query("SELECT AVG(?o) FROM <http://example.org/> WHERE {?s ?p ?o. FILTER(DATATYPE(?o) = <http://www.w3c.org/2001/XMLSchema#decimal>)}"); CheckQueryResult(result, true); } finally { if (manager != null) { manager.Dispose(); } } }
public void ParsingWriteToStoreHandlerBNodesAcrossBatchesVirtuoso() { VirtuosoManager virtuoso = VirtuosoTest.GetConnection(); this.TestWriteToStoreHandlerWithBNodes(virtuoso); }
public void ParsingWriteToStoreHandlerDatasetsVirtuoso() { VirtuosoManager virtuoso = VirtuosoTest.GetConnection(); this.TestWriteToStoreDatasetsHandler(virtuoso); }
public void StoragePersistentTripleStoreVirtuosoUpdateUnsynced() { VirtuosoManager virtuoso = VirtuosoTest.GetConnection(); Assert.Throws <SparqlUpdateException>(() => this.TestUpdateUnsynced(virtuoso)); }
public void StoragePersistentTripleStoreVirtuosoUpdate() { VirtuosoManager virtuoso = VirtuosoTest.GetConnection(); this.TestUpdate(virtuoso); }
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(); } } }
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 StorageVirtuosoConfigSerialization() { NTriplesFormatter formatter = new NTriplesFormatter(); VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Graph g = new Graph(); INode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); INode dnrType = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyType)); INode objFactory = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.ClassObjectFactory)); INode virtFactory = g.CreateLiteralNode("VDS.RDF.Configuration.VirtuosoObjectFactory, dotNetRDF.Data.Virtuoso"); INode genericManager = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.ClassStorageProvider)); INode virtManager = g.CreateLiteralNode("VDS.RDF.Storage.VirtuosoManager, dotNetRDF.Data.Virtuoso"); //Serialize Configuration ConfigurationSerializationContext context = new ConfigurationSerializationContext(g); manager.SerializeConfiguration(context); Console.WriteLine("Serialized Configuration"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); //Ensure that it was serialized INode factory = g.GetTriplesWithPredicateObject(rdfType, objFactory).Select(t => t.Subject).FirstOrDefault(); Assert.IsNotNull(factory, "Should be an object factory in the serialized configuration"); Assert.IsTrue(g.ContainsTriple(new Triple(factory, dnrType, virtFactory)), "Should contain a Triple declaring the dnr:type to be the Virtuoso Object factory type"); INode objNode = g.GetTriplesWithPredicateObject(rdfType, genericManager).Select(t => t.Subject).FirstOrDefault(); Assert.IsNotNull(objNode, "Should be a generic manager in the serialized configuration"); Assert.IsTrue(g.ContainsTriple(new Triple(objNode, dnrType, virtManager)), "Should contain a Triple declaring the dnr:type to be the Virtuoso Manager type"); //Serialize again manager.SerializeConfiguration(context); Console.WriteLine("Serialized Configuration (after 2nd pass)"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); //Ensure that object factory has not been serialized again Assert.AreEqual(1, g.GetTriplesWithPredicateObject(rdfType, objFactory).Count(), "Should only be 1 Object Factory registered even after a 2nd serializer pass"); //Now try to load the object ConfigurationLoader.AutoConfigureObjectFactories(g); Object loadedObj = ConfigurationLoader.LoadObject(g, objNode); if (loadedObj is VirtuosoManager) { Assert.AreEqual(manager.ToString(), loadedObj.ToString(), "String forms should be equal"); } else { Assert.Fail("Returned an object of type '" + loadedObj.GetType().FullName + "' when deserializing"); } } finally { if (manager != null) { manager.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(); } } }