public void WritingSerializeOwnOneOf() { //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 <= 10; 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(); 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"); }
public void ParsingBaseUriAssignmentRdfXml() { Graph g = new Graph(); g.BaseUri = new Uri("http://example.org/RdfXml"); System.IO.StringWriter strWriter = new System.IO.StringWriter(); RdfXmlWriter writer = new RdfXmlWriter(); writer.Save(g, strWriter); Console.WriteLine("Original Base URI: " + ShowBaseUri(g.BaseUri)); Console.WriteLine("Output using RdfXmlWriter:"); Console.WriteLine(strWriter.ToString()); Console.WriteLine(); Graph h = new Graph(); RdfXmlParser parser = new RdfXmlParser(); parser.Load(h, new System.IO.StringReader(strWriter.ToString())); Console.WriteLine("Base URI after round-trip using RdfXmlWriter: " + ShowBaseUri(h.BaseUri)); Assert.IsNotNull(h.BaseUri, "Base URI should not be null"); strWriter = new System.IO.StringWriter(); FastRdfXmlWriter fastWriter = new FastRdfXmlWriter(); fastWriter.Save(g, strWriter); Console.WriteLine("Output using FastRdfXmlWriter:"); Console.WriteLine(strWriter.ToString()); Console.WriteLine(); Graph i = new Graph(); parser.Load(i, new System.IO.StringReader(strWriter.ToString())); Console.WriteLine("Base URI after round-trip to FastRdfXmlWriter: " + ShowBaseUri(h.BaseUri)); Assert.IsNotNull(i.BaseUri, "Base URI should not be null"); }
/// <summary> /// Internal Method which performs multi-threaded writing of data /// </summary> private void SaveGraphs(FolderStoreWriterContext context) { //Create the relevant Writer IRdfWriter writer; switch (context.Format) { case FolderStoreFormat.Turtle: writer = new TurtleWriter(); break; case FolderStoreFormat.Notation3: writer = new Notation3Writer(); break; case FolderStoreFormat.RdfXml: #if !NO_XMLDOM writer = new FastRdfXmlWriter(); #else writer = new RdfXmlWriter(); #endif break; default: writer = new TurtleWriter(); break; } try { Uri u = context.GetNextURI(); while (u != null) { //Get the Graph from the Store IGraph g = context.Store.Graphs[u]; //Write to Disk String destFile = Path.Combine(context.Folder, u.GetSha256Hash()); switch (context.Format) { case FolderStoreFormat.Turtle: destFile += ".ttl"; break; case FolderStoreFormat.Notation3: destFile += ".n3"; break; case FolderStoreFormat.RdfXml: destFile += ".rdf"; break; default: destFile += ".ttl"; break; } writer.Save(g, destFile); //Get the Next Uri u = context.GetNextURI(); } } catch (ThreadAbortException) { //We've been terminated, don't do anything #if !SILVERLIGHT Thread.ResetAbort(); #endif } catch (Exception ex) { throw new RdfStorageException("Error in Threaded Writer in Thread ID " + Thread.CurrentThread.ManagedThreadId, ex); } }