public void StorageStardogLoadNamedGraph() { StardogConnector stardog = StardogTests.GetConnection(); // Ensure graph exists Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); g.BaseUri = new Uri("http://example.org/graph"); stardog.SaveGraph(g); // Load it back from the store Graph h = new Graph(); stardog.LoadGraph(h, new Uri("http://example.org/graph")); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString(formatter)); } Assert.False(h.IsEmpty); Assert.Equal(g, h); }
public void StorageStardogReasoningByQuery2() { StardogConnector stardog = StardogTests.GetConnection(); if (stardog.Reasoning == StardogReasoningMode.DatabaseControlled) { throw new SkipTestException( "Version of Stardog being tested does not support configuring reasoning mode at connection level"); } Graph g = new Graph(); g.LoadFromFile("resources\\stardog-reasoning-test.rdf"); g.BaseUri = new Uri("http://www.reasoningtest.com/"); stardog.SaveGraph(g); String query = "Select ?building where { ?building <http://www.reasoningtest.com#hasLocation> ?room.}"; Console.WriteLine(query); Console.WriteLine(); SparqlResultSet resultsWithNoReasoning = stardog.Query(query, false) as SparqlResultSet; Assert.Null(resultsWithNoReasoning); if (resultsWithNoReasoning != null) { Console.WriteLine("Results With No Reasoning"); Assert.True(false, "There should not be any reasoning results !"); } else { Assert.True(true, "No SPARQL Results returned ! Success."); } }
public void StorageStardogReasoningByQuery1() { StardogConnector stardog = StardogTests.GetConnection(); Skip.If(stardog.Reasoning == StardogReasoningMode.DatabaseControlled, "Version of Stardog being tested does not support configuring reasoning mode at connection level"); Graph g = new Graph(); g.LoadFromFile("resources\\stardog-reasoning-test.rdf"); g.BaseUri = new Uri("http://www.reasoningtest.com/"); stardog.SaveGraph(g); String query = "Select ?building where { ?building <http://www.reasoningtest.com#hasLocation> ?room.}"; Console.WriteLine(query); Console.WriteLine(); SparqlResultSet resultsWithReasoning = stardog.Query(query, true) as SparqlResultSet; Assert.NotNull(resultsWithReasoning); if (resultsWithReasoning != null) { Console.WriteLine("Results With Reasoning"); TestTools.ShowResults(resultsWithReasoning); Assert.True(true, "Reasoning By Query OK !"); } else { Assert.True(false, "Did not get a SPARQL Result Set as expected"); } }
public void StorageStardogSaveToNamedGraphOverwrite() { StardogConnector stardog = StardogTests.GetConnection(); Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); g.BaseUri = new Uri("http://example.org/namedGraph"); stardog.SaveGraph(g); Graph h = new Graph(); stardog.LoadGraph(h, new Uri("http://example.org/namedGraph")); Assert.Equal(g, h); Graph i = new Graph(); i.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.LeviathanFunctionLibrary.ttl"); i.BaseUri = new Uri("http://example.org/namedGraph"); stardog.SaveGraph(i); Graph j = new Graph(); stardog.LoadGraph(j, "http://example.org/namedGraph"); Assert.NotEqual(g, j); Assert.Equal(i, j); }
public void StorageStardogSparqlUpdate3() { StardogConnector stardog = StardogTests.GetConnection(); IGraph g; Console.WriteLine("Dropping graph"); stardog.Update("DROP SILENT GRAPH <http://example.org/stardog/update/3>"); Console.WriteLine("Dropped graph"); Thread.Sleep(2500); g = new Graph(); stardog.LoadGraph(g, "http://example.org/stardog/update/3"); Assert.True(g.IsEmpty, "Graph should be empty after DROP command"); Console.WriteLine("Inserting data"); IGraph newData = new Graph(); newData.BaseUri = new Uri("http://example.org/stardog/update/3"); newData.Assert(newData.CreateUriNode(new Uri("http://x")), newData.CreateUriNode(new Uri("http://y")), newData.CreateUriNode(new Uri("http://z"))); stardog.SaveGraph(newData); Console.WriteLine("Inserted data"); g = new Graph(); stardog.LoadGraph(g, "http://example.org/stardog/update/3"); Assert.False(g.IsEmpty, "Graph should not be empty"); Assert.Equal(1, g.Triples.Count); }
public void StorageStardogCreateNewStore() { Guid guid; do { guid = Guid.NewGuid(); } while (guid.Equals(Guid.Empty) || !Char.IsLetter(guid.ToString()[0])); StardogServer stardog = StardogTests.GetServer(); IStoreTemplate template = stardog.GetDefaultTemplate(guid.ToString()); Console.WriteLine("Template ID " + template.ID); try { Options.HttpDebugging = true; //Options.HttpFullDebugging = true; stardog.CreateStore(template); } finally { //Options.HttpFullDebugging = false; Options.HttpDebugging = false; } stardog.Dispose(); }
public void StorageStardogSparqlUpdate1() { StardogConnector stardog = StardogTests.GetConnection(); IGraph g; g = new Graph(); stardog.LoadGraph(g, "http://example.org/stardog/update/1"); if (!g.IsEmpty) { Console.WriteLine("Dropping graph"); stardog.Update("DROP SILENT GRAPH <http://example.org/stardog/update/1>"); Console.WriteLine("Dropped graph"); Thread.Sleep(2500); g = new Graph(); stardog.LoadGraph(g, "http://example.org/stardog/update/1"); Assert.True(g.IsEmpty, "Graph should be empty after DROP command"); } Console.WriteLine("Inserting data"); stardog.Update( "INSERT DATA { GRAPH <http://example.org/stardog/update/1> { <http://x> <http://y> <http://z> } }"); Console.WriteLine("Inserted data"); g = new Graph(); stardog.LoadGraph(g, "http://example.org/stardog/update/1"); Assert.False(g.IsEmpty, "Graph should not be empty"); Assert.Equal(1, g.Triples.Count); }
public void StorageStardogDeleteNamedGraph() { try { //Options.UseBomForUtf8 = false; StardogConnector stardog = StardogTests.GetConnection();; Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); g.BaseUri = new Uri("http://example.org/tempGraph"); stardog.SaveGraph(g); Graph h = new Graph(); stardog.LoadGraph(h, new Uri("http://example.org/tempGraph")); if (g.Triples.Count == h.Triples.Count) { Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph"); } else { Assert.IsTrue(h.HasSubGraph(g), "Retrieved Graph should have the Saved Graph as a subgraph"); } stardog.DeleteGraph("http://example.org/tempGraph"); Graph i = new Graph(); stardog.LoadGraph(i, new Uri("http://example.org/tempGraph")); Assert.IsTrue(i.IsEmpty, "Retrieved Graph should be empty since it has been deleted"); } finally { //Options.UseBomForUtf8 = true; } }
public void StorageStardogUpdateNamedGraphRemoveTriples() { try { //Options.UseBomForUtf8 = false; StardogConnector stardog = StardogTests.GetConnection();; Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); g.BaseUri = new Uri("http://example.org/graph"); stardog.SaveGraph(g); INode rdfType = g.CreateUriNode(new Uri(VDS.RDF.Parsing.RdfSpecsHelper.RdfType)); stardog.UpdateGraph(g.BaseUri, null, g.GetTriplesWithPredicate(rdfType)); g.Retract(g.GetTriplesWithPredicate(rdfType).ToList()); Graph h = new Graph(); stardog.LoadGraph(h, new Uri("http://example.org/graph")); if (g.Triples.Count == h.Triples.Count) { Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph"); } else { Assert.IsTrue(h.HasSubGraph(g), "Retrieved Graph should have the Saved Graph as a subgraph"); } Assert.IsFalse(h.GetTriplesWithPredicate(rdfType).Any(), "Retrieved Graph should not contain any rdf:type Triples"); } finally { //Options.UseBomForUtf8 = true; } }
public void StorageStardogSaveToNamedGraphOverwrite() { try { //Options.UseBomForUtf8 = false; Options.HttpDebugging = true; StardogConnector stardog = StardogTests.GetConnection();; Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); g.BaseUri = new Uri("http://example.org/namedGraph"); stardog.SaveGraph(g); Graph h = new Graph(); stardog.LoadGraph(h, new Uri("http://example.org/namedGraph")); Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph"); Graph i = new Graph(); i.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.LeviathanFunctionLibrary.ttl"); i.BaseUri = new Uri("http://example.org/namedGraph"); stardog.SaveGraph(i); Graph j = new Graph(); stardog.LoadGraph(j, "http://example.org/namedGraph"); Assert.AreNotEqual(g, j, "Retrieved Graph should not be equal to overwritten Graph"); Assert.AreEqual(i, j, "Retrieved Graph should be equal to Saved Graph"); } finally { Options.HttpDebugging = false; //Options.UseBomForUtf8 = true; } }
public void StorageStardogSaveToDefaultGraph() { try { //Options.UseBomForUtf8 = false; StardogConnector stardog = StardogTests.GetConnection();; Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); g.BaseUri = null; stardog.SaveGraph(g); Graph h = new Graph(); stardog.LoadGraph(h, (Uri)null); Console.WriteLine("Retrieved " + h.Triples.Count + " Triple(s) from Stardog"); if (g.Triples.Count == h.Triples.Count) { Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph"); } else { Assert.IsTrue(h.HasSubGraph(g), "Retrieved Graph should have the Saved Graph as a subgraph"); } } finally { //Options.UseBomForUtf8 = true; } }
public void StorageStardogIsReadyValidDb() { StardogConnector stardog = StardogTests.GetConnection(); Assert.True(stardog.IsReady); stardog.Dispose(); }
public void StorageStardogTransactionTest() { StardogConnector stardog = StardogTests.GetConnection(); stardog.Begin(); stardog.Commit(); stardog.Dispose(); }
public void StorageStardogReasoningMode() { StardogConnector connector = StardogTests.GetConnection(); if (connector.Reasoning != StardogReasoningMode.DatabaseControlled) { Assert.Pass(); } else { connector.Reasoning = StardogReasoningMode.DL; } }
public void StorageStardogReasoningQL() { StardogConnector stardog = StardogTests.GetConnection(); if (stardog.Reasoning == StardogReasoningMode.DatabaseControlled) { Assert.Inconclusive( "Version of Stardog being tested does not support configuring reasoning mode at connection level"); } Graph g = new Graph(); g.LoadFromFile("resources\\InferenceTest.ttl"); g.BaseUri = new Uri("http://example.org/reasoning"); stardog.SaveGraph(g); String query = "PREFIX rdfs: <" + NamespaceMapper.RDFS + "> SELECT * WHERE { { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } UNION { GRAPH <http://example.org/reasoning> { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } } }"; Console.WriteLine(query); Console.WriteLine(); SparqlResultSet resultsNoReasoning = stardog.Query(query) as SparqlResultSet; if (resultsNoReasoning != null) { Console.WriteLine("Results without Reasoning"); TestTools.ShowResults(resultsNoReasoning); } else { Assert.Fail("Did not get a SPARQL Result Set as expected"); } stardog.Reasoning = StardogReasoningMode.QL; SparqlResultSet resultsWithReasoning = stardog.Query(query) as SparqlResultSet; if (resultsWithReasoning != null) { Console.WriteLine("Results with Reasoning"); TestTools.ShowResults(resultsWithReasoning); } else { Assert.Fail("Did not get a SPARQL Result Set as expected"); } Assert.IsTrue(resultsWithReasoning.Count >= resultsNoReasoning.Count, "Reasoning should yield as many if not more results"); }
public void StorageStardogReasoningQL() { try { //Options.UseBomForUtf8 = false; Options.HttpDebugging = true; StardogConnector stardog = StardogTests.GetConnection();; Graph g = new Graph(); g.LoadFromFile("InferenceTest.ttl"); g.BaseUri = new Uri("http://example.org/reasoning"); stardog.SaveGraph(g); String query = "PREFIX rdfs: <" + NamespaceMapper.RDFS + "> SELECT * WHERE { { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } UNION { GRAPH <http://example.org/reasoning> { ?class rdfs:subClassOf <http://example.org/vehicles/Vehicle> } } }"; Console.WriteLine(query); Console.WriteLine(); SparqlResultSet resultsNoReasoning = stardog.Query(query) as SparqlResultSet; if (resultsNoReasoning != null) { Console.WriteLine("Results without Reasoning"); TestTools.ShowResults(resultsNoReasoning); } else { Assert.Fail("Did not get a SPARQL Result Set as expected"); } stardog.Reasoning = StardogReasoningMode.QL; SparqlResultSet resultsWithReasoning = stardog.Query(query) as SparqlResultSet; if (resultsWithReasoning != null) { Console.WriteLine("Results with Reasoning"); TestTools.ShowResults(resultsWithReasoning); } else { Assert.Fail("Did not get a SPARQL Result Set as expected"); } Assert.IsTrue(resultsWithReasoning.Count >= resultsNoReasoning.Count, "Reasoning should yield as many if not more results"); } finally { //Options.UseBomForUtf8 = true; Options.HttpDebugging = false; } }
public void StorageStardogReasoningMode() { StardogConnector connector = StardogTests.GetConnection(); if (connector.Reasoning != StardogReasoningMode.DatabaseControlled) { return; } else { Assert.Throws <RdfStorageException>(() => connector.Reasoning = StardogReasoningMode.DL ); } }
public void StorageStardogTransactionTest() { try { Options.HttpDebugging = true; StardogConnector stardog = StardogTests.GetConnection();; stardog.Begin(); stardog.Commit(); stardog.Dispose(); } finally { Options.HttpDebugging = false; } }
public void StorageStardogLoadDefaultGraph() { StardogConnector stardog = StardogTests.GetConnection();; Graph g = new Graph(); stardog.LoadGraph(g, (Uri)null); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Assert.IsFalse(g.IsEmpty); }
public void StorageStardogLoadNamedGraph() { StardogConnector stardog = StardogTests.GetConnection();; Graph g = new Graph(); stardog.LoadGraph(g, new Uri("http://example.org/graph")); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Assert.IsFalse(g.IsEmpty); }
public void StorageStardogAmpersandsInDataTest() { try { Options.HttpDebugging = true; StardogConnector stardog = StardogTests.GetConnection();; //Save the Graph Graph g = new Graph(); String fragment = "@prefix : <http://example.org/> . [] :string \"This has & ampersands in it\" ."; g.LoadFromString(fragment); g.BaseUri = new Uri("http://example.org/ampersandGraph"); Console.WriteLine("Original Graph:"); TestTools.ShowGraph(g); stardog.SaveGraph(g); //Retrieve and check it round trips Graph h = new Graph(); stardog.LoadGraph(h, g.BaseUri); Console.WriteLine("Graph as retrieved from Stardog:"); TestTools.ShowGraph(h); Assert.AreEqual(g, h, "Graphs should be equal"); //Now try to delete the data from this Graph GenericUpdateProcessor processor = new GenericUpdateProcessor(stardog); SparqlUpdateParser parser = new SparqlUpdateParser(); processor.ProcessCommandSet(parser.ParseFromString("WITH <http://example.org/ampersandGraph> DELETE WHERE { ?s ?p ?o }")); Graph i = new Graph(); stardog.LoadGraph(i, g.BaseUri); Console.WriteLine("Graph as retrieved after the DELETE WHERE:"); TestTools.ShowGraph(i); Assert.AreNotEqual(g, i, "Graphs should not be equal"); Assert.AreNotEqual(h, i, "Graphs should not be equal"); } finally { Options.HttpDebugging = false; } }
public void StorageStardogCreateNewStore() { Guid guid; do { guid = Guid.NewGuid(); } while (guid.Equals(Guid.Empty) || !Char.IsLetter(guid.ToString()[0])); StardogServer stardog = StardogTests.GetServer(); IStoreTemplate template = stardog.GetDefaultTemplate(guid.ToString()); Console.WriteLine("Template ID " + template.ID); stardog.CreateStore(template); stardog.Dispose(); }
public void StorageStardogLoadDefaultGraph() { StardogConnector stardog = StardogTests.GetConnection(); Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); g.BaseUri = null; stardog.SaveGraph(g); Graph h = new Graph(); stardog.LoadGraph(h, (Uri)null); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString(formatter)); } Assert.False(h.IsEmpty); }
public void StorageStardogSparqlUpdate5() { StardogConnector stardog = StardogTests.GetConnection(); IGraph g; // Begin a transaction stardog.Begin(); // Try to make an update stardog.Update( "DROP SILENT GRAPH <http://example.org/stardog/update/5>; INSERT DATA { GRAPH <http://example.org/stardog/update/5> { <http://x> <http://y> <http://z> } }"); // Rollback the transaction stardog.Rollback(); g = new Graph(); stardog.LoadGraph(g, "http://example.org/stardog/update/5"); Assert.False(g.IsEmpty, "Graph should not be empty after update"); Assert.Equal(1, g.Triples.Count); stardog.Dispose(); }
public void StorageStardogSaveToNamedGraph() { try { //Options.UseBomForUtf8 = false; StardogConnector stardog = StardogTests.GetConnection();; Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); g.BaseUri = new Uri("http://example.org/graph"); stardog.SaveGraph(g); Graph h = new Graph(); stardog.LoadGraph(h, new Uri("http://example.org/graph")); Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph"); } finally { //Options.UseBomForUtf8 = true; } }
public void StorageStardogSaveToNamedGraph2() { try { //Options.UseBomForUtf8 = false; StardogConnector stardog = StardogTests.GetConnection(); Graph g = new Graph(); g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl"); Uri u = new Uri("http://example.org/graph/" + DateTime.Now.Ticks); g.BaseUri = u; stardog.SaveGraph(g); Graph h = new Graph(); stardog.LoadGraph(h, u); Assert.Equal(g, h); } finally { //Options.UseBomForUtf8 = true; } }
protected override IStorageProvider GetManager() { return((IStorageProvider)StardogTests.GetConnection()); }