Beispiel #1
0
        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");
        }