コード例 #1
0
        /// <summary>
        /// Starts RDF Handling instantiating a Triple Formatter if necessary
        /// </summary>
        protected override void StartRdfInternal()
        {
            if (this._closeOnEnd && this._writer == null)
            {
                throw new RdfParseException("Cannot use this WriteThroughHandler as an RDF Handler for parsing as you set closeOnEnd to true and you have already used this Handler and so the provided TextWriter was closed");
            }

            if (this._formatterType != null)
            {
                this._formatter        = null;
                this._formattingMapper = new QNameOutputMapper();

                //Instantiate a new Formatter
                ConstructorInfo[] cs = this._formatterType.GetConstructors();
                Type qnameMapperType = typeof(QNameOutputMapper);
                Type nsMapperType    = typeof(INamespaceMapper);
                foreach (ConstructorInfo c in cs.OrderByDescending(c => c.GetParameters().Count()))
                {
                    ParameterInfo[] ps = c.GetParameters();
                    try
                    {
                        if (ps.Length == 1)
                        {
                            if (ps[0].ParameterType.Equals(qnameMapperType))
                            {
                                this._formatter = Activator.CreateInstance(this._formatterType, new Object[] { this._formattingMapper }) as ITripleFormatter;
                            }
                            else if (ps[0].ParameterType.Equals(nsMapperType))
                            {
                                this._formatter = Activator.CreateInstance(this._formatterType, new Object[] { this._formattingMapper }) as ITripleFormatter;
                            }
                        }
                        else if (ps.Length == 0)
                        {
                            this._formatter = Activator.CreateInstance(this._formatterType) as ITripleFormatter;
                        }

                        if (this._formatter != null)
                        {
                            break;
                        }
                    }
                    catch
                    {
                        //Suppress errors since we'll throw later if necessary
                    }
                }

                //If we get out here and the formatter is null then we throw an error
                if (this._formatter == null)
                {
                    throw new RdfParseException("Unable to instantiate a ITripleFormatter from the given Formatter Type " + this._formatterType.FullName);
                }
            }

            if (this._formatter is IGraphFormatter)
            {
                this._writer.WriteLine(((IGraphFormatter)this._formatter).FormatGraphHeader(this._formattingMapper));
            }
        }
コード例 #2
0
        private void ParsingUsingWriteThroughHandler(ITripleFormatter formatter)
        {
            if (!System.IO.File.Exists("temp.ttl"))
            {
                Graph g = new Graph();
                EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl");
                g.SaveToFile("temp.ttl");
            }

            WriteThroughHandler handler = new WriteThroughHandler(formatter, Console.Out, false);
            TurtleParser parser = new TurtleParser();
            parser.Load(handler, "temp.ttl");
        }
コード例 #3
0
        private void ParsingUsingWriteThroughHandler(ITripleFormatter formatter)
        {
            if (!System.IO.File.Exists("write_through_handler_tests_temp.ttl"))
            {
                Graph g = new Graph();
                EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl");
                g.SaveToFile("write_through_handler_tests_temp.ttl");
            }

            WriteThroughHandler handler = new WriteThroughHandler(formatter, Console.Out, false);
            TurtleParser        parser  = new TurtleParser();

            parser.Load(handler, "write_through_handler_tests_temp.ttl");
        }
コード例 #4
0
 /// <summary>
 /// Creates a new Write-Through Handler
 /// </summary>
 /// <param name="formatter">Triple Formatter to use</param>
 /// <param name="writer">Text Writer to write to</param>
 /// <param name="closeOnEnd">Whether to close the writer at the end of RDF handling</param>
 public WriteThroughHandler(ITripleFormatter formatter, TextWriter writer, bool closeOnEnd)
 {
     if (writer == null) throw new ArgumentNullException("writer", "Cannot use a null TextWriter with the Write Through Handler");
     if (formatter != null)
     {
         this._formatter = formatter;
     }
     else
     {
         this._formatter = new NTriplesFormatter();
     }
     this._writer = writer;
     this._closeOnEnd = closeOnEnd;
 }
コード例 #5
0
 /// <summary>
 /// Creates a new Write-Through Handler
 /// </summary>
 /// <param name="formatter">Triple Formatter to use</param>
 /// <param name="writer">Text Writer to write to</param>
 /// <param name="closeOnEnd">Whether to close the writer at the end of RDF handling</param>
 public WriteThroughHandler(ITripleFormatter formatter, TextWriter writer, bool closeOnEnd)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer", "Cannot use a null TextWriter with the Write Through Handler");
     }
     if (formatter != null)
     {
         this._formatter = formatter;
     }
     else
     {
         this._formatter = new NTriplesFormatter();
     }
     this._writer     = writer;
     this._closeOnEnd = closeOnEnd;
 }
コード例 #6
0
        private void EnsureTestData(int triples, String file, ITripleFormatter formatter)
        {
            if (!File.Exists(file))
            {
                Graph g = new Graph();
                g.NamespaceMap.AddNamespace(String.Empty, new Uri("http://example.org/node#"));

                int padding = triples.ToString().Length;

                using (StreamWriter writer = new StreamWriter(file))
                {
                    for (int i = 1; i <= triples; i++)
                    {
                        IUriNode temp = g.CreateUriNode(":" + i);
                        writer.WriteLine(formatter.Format(new Triple(temp, temp, temp)));
                    }
                    writer.Close();
                }
            }
        }
