Ejemplo n.º 1
0
        public IGraphFormatter GetFormatter(Type type)
        {
            IGraphFormatter result = m_formatters.GetValue(type);

            if (result != null)
            {
                return(result);
            }

            return(m_next != null?m_next.GetFormatter(type) : null);
        }
Ejemplo n.º 2
0
        public void WritingFormattingGraphs()
        {
            List <IGraph> graphs = new List <IGraph>();
            Graph         g      = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            graphs.Add(g);
            g = new Graph();
            g.LoadFromFile("resources\\InferenceTest.ttl");
            graphs.Add(g);
            g = new Graph();
            g.LoadFromFile("resources\\cyrillic.rdf");
            graphs.Add(g);
            g = new Graph();
            g.LoadFromFile("resources\\complex-collections.nt");
            graphs.Add(g);

            List <IGraphFormatter> formatters = new List <IGraphFormatter>()
            {
                new RdfXmlFormatter()
            };

            List <IRdfReader> parsers = new List <IRdfReader>()
            {
                new RdfXmlParser()
            };

            for (int i = 0; i < formatters.Count; i++)
            {
                IGraphFormatter formatter = formatters[i];
                Console.WriteLine("Using Formatter " + formatter.GetType().ToString());

                foreach (IGraph graph in graphs)
                {
                    Console.WriteLine("Testing Graph " + (graph.BaseUri != null ? graph.BaseUri.ToString() : String.Empty));
                    StringBuilder output = new StringBuilder();
                    output.AppendLine(formatter.FormatGraphHeader(graph));
                    foreach (Triple t in graph.Triples)
                    {
                        output.AppendLine(formatter.Format(t));
                    }
                    output.AppendLine(formatter.FormatGraphFooter());

                    Console.WriteLine(output.ToString());

                    //Try parsing to check it round trips
                    Graph      h      = new Graph();
                    IRdfReader parser = parsers[i];
                    parser.Load(h, new StringReader(output.ToString()));

                    GraphDiffReport diff = graph.Difference(h);
                    if (!diff.AreEqual)
                    {
                        TestTools.ShowDifferences(diff);
                    }

                    Assert.AreEqual(graph, h, "Graphs should be equal after round tripping");
                }
            }
            Console.WriteLine();
        }
Ejemplo n.º 3
0
 public void AddFormatter(Type type, bool useInChildren, IGraphFormatter formatter)
 {
     m_formatters.AddValue(type, useInChildren, formatter);
 }
 public void AddFormatter(Type type, bool useInChildren, IGraphFormatter formatter)
 {
     m_formatters.AddValue(type,useInChildren,formatter);
 }