Inheritance: StatementSink, CanForgetBNodes
Esempio n. 1
0
        public override void Select(StatementSink storage)
        {
            foreach (string infile in files)
            {
                if (!quiet)
                {
                    Console.Error.Write(infile + " ");
                }

                try {
                    DateTime start = DateTime.Now;

                    StatementFilterSink filter = new StatementFilterSink(storage);

                    if (format == null || format != "spec")
                    {
                        string fmt = format;
                        if (fmt == null)
                        {
                            // Use file extension to override default parser type.
                            if (infile.StartsWith("http:"))
                            {
                                fmt = "url";
                            }
                            else if (infile.EndsWith(".nt") || infile.EndsWith(".n3") || infile.EndsWith(".ttl"))
                            {
                                fmt = "n3";
                            }
                            else if (infile.EndsWith(".xml") || infile.EndsWith(".rdf"))
                            {
                                fmt = "xml";
                            }
                            else
                            {
                                Console.Error.WriteLine("Unrecognized file extension in " + infile + ": Trying RDF/XML.");
                                fmt = "xml";
                            }
                        }

                        using (RdfReader parser = RdfReader.Create(fmt, infile)) {
                            if (baseuri != null)
                            {
                                parser.BaseUri = baseuri;
                            }
                            if (meta != null)
                            {
                                parser.Meta = meta;
                            }

                            if (storage is RdfWriter)
                            {
                                ((RdfWriter)storage).Namespaces.AddFrom(parser.Namespaces);
                            }

                            try {
                                parser.Select(filter);
                            } finally {
                                if (parser.Warnings.Count > 0)
                                {
                                    Console.Error.WriteLine("\nThere were warnings parsing this file:");
                                }
                                foreach (string warning in parser.Warnings)
                                {
                                    Console.Error.WriteLine("> " + warning);
                                }
                            }
                        }
                    }
                    else
                    {
                        StatementSource src = Store.Create(infile);
                        src.Select(filter);
                        if (src is IDisposable)
                        {
                            ((IDisposable)src).Dispose();
                        }
                    }

                    totalStatementsRead += filter.StatementCount;

                    TimeSpan time = DateTime.Now - start;

                    if (!quiet)
                    {
                        Console.Error.WriteLine(" {0}m{1}s, {2} statements, {3} st/sec", (int)time.TotalMinutes, (int)time.Seconds, filter.StatementCount, time.TotalSeconds == 0 ? "?" : ((int)(filter.StatementCount / time.TotalSeconds)).ToString());
                    }
                } catch (ParserException e) {
                    Console.Error.WriteLine(" " + e.Message);
                } catch (Exception e) {
                    Console.Error.WriteLine("\n" + e + "\n");
                }
            }
        }
Esempio n. 2
0
        public override void Select(StatementSink storage)
        {
            foreach (string infile in files) {
                if (!quiet)
                    Console.Error.Write(infile + " ");

                try {
                    DateTime start = DateTime.Now;

                    StatementFilterSink filter = new StatementFilterSink(storage);

                    if (format == null || format != "spec") {
                        string fmt = format;
                        if (fmt == null) {
                            // Use file extension to override default parser type.
                            if (infile.StartsWith("http:"))
                                fmt = "url";
                            else if (infile.EndsWith(".nt") || infile.EndsWith(".n3") || infile.EndsWith(".ttl"))
                                fmt = "n3";
                            else if (infile.EndsWith(".xml") || infile.EndsWith(".rdf"))
                                fmt = "xml";
                            else {
                                Console.Error.WriteLine("Unrecognized file extension in " + infile + ": Trying RDF/XML.");
                                fmt = "xml";
                            }
                        }

                        using (RdfReader parser = RdfReader.Create(fmt, infile)) {
                            if (baseuri != null) parser.BaseUri = baseuri;
                            if (meta != null) parser.Meta = meta;

                            if (storage is RdfWriter)
                                ((RdfWriter)storage).Namespaces.AddFrom(parser.Namespaces);

                            try {
                                parser.Select(filter);
                            } finally {
                                if (parser.Warnings.Count > 0)
                                    Console.Error.WriteLine("\nThere were warnings parsing this file:");
                                foreach (string warning in parser.Warnings)
                                    Console.Error.WriteLine("> " + warning);
                            }
                        }
                    } else {
                        StatementSource src = Store.Create(infile);
                        src.Select(filter);
                        if (src is IDisposable)
                            ((IDisposable)src).Dispose();
                    }

                    totalStatementsRead += filter.StatementCount;

                    TimeSpan time = DateTime.Now - start;

                    if (!quiet)
                        Console.Error.WriteLine(" {0}m{1}s, {2} statements, {3} st/sec", (int)time.TotalMinutes, (int)time.Seconds, filter.StatementCount, time.TotalSeconds == 0 ? "?" : ((int)(filter.StatementCount/time.TotalSeconds)).ToString());
                } catch (ParserException e) {
                    Console.Error.WriteLine(" " + e.Message);
                } catch (Exception e) {
                    Console.Error.WriteLine("\n" + e + "\n");
                }
            }
        }