コード例 #7
0
        private void EnsureTestData(int triples, String file, ITripleFormatter formatter)
        {
            if (!File.Exists(file))
            {
                Graph g = new Graph();
                g.NamespaceMap.AddNamespace(String.Empty, new Uri("http://example.org/node#"));

                int padding = triples.ToString().Length;

                using (StreamWriter writer = new StreamWriter(File.OpenWrite(file)))
                {
                    for (int i = 1; i <= triples; i++)
                    {
                        IUriNode temp = g.CreateUriNode(":" + i);
                        writer.WriteLine(formatter.Format(new Triple(temp, temp, temp)));
                    }
                    writer.Close();
                }
            }

            //Force a GC prior to each of these tests
            GC.GetTotalMemory(true);
        }
コード例 #8
0
        private static void DumpOneTriple(IGraph from, Triple trip0, ITripleFormatter formatter, TextWriter writer, string fmt)
        {
            Triple trip = trip0;

            if (trip.Graph == null)
            {
                trip         = new Triple(trip.Subject, trip.Predicate, trip.Object, from);
                trip.Context = trip0.Context;
            }
            string ts;

            try
            {
                ts = trip.ToString(formatter);
            }
            catch (RdfOutputException)
            {
                ts = trip.ToString();
            }
            var hline = (" " + ts).Replace(" robokind:", " rk:");

            hline = hline.Replace("<robokind:", "<rk:");
            writer.WriteLine(fmt, hline);
        }
コード例 #9
0
 /// <summary>
 /// Gets the String representation of a Triple using the given Triple Formatter.
 /// </summary>
 /// <param name="formatter">Formatter.</param>
 /// <returns></returns>
 public string ToString(ITripleFormatter formatter)
 {
     return(formatter.Format(this));
 }
コード例 #10
0
 /// <summary>
 /// Creates a new Write-Through Handler
 /// </summary>
 /// <param name="formatter">Triple Formatter to use</param>
 /// <param name="writer">Text Writer to write to</param>
 public WriteThroughHandler(ITripleFormatter formatter, TextWriter writer)
     : this(formatter, writer, true)
 {
 }
コード例 #11
0
 protected NTriplesAdaptor(ITripleFormatter formatter)
     : this()
 {
     this._formatter = formatter;
 }
コード例 #12
0
ファイル: WriteThroughHandler.cs プロジェクト: jmahmud/RDFer
        /// <summary>
        /// Starts RDF Handling instantiating a Triple Formatter if necessary
        /// </summary>
        protected override void StartRdfInternal()
        {
            if (this._closeOnEnd && this._writer == null) throw new RdfParseException("Cannot use this WriteThroughHandler as an RDF Handler for parsing as you set closeOnEnd to true and you have already used this Handler and so the provided TextWriter was closed");

            if (this._formatterType != null)
            {
                this._formatter = null;
                this._formattingMapper = new QNameOutputMapper();

                //Instantiate a new Formatter
                ConstructorInfo[] cs = this._formatterType.GetConstructors();
                Type qnameMapperType = typeof(QNameOutputMapper);
                Type nsMapperType = typeof(INamespaceMapper);
                foreach (ConstructorInfo c in cs.OrderByDescending(c => c.GetParameters().Count()))
                {
                    ParameterInfo[] ps = c.GetParameters();
                    try
                    {
                        if (ps.Length == 1)
                        {
                            if (ps[0].ParameterType.Equals(qnameMapperType))
                            {
                                this._formatter = Activator.CreateInstance(this._formatterType, new Object[] { this._formattingMapper }) as ITripleFormatter;
                            }
                            else if (ps[0].ParameterType.Equals(nsMapperType))
                            {
                                this._formatter = Activator.CreateInstance(this._formatterType, new Object[] { this._formattingMapper }) as ITripleFormatter;
                            }
                        }
                        else if (ps.Length == 0)
                        {
                            this._formatter = Activator.CreateInstance(this._formatterType) as ITripleFormatter;
                        }

                        if (this._formatter != null) break;
                    }
                    catch
                    {
                        //Suppress errors since we'll throw later if necessary
                    }
                }

                //If we get out here and the formatter is null then we throw an error
                if (this._formatter == null) throw new RdfParseException("Unable to instantiate a ITripleFormatter from the given Formatter Type " + this._formatterType.FullName);
            }

            if (this._formatter is IGraphFormatter)
            {
                this._writer.WriteLine(((IGraphFormatter)this._formatter).FormatGraphHeader(this._formattingMapper));
            }
            this._written = 0;
        }
コード例 #13
0
ファイル: WriteThroughHandler.cs プロジェクト: jmahmud/RDFer
 /// <summary>
 /// Creates a new Write-Through Handler
 /// </summary>
 /// <param name="formatter">Triple Formatter to use</param>
 /// <param name="writer">Text Writer to write to</param>
 public WriteThroughHandler(ITripleFormatter formatter, TextWriter writer)
     : this(formatter, writer, true)
 {
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: IllidanS4/xml2rdf
 public NamespaceWriteThroughHandler(ITripleFormatter formatter, INamespaceMapper namespaceMapper, TextWriter writer) : base(formatter, writer)
 {
     this.namespaceMapper = namespaceMapper;
 }
コード例 #15
0
ファイル: NTriplesAdaptor.cs プロジェクト: jbunzel/MvcRQ_git
 protected NTriplesAdaptor(ITripleFormatter formatter)
     : this()
 {
     this._formatter = formatter;
 }