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"); }
public void ParsingRdfXmlEmptyStrings() { NTriplesFormatter formatter = new NTriplesFormatter(); RdfXmlParser domParser = new RdfXmlParser(RdfXmlParserMode.DOM); Graph g = new Graph(); domParser.Load(g, "empty-string-rdfxml.rdf"); Console.WriteLine("DOM Parser parsed OK"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); RdfXmlParser streamingParser = new RdfXmlParser(RdfXmlParserMode.Streaming); Graph h = new Graph(); streamingParser.Load(h, "empty-string-rdfxml.rdf"); Console.WriteLine("Streaming Parser parsed OK"); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString(formatter)); } Assert.AreEqual(g, h, "Graphs should be equal"); }
public void ServiceDescriptionOptionsRequestOnSparqlServer2() { Console.WriteLine("Making an OPTIONS request to the web demos SPARQL Server at http://localhost/demos/server/some/long/path/elsewhere"); Console.WriteLine("This Test tries to ensure that the URI resolution works correctly"); Console.WriteLine(); NTriplesFormatter formatter = new NTriplesFormatter(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/demos/server/some/long/path/elsewhere"); request.Method = "OPTIONS"; request.Accept = MimeTypesHelper.HttpAcceptHeader; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { IRdfReader parser = MimeTypesHelper.GetParser(response.ContentType); Graph g = new Graph(); parser.Load(g, new StreamReader(response.GetResponseStream())); TestTools.ShowGraph(g); Assert.IsFalse(g.IsEmpty, "A non-empty Service Description Graph should have been returned"); response.Close(); } }
private void TestConstruct(IInMemoryQueryableStore store, IGraph expected, String query) { SparqlQuery q = this._parser.ParseFromString(query); LeviathanQueryProcessor processor = new LeviathanQueryProcessor(store); Object results = processor.ProcessQuery(q); if (results is IGraph) { IGraph result = (IGraph)results; 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"); } else { Assert.Fail("Did not get a Graph as expected"); } }
public void WritingSerializeOwnOneOfVeryLarge() { try { //Create the Graph for the Test and Generate a List of URIs Graph g = new Graph(); List<IUriNode> nodes = new List<IUriNode>(); for (int i = 1; i <= 10000; i++) { nodes.Add(g.CreateUriNode(new Uri("http://example.org/Class" + i))); } //Use the thingOneOf to generate the Triples thingOneOf(g, nodes.ToArray()); //Dump as NTriples to the Console NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); //Now try to save as RDF/XML IRdfWriter writer = new RdfXmlWriter(); writer.Save(g, "owl-one-of.rdf"); Console.WriteLine("Saved OK using RdfXmlWriter"); Console.WriteLine(); writer = new FastRdfXmlWriter(); ((ICompressingWriter)writer).CompressionLevel = WriterCompressionLevel.Medium; writer.Save(g, "owl-one-of-fast.rdf"); Console.WriteLine("Saved OK using FastRdfXmlWriter"); Console.WriteLine(); //Now check that the Graphs are all equivalent Graph h = new Graph(); FileLoader.Load(h, "owl-one-of.rdf"); Assert.AreEqual(g, h, "Graphs should be equal (RdfXmlWriter)"); Console.WriteLine("RdfXmlWriter serialization was OK"); Console.WriteLine(); Graph j = new Graph(); FileLoader.Load(j, "owl-one-of-fast.rdf"); Assert.AreEqual(g, j, "Graphs should be equal (FastRdfXmlWriter)"); Console.WriteLine("FastRdfXmlWriter serialization was OK"); } catch (StackOverflowException ex) { TestTools.ReportError("Stack Overflow", ex, true); } }
public void ParsingGraphHandlerImplicitTurtle() { Graph g = new Graph(); EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl"); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Assert.IsFalse(g.IsEmpty, "Graph should not be empty"); Assert.IsTrue(g.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace"); }
public void StorageStardogLoadNamedGraph() { StardogConnector stardog = this.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 StorageStardogLoadDefaultGraph() { StardogConnector stardog = this.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 ParsingResultSetHandlerImplicitSparqlRdfNTriples() { this.EnsureTestData("test.sparql.nt", new SparqlRdfWriter(new NTriplesWriter())); SparqlRdfParser parser = new SparqlRdfParser(new NTriplesParser()); SparqlResultSet results = new SparqlResultSet(); parser.Load(results, "test.sparql.nt"); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (SparqlResult r in results) { Console.WriteLine(r.ToString(formatter)); } Assert.IsFalse(results.IsEmpty, "Result Set should not be empty"); Assert.AreEqual(SparqlResultsType.VariableBindings, results.ResultsType, "Results Type should be VariableBindings"); }
public void ParsingGraphHandlerImplicitBaseUriPropogation() { try { Options.UriLoaderCaching = false; Graph g = new Graph(); UriLoader.Load(g, new Uri("http://wiki.rkbexplorer.com/id/void")); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString()); } } finally { Options.UriLoaderCaching = true; } }
public void ParsingUsingPagingHandler(String tempFile, IRdfReader parser) { Graph g = new Graph(); EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl"); g.SaveToFile(tempFile); Graph h = new Graph(); PagingHandler handler = new PagingHandler(new GraphHandler(h), 25); parser.Load(handler, tempFile); h.Retract(h.Triples.Where(t => !t.IsGroundTriple)); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); Assert.IsFalse(h.IsEmpty, "Graph should not be empty"); Assert.IsTrue(h.Triples.Count <= 25, "Graphs should have <= 25 Triples"); Graph i = new Graph(); handler = new PagingHandler(new GraphHandler(i), 25, 25); parser.Load(handler, tempFile); i.Retract(i.Triples.Where(t => !t.IsGroundTriple)); foreach (Triple t in i.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); Assert.IsFalse(i.IsEmpty, "Graph should not be empty"); Assert.IsTrue(i.Triples.Count <= 25, "Graphs should have <= 25 Triples"); GraphDiffReport report = h.Difference(i); Assert.IsFalse(report.AreEqual, "Graphs should not be equal"); Assert.AreEqual(i.Triples.Count, report.AddedTriples.Count(), "Should be " + i.Triples.Count + " added Triples"); Assert.AreEqual(h.Triples.Count, report.RemovedTriples.Count(), "Should be " + h.Triples.Count + " removed Triples"); }
public void ServiceDescriptionOptionsRequestOnQueryHandler() { Console.WriteLine("Making an OPTIONS request to the web demos Query Handler at http://localhost/demos/leviathan/"); Console.WriteLine(); NTriplesFormatter formatter = new NTriplesFormatter(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/demos/leviathan/"); request.Method = "OPTIONS"; request.Accept = MimeTypesHelper.HttpAcceptHeader; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { IRdfReader parser = MimeTypesHelper.GetParser(response.ContentType); Graph g = new Graph(); parser.Load(g, new StreamReader(response.GetResponseStream())); TestTools.ShowGraph(g); Assert.IsFalse(g.IsEmpty, "A non-empty Service Description Graph should have been returned"); response.Close(); } }
public static void ShowDifferences(GraphDiffReport report) { NTriplesFormatter formatter = new NTriplesFormatter(); if (report.AreEqual) { Console.WriteLine("Graphs are Equal"); Console.WriteLine(); Console.WriteLine("Blank Node Mapping between Graphs:"); foreach (KeyValuePair<INode, INode> kvp in report.Mapping) { Console.WriteLine(kvp.Key.ToString(formatter) + " => " + kvp.Value.ToString(formatter)); } } else { Console.WriteLine("Graphs are non-equal"); Console.WriteLine(); Console.WriteLine("Triples added to 1st Graph to give 2nd Graph:"); foreach (Triple t in report.AddedTriples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); Console.WriteLine("Triples removed from 1st Graph to given 2nd Graph:"); foreach (Triple t in report.RemovedTriples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); Console.WriteLine("Blank Node Mapping between Graphs:"); foreach (KeyValuePair<INode, INode> kvp in report.Mapping) { Console.WriteLine(kvp.Key.ToString(formatter) + " => " + kvp.Value.ToString(formatter)); } Console.WriteLine(); Console.WriteLine("MSGs added to 1st Graph to give 2nd Graph:"); foreach (IGraph msg in report.AddedMSGs) { foreach (Triple t in msg.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("MSGs removed from 1st Graph to give 2nd Graph:"); foreach (IGraph msg in report.RemovedMSGs) { foreach (Triple t in msg.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); } } }
public static void ShowGraph(IGraph g) { Console.Write("Graph URI: "); if (g.BaseUri != null) { Console.WriteLine(g.BaseUri.ToString()); } else { Console.WriteLine("NULL"); } Console.WriteLine(g.Triples.Count + " Triples"); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } }
public void StorageVirtuosoSaveGraph() { NTriplesFormatter formatter = new NTriplesFormatter(); try { VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword); 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, "Turtle.ttl"); 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, "http://example.org"); 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); Console.WriteLine(); if (!diff.AreEqual) { Console.WriteLine("Some Differences in Graphs detected (should only be due to Virtuoso not running xsd:boolean as true/false"); Console.WriteLine(); TestTools.ShowDifferences(diff); IUriNode allowedDiffSubject = g.CreateUriNode(":four"); IUriNode allowedDiffSubject2 = g.CreateUriNode(":six"); Assert.IsTrue(diff.RemovedTriples.All(t => t.Subject.Equals(allowedDiffSubject2) || (t.Subject.Equals(allowedDiffSubject) && (t.Object.ToString().Equals("true^^" + XmlSpecsHelper.XmlSchemaDataTypeBoolean) || t.Object.ToString().Equals("false^^" + XmlSpecsHelper.XmlSchemaDataTypeBoolean)))), "Removed Triples should only be those with subject :four and boolean object"); Assert.IsTrue(diff.AddedTriples.All(t => t.Subject.Equals(allowedDiffSubject2) || (t.Subject.Equals(allowedDiffSubject) && (t.Object.ToString().Equals("1") || t.Object.ToString().Equals("0")))), "Added Triples should only be those with subject :four and 1/0 in place of boolean object"); } else { Console.WriteLine("Graphs are equal"); } } catch (VirtuosoException virtEx) { TestTools.ReportError("Virtuoso Error", virtEx, true); } catch (Exception ex) { TestTools.ReportError("Other Error", ex, true); } }
private static void CheckQueryResult(Object results, bool expectResultSet) { NTriplesFormatter formatter = new NTriplesFormatter(); if (results == null) { Assert.Fail("Got a Null Result from a Query"); } else if (results is SparqlResultSet) { if (expectResultSet) { Console.WriteLine("Got a SPARQLResultSet as expected"); SparqlResultSet rset = (SparqlResultSet)results; Console.WriteLine("Result = " + rset.Result); foreach (SparqlResult r in rset) { Console.WriteLine(r.ToString(formatter)); } Console.WriteLine(); } else { Assert.Fail("Expected a SPARQLResultSet but got a '" + results.GetType().ToString() + "'"); } } else if (results is Graph) { if (!expectResultSet) { Console.WriteLine("Got a Graph as expected"); Graph g = (Graph)results; Console.WriteLine(g.Triples.Count + " Triples"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); } else { Assert.Fail("Expected a Graph but got a '" + results.GetType().ToString() + "'"); } } }
public void StorageVirtuosoNativeQuery() { NTriplesFormatter formatter = new NTriplesFormatter(); try { VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword); 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("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 result = manager.Query("DELETE DATA FROM <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}"); CheckQueryResult(result, true); 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 result = manager.Query("INSERT DATA INTO <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}"); CheckQueryResult(result, true); 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); } catch (RdfQueryException queryEx) { TestTools.ReportError("RDF Query Error", queryEx, true); } catch (VirtuosoException virtEx) { TestTools.ReportError("Virtuoso Error", virtEx, true); } catch (Exception ex) { TestTools.ReportError("Other Error", ex, true); } }
public void StorageVirtuosoLoadGraph() { NTriplesFormatter formatter = new NTriplesFormatter(); try { VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword); Assert.IsNotNull(manager); Console.WriteLine("Got the Virtuoso Manager OK"); //Add the Test Date to Virtuoso Graph testData = new Graph(); FileLoader.Load(testData, "MergePart1.ttl"); testData.BaseUri = new Uri("http://localhost/VirtuosoTest"); manager.SaveGraph(testData); testData = new Graph(); FileLoader.Load(testData, "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); } catch (VirtuosoException virtEx) { TestTools.ReportError("Virtuoso Error", virtEx, true); } catch (Exception ex) { TestTools.ReportError("Other Error", ex, true); } }
public void WritingCollectionCompressionComplex2() { Graph g = new Graph(); g.LoadFromFile("complex-collections.nt"); CompressingTurtleWriterContext context = new CompressingTurtleWriterContext(g, Console.Out); WriterHelper.FindCollections(context); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (KeyValuePair<INode, OutputRdfCollection> kvp in context.Collections) { Console.WriteLine("Collection Root - " + kvp.Key.ToString(formatter)); Console.WriteLine("Collection Triples (" + kvp.Value.Triples.Count + ")"); foreach (Triple t in kvp.Value.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); } this.CheckCompressionRoundTrip(g); }
public void ParsingGraphHandlerImplicitMerging() { Graph g = new Graph(); EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl"); g.SaveToFile("temp.ttl"); Graph h = new Graph(); TurtleParser parser = new TurtleParser(); parser.Load(h, "temp.ttl"); Assert.IsFalse(g.IsEmpty, "Graph should not be empty"); Assert.IsTrue(g.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace"); Assert.IsFalse(h.IsEmpty, "Graph should not be empty"); Assert.IsTrue(h.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace"); Assert.AreEqual(g, h, "Graphs should be equal"); parser.Load(h, "temp.ttl"); Assert.AreEqual(g.Triples.Count + 2, h.Triples.Count, "Triples count should now be 2 higher due to the merge which will have replicated the 2 triples containing Blank Nodes"); Assert.AreNotEqual(g, h, "Graphs should no longer be equal"); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in h.Triples.Where(x => !x.IsGroundTriple)) { Console.WriteLine(t.ToString(formatter)); } }
public void ParsingUsingGraphHandlerExplicitTest(String tempFile, IRdfReader parser, bool nsCheck) { Graph g = new Graph(); EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl"); g.SaveToFile(tempFile); Graph h = new Graph(); GraphHandler handler = new GraphHandler(h); parser.Load(handler, tempFile); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString(formatter)); } Assert.IsFalse(g.IsEmpty, "Graph should not be empty"); Assert.IsTrue(g.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace"); Assert.IsFalse(h.IsEmpty, "Graph should not be empty"); if (nsCheck) Assert.IsTrue(h.NamespaceMap.HasNamespace("dnr"), "Graph should have the dnr: Namespace"); Assert.AreEqual(g, h, "Graphs should be equal"); }
public void SimpleExample() { Graph g = new Graph(); g.LoadFromFile("example.rdf"); NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in g.Triples) { if (t.Subject.NodeType == NodeType.Blank) { Console.WriteLine(t.ToString(formatter)); } } }
public void WritingCollectionCompressionNamedListNodes3() { Graph g = new Graph(); INode data1 = g.CreateBlankNode(); g.Assert(data1, g.CreateUriNode(new Uri("http://property")), g.CreateLiteralNode("test1")); INode data2 = g.CreateBlankNode(); g.Assert(data2, g.CreateUriNode(new Uri("http://property")), g.CreateLiteralNode("test2")); INode listEntry1 = g.CreateUriNode(new Uri("http://test/1")); INode rdfFirst = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfListFirst)); INode rdfRest = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfListRest)); INode rdfNil = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfListNil)); g.Assert(listEntry1, rdfFirst, data1); g.Assert(listEntry1, rdfRest, rdfNil); INode listEntry2 = g.CreateUriNode(new Uri("http://test/2")); g.Assert(listEntry2, rdfFirst, data2); g.Assert(listEntry2, rdfRest, listEntry1); INode root = g.CreateUriNode(new Uri("http://root")); g.Assert(root, g.CreateUriNode(new Uri("http://list")), listEntry2); NTriplesFormatter formatter = new NTriplesFormatter(); Console.WriteLine("Original Graph"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); CompressingTurtleWriterContext context = new CompressingTurtleWriterContext(g, Console.Out); WriterHelper.FindCollections(context); Console.WriteLine(context.Collections.Count + " Collections Found"); Console.WriteLine(); System.IO.StringWriter strWriter = new System.IO.StringWriter(); CompressingTurtleWriter writer = new CompressingTurtleWriter(); writer.CompressionLevel = WriterCompressionLevel.High; writer.Save(g, strWriter); Console.WriteLine("Compressed Turtle"); Console.WriteLine(strWriter.ToString()); Console.WriteLine(); Graph h = new Graph(); TurtleParser parser = new TurtleParser(); StringParser.Parse(h, strWriter.ToString()); Console.WriteLine("Graph after Round Trip to Compressed Turtle"); foreach (Triple t in h.Triples) { Console.WriteLine(t.ToString(formatter)); } Assert.AreEqual(g, h, "Graphs should be equal"); }
public void StorageVirtuosoDataTypes() { VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword); Assert.IsNotNull(manager); NTriplesFormatter formatter = new NTriplesFormatter(); //Try to retrieve Graph g = new Graph(); manager.LoadGraph(g, "http://localhost/TurtleImportTest"); Assert.IsFalse(g.IsEmpty, "Retrieved Graph should be non-empty"); Console.WriteLine("Retrieved the Graph from Virtuoso OK"); Console.WriteLine("Retrieved Graph contains:"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } }