Esempio n. 1
0
        public StreamingNQuadsParser(GraphFactory factory, StreamReader reader)
        {
            this._factory = factory;;

            NTriplesTokeniser tokeniser = new NTriplesTokeniser(reader);

            tokeniser.NQuadsMode = true;
            this._tokens         = new BufferedTokenQueue(tokeniser);
            this._tokens.InitialiseBuffer();
        }
Esempio n. 2
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="input">Input to load from</param>
        public void Load(IRdfHandler handler, TextReader input)
        {
            if (handler == null)
            {
                throw new RdfParseException("Cannot parse an RDF Dataset using a null handler");
            }
            if (input == null)
            {
                throw new RdfParseException("Cannot parse an RDF Dataset from a null input");
            }

            try
            {
                //Setup Token Queue and Tokeniser
                NTriplesTokeniser tokeniser = new NTriplesTokeniser(input);
                tokeniser.NQuadsMode = true;
                ITokenQueue tokens;
                switch (this._queueMode)
                {
                case TokenQueueMode.AsynchronousBufferDuringParsing:
                    tokens = new AsynchronousBufferedTokenQueue(tokeniser);
                    break;

                case TokenQueueMode.QueueAllBeforeParsing:
                    tokens = new TokenQueue(tokeniser);
                    break;

                case TokenQueueMode.SynchronousBufferDuringParsing:
                default:
                    tokens = new BufferedTokenQueue(tokeniser);
                    break;
                }
                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
                }
            }
        }
Esempio n. 3
0
        public StreamingNTriplesParser(IGraph g, StreamReader reader)
        {
            this._g = g;
            NTriplesTokeniser tokeniser = new NTriplesTokeniser(reader);

            this._tokens = new BufferedTokenQueue(tokeniser);
            this._tokens.InitialiseBuffer();

            //Expect a BOF
            IToken start = this._tokens.Dequeue();

            if (start.TokenType != Token.BOF)
            {
                throw ParserHelper.Error("Unexpected Token '" + start.GetType().ToString() + "' encountered, expected a Beginning of File Token", start);
            }
            IToken next = this._tokens.Peek();

            if (next.TokenType == Token.EOF)
            {
                this._eof = true;
            }
        }
Esempio n. 4
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");
            }
        }
Esempio n. 5
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="input">Input to load from</param>
        public void Load(IRdfHandler handler, TextReader input)
        {
            if (handler == null)
            {
                throw new RdfParseException("Cannot parse an RDF Dataset using a null handler");
            }
            if (input == null)
            {
                throw new RdfParseException("Cannot parse an RDF Dataset from a null input");
            }

            // Check for incorrect stream encoding and issue warning if appropriate
            if (input is StreamReader)
            {
                switch (this.Syntax)
                {
                case NQuadsSyntax.Original:
#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
                    break;

                default:
                    if (!((StreamReader)input).CurrentEncoding.Equals(Encoding.UTF8))
                    {
#if SILVERLIGHT
                        this.RaiseWarning("Expected Input Stream to be encoded as UTF-8 but got a Stream encoded as " + ((StreamReader)input).CurrentEncoding.GetType().Name + " - Please be aware that parsing errors may occur as a result");
#else
                        this.RaiseWarning("Expected Input Stream to be encoded as UTF-8 but got a Stream encoded as " + ((StreamReader)input).CurrentEncoding.EncodingName + " - Please be aware that parsing errors may occur as a result");
#endif
                    }
                    break;
                }
            }

            try
            {
                //Setup Token Queue and Tokeniser
                NTriplesTokeniser tokeniser = new NTriplesTokeniser(input, AsNTriplesSyntax(this.Syntax));
                tokeniser.NQuadsMode = true;
                ITokenQueue tokens;
                switch (this.TokenQueueMode)
                {
                case TokenQueueMode.AsynchronousBufferDuringParsing:
                    tokens = new AsynchronousBufferedTokenQueue(tokeniser);
                    break;

                case TokenQueueMode.QueueAllBeforeParsing:
                    tokens = new TokenQueue(tokeniser);
                    break;

                case TokenQueueMode.SynchronousBufferDuringParsing:
                default:
                    tokens = new BufferedTokenQueue(tokeniser);
                    break;
                }
                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
                }
            }
        }