示例#1
0
        /// <summary>
        /// Loads a RDF Dataset from the NQuads input using a RDF Handler
        /// </summary>
        /// <param name="handler">RDF Handler to use</param>
        /// <param name="parameters">Parameters indicating the Stream to read from</param>
        public void Load(IRdfHandler handler, IStoreParams parameters)
        {
            if (handler == null) throw new ArgumentNullException("handler", "Cannot parse an RDF Dataset using a null RDF Handler");
            if (parameters == null) throw new ArgumentNullException("parameters", "Cannot parse an RDF Dataset using null Parameters");

            //Try and get the Input from the parameters
            TextReader input = null;
            if (parameters is StreamParams)
            {
                //Get Input Stream
                input = ((StreamParams)parameters).StreamReader;

#if !SILVERLIGHT
                //Issue a Warning if the Encoding of the Stream is not ASCII
                if (!((StreamReader)input).CurrentEncoding.Equals(Encoding.ASCII))
                {
                    this.RaiseWarning("Expected Input Stream to be encoded as ASCII but got a Stream encoded as " + ((StreamReader)input).CurrentEncoding.EncodingName + " - Please be aware that parsing errors may occur as a result");
                }
#endif
            } 
            else if (parameters is TextReaderParams)
            {
                input = ((TextReaderParams)parameters).TextReader;
            }

            if (input != null)
            {
                try
                {
                    //Setup Token Queue and Tokeniser
                    NTriplesTokeniser tokeniser = new NTriplesTokeniser(input);
                    tokeniser.NQuadsMode = true;
                    TokenQueue tokens = new TokenQueue();
                    tokens.Tokeniser = tokeniser;
                    tokens.Tracing = this._tracetokeniser;
                    tokens.InitialiseBuffer();

                    //Invoke the Parser
                    this.Parse(handler, tokens);
                }
                catch
                {
                    throw;
                }
                finally
                {
                    try
                    {
                        input.Close();
                    }
                    catch
                    {
                        //No catch actions - just cleaning up
                    }
                }
            }
            else
            {
                throw new RdfStorageException("Parameters for the NQuadsParser must be of the type StreamParams/TextReaderParams");
            }
        }
        public static void Main(string[] args)
        {
            StreamWriter output = new StreamWriter("ParserSpeedTest.txt");
            Notation3Parser n3parser = new Notation3Parser();
            TurtleParser ttlparser = new TurtleParser();
            ITokenQueue queue;
            DateTime start, end;
            long diff;
            bool tokeniseOnly = false;

            Console.SetOut(output);

            String[] files = { "turtle_tests/test-14.ttl", "turtle_tests/test-15.ttl", "turtle_tests/test-16.ttl" };
            foreach (String file in files)
            {
                Console.WriteLine("## Testing File " + file);

                //Use Turtle Tokeniser
                Debug.WriteLine("Testing file " + file + " using Turtle Tokeniser");
                Console.WriteLine("# Using Turtle Tokeniser Only");
                queue = new TokenQueue();
                queue.Tokeniser = new TurtleTokeniser(new StreamReader(file));
                Console.WriteLine("# Test Started at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                queue.InitialiseBuffer();
                Console.WriteLine("# Test Finished at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                
                //Use Turtle Parser
                if (!tokeniseOnly)
                {
                    Debug.WriteLine("Testing file " + file + " using Turtle Parser");
                    Console.WriteLine("# Using Turtle Parser");
                    Console.WriteLine("# Test Started at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                    start = DateTime.Now;
                    Debug.WriteLine("Start " + start.ToString(TestSuite.TestSuiteTimeFormat));
                    Test(file, ttlparser, output);
                    Console.WriteLine("# Test Finished at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                    end = DateTime.Now;
                    diff = Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Second, start, end, Microsoft.VisualBasic.FirstDayOfWeek.Saturday, Microsoft.VisualBasic.FirstWeekOfYear.System);
                    Console.WriteLine("Read Time was " + diff + " seconds");
                    Debug.WriteLine("End " + end.ToString(TestSuite.TestSuiteTimeFormat));
                    Debug.WriteLine("Read Time was " + diff + " seconds");
                    Console.WriteLine();
                }

                //Use Notation 3 Tokeniser
                Debug.WriteLine("Testing file " + file + " using Notation 3 Tokeniser");
                Console.WriteLine("# Using Notation 3 Tokeniser Only");
                queue = new TokenQueue();
                queue.Tokeniser = new Notation3Tokeniser(new StreamReader(file));
                Console.WriteLine("# Test Started at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                queue.InitialiseBuffer();
                Console.WriteLine("# Test Finished at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));


                //Use Notation 3 Parser
                if (!tokeniseOnly)
                {
                    Debug.WriteLine("Testing file " + file + " using Notation 3 Parser");
                    Console.WriteLine("# Using Notation 3 Parser");
                    Console.WriteLine("# Test Started at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                    start = DateTime.Now;
                    Debug.WriteLine("Start " + start.ToString(TestSuite.TestSuiteTimeFormat));
                    Test(file, n3parser, output);
                    Console.WriteLine("# Test Finished at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                    end = DateTime.Now;
                    diff = Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Second, start, end, Microsoft.VisualBasic.FirstDayOfWeek.Saturday, Microsoft.VisualBasic.FirstWeekOfYear.System);
                    Console.WriteLine("Read Time was " + diff + " seconds");
                    Debug.WriteLine("End " + end.ToString(TestSuite.TestSuiteTimeFormat));
                    Debug.WriteLine("Read Time was " + diff + " seconds");
                    Console.WriteLine();
                }
            }

            output.Close();

        }