Exemple #1
0
        private void TryParseTriple(IRdfHandler handler, IToken s, IToken p, IToken o, Uri graphUri)
        {
            INode subj, pred, obj;

            switch (s.TokenType)
            {
            case Token.BLANKNODEWITHID:
                subj = handler.CreateBlankNode(s.Value.Substring(2));
                break;

            case Token.URI:
                subj = ParserHelper.TryResolveUri(handler, s);
                break;

            default:
                throw ParserHelper.Error("Unexpected Token '" + s.GetType().ToString() + "' encountered, expected a Blank Node/URI as the Subject of a Triple", s);
            }

            switch (p.TokenType)
            {
            case Token.URI:
                pred = ParserHelper.TryResolveUri(handler, p);
                break;

            default:
                throw ParserHelper.Error("Unexpected Token '" + p.GetType().ToString() + "' encountered, expected a URI as the Predicate of a Triple", p);
            }

            switch (o.TokenType)
            {
            case Token.BLANKNODEWITHID:
                obj = handler.CreateBlankNode(o.Value.Substring(2));
                break;

            case Token.LITERAL:
                obj = handler.CreateLiteralNode(o.Value);
                break;

            case Token.LITERALWITHDT:
                String dtUri = ((LiteralWithDataTypeToken)o).DataType;
                obj = handler.CreateLiteralNode(o.Value, new Uri(dtUri.Substring(1, dtUri.Length - 2)));
                break;

            case Token.LITERALWITHLANG:
                obj = handler.CreateLiteralNode(o.Value, ((LiteralWithLanguageSpecifierToken)o).Language);
                break;

            case Token.URI:
                obj = ParserHelper.TryResolveUri(handler, o);
                break;

            default:
                throw ParserHelper.Error("Unexpected Token '" + o.GetType().ToString() + "' encountered, expected a Blank Node/Literal/URI as the Object of a Triple", o);
            }

            if (!handler.HandleTriple(new Triple(subj, pred, obj, graphUri)))
            {
                ParserHelper.Stop();
            }
        }
        private void TryParseResultRow(TokenisingResultParserContext context)
        {
            IToken next = context.Tokens.Peek();

            if (next.TokenType == Token.EOF)
            {
                context.Tokens.Dequeue();
                return;
            }

            bool         allowEOL = true, expectComma = false;
            int          v      = 0;
            SparqlResult result = new SparqlResult();

            while (true)
            {
                next = context.Tokens.Dequeue();
                switch (next.TokenType)
                {
                case Token.BLANKNODEWITHID:
                    if (expectComma)
                    {
                        throw ParserHelper.Error("Unexpected Blank Node, expected a comma between RDF Terms", next);
                    }
                    if (v >= context.Variables.Count)
                    {
                        throw ParserHelper.Error("Too many RDF Terms, only expecting " + context.Variables.Count + " terms", next);
                    }
                    INode blank = context.Handler.CreateBlankNode(next.Value.Substring(2));
                    result.SetValue(context.Variables[v], blank);
                    v++;
                    allowEOL    = true;
                    expectComma = true;
                    break;

                case Token.LITERAL:
                case Token.PLAINLITERAL:
                    if (expectComma)
                    {
                        throw ParserHelper.Error("Unexpected Blank Node, expected a comma between RDF Terms", next);
                    }
                    if (v >= context.Variables.Count)
                    {
                        throw ParserHelper.Error("Too many RDF Terms, only expecting " + context.Variables.Count + " terms", next);
                    }

                    // Try and guess what kind of term this is
                    String lexicalForm = next.Value;
                    INode  value;
                    if (lexicalForm.StartsWith("http://") || lexicalForm.StartsWith("https://") || lexicalForm.StartsWith("mailto:") || lexicalForm.StartsWith("ftp://"))
                    {
                        try
                        {
                            // Guessing a URI if starts with common URI prefix
                            value = ParserHelper.TryResolveUri(context, next);
                        }
                        catch
                        {
                            // If invalid URI fall back to treating as literal
                            value = context.Handler.CreateLiteralNode(lexicalForm);
                        }
                    }
                    else
                    {
                        value = context.Handler.CreateLiteralNode(lexicalForm);
                    }

                    result.SetValue(context.Variables[v], value);
                    v++;
                    allowEOL    = true;
                    expectComma = true;
                    break;

                case Token.EOL:
                    if (allowEOL)
                    {
                        break;
                    }
                    else
                    {
                        if (v == context.Variables.Count - 1)
                        {
                            // If this is the last expected term then this must be an empty term
                            v++;
                            break;
                        }
                        throw ParserHelper.Error("Unexpected End of Line, expected a RDF Term Token", next);
                    }

                case Token.COMMA:
                    if (!expectComma)
                    {
                        // This is an empty field
                        if (v >= context.Variables.Count)
                        {
                            throw ParserHelper.Error("Too many RDF Terms, only expecting " + context.Variables.Count + " terms", next);
                        }
                        v++;
                    }
                    expectComma = false;
                    allowEOL    = false;
                    break;

                case Token.EOF:
                    if (!allowEOL)
                    {
                        throw ParserHelper.Error("Unexpected EOF, expected another RDF Term for the Result Row", next);
                    }
                    break;

                default:
                    throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered", next);
                }

                // Stop when we've hit the End of the Line/File
                if (next.TokenType == Token.EOL || next.TokenType == Token.EOF)
                {
                    break;
                }
            }

            result.SetVariableOrdering(context.Variables);
            if (!context.Handler.HandleResult(result))
            {
                ParserHelper.Stop();
            }
        }
Exemple #3
0
        private void TryParseResultRow(TokenisingResultParserContext context)
        {
            IToken next = context.Tokens.Peek();

            if (next.TokenType == Token.EOF)
            {
                context.Tokens.Dequeue();
                return;
            }

            bool         allowEOL = true, expectTab = false;
            int          v      = 0;
            SparqlResult result = new SparqlResult();

            while (true)
            {
                next = context.Tokens.Dequeue();
                switch (next.TokenType)
                {
                case Token.URI:
                    if (expectTab)
                    {
                        throw ParserHelper.Error("Unexpected URI, expected a Tab between RDF Terms", next);
                    }
                    if (v >= context.Variables.Count)
                    {
                        throw ParserHelper.Error("Too many RDF Terms, only expecting " + context.Variables.Count + " terms", next);
                    }
                    INode uri = ParserHelper.TryResolveUri(context, next);
                    result.SetValue(context.Variables[v], uri);
                    v++;
                    allowEOL  = true;
                    expectTab = true;
                    break;

                case Token.BLANKNODEWITHID:
                    if (expectTab)
                    {
                        throw ParserHelper.Error("Unexpected Blank Node, expected a Tab between RDF Terms", next);
                    }
                    if (v >= context.Variables.Count)
                    {
                        throw ParserHelper.Error("Too many RDF Terms, only expecting " + context.Variables.Count + " terms", next);
                    }
                    INode blank = context.Handler.CreateBlankNode(next.Value.Substring(2));
                    result.SetValue(context.Variables[v], blank);
                    v++;
                    allowEOL  = true;
                    expectTab = true;
                    break;

                case Token.LITERAL:
                case Token.LONGLITERAL:
                case Token.PLAINLITERAL:
                    if (expectTab)
                    {
                        throw ParserHelper.Error("Unexpected Blank Node, expected a Tab between RDF Terms", next);
                    }
                    if (v >= context.Variables.Count)
                    {
                        throw ParserHelper.Error("Too many RDF Terms, only expecting " + context.Variables.Count + " terms", next);
                    }
                    INode lit = TryParseLiteral(context, next);
                    result.SetValue(context.Variables[v], lit);
                    v++;
                    allowEOL  = true;
                    expectTab = true;
                    break;

                case Token.EOL:
                    if (allowEOL)
                    {
                        break;
                    }
                    else
                    {
                        if (v == context.Variables.Count - 1)
                        {
                            // If this is the last expected term then this must be an empty term
                            v++;
                            break;
                        }
                        throw ParserHelper.Error("Unexpected End of Line, expected a RDF Term Token", next);
                    }

                case Token.TAB:
                    if (!expectTab)
                    {
                        // This is an empty field
                        if (v >= context.Variables.Count)
                        {
                            throw ParserHelper.Error("Too many RDF Terms, only expecting " + context.Variables.Count + " terms", next);
                        }
                        v++;
                    }
                    expectTab = false;
                    allowEOL  = false;
                    break;

                case Token.EOF:
                    if (!allowEOL)
                    {
                        throw ParserHelper.Error("Unexpected EOF, expected another RDF Term for the Result Row", next);
                    }
                    break;

                default:
                    throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered", next);
                }

                // Stop when we've hit the End of the Line/File
                if (next.TokenType == Token.EOL || next.TokenType == Token.EOF)
                {
                    break;
                }
            }

            if (v < context.Variables.Count)
            {
                throw ParserHelper.Error("Too few RDF Terms, got " + v + " but expected " + context.Variables.Count, next);
            }

            result.SetVariableOrdering(context.Variables);
            if (!context.Handler.HandleResult(result))
            {
                ParserHelper.Stop();
            }
        }
        private void TryParseObjectList(TriGParserContext context, Uri graphUri, INode subj, INode pred)
        {
            bool ok = false;

            do
            {
                //After the first run through we'll need to discard commas here
                if (ok)
                {
                    context.Tokens.Dequeue();
                }

                //Try to get the Object
                IToken obj = context.Tokens.Dequeue();
                IToken next;
                INode  objNode;

                switch (obj.TokenType)
                {
                case Token.COMMENT:
                    //Discard and Continue
                    ok = false;
                    continue;

                case Token.QNAME:
                case Token.URI:
                    objNode = ParserHelper.TryResolveUri(context, obj);
                    break;

                case Token.LITERAL:
                case Token.LONGLITERAL:
                    //Literals

                    //See whether we get a Language Specifier/Data Type next
                    next = context.Tokens.Peek();
                    if (next.TokenType == Token.LANGSPEC)
                    {
                        //Literal with Language Specifier
                        context.Tokens.Dequeue();
                        objNode = context.Handler.CreateLiteralNode(obj.Value, next.Value);
                    }
                    else if (next.TokenType == Token.HATHAT)
                    {
                        //Literal with DataType
                        context.Tokens.Dequeue();
                        //Now expect a QName/Uri Token
                        next = context.Tokens.Dequeue();
                        if (next.TokenType == Token.QNAME || next.TokenType == Token.URI)
                        {
                            Uri dt = UriFactory.Create(Tools.ResolveUriOrQName(next, context.Namespaces, context.BaseUri));
                            objNode = context.Handler.CreateLiteralNode(obj.Value, dt);
                        }
                        else
                        {
                            throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered, expected a URI/QName Token to specify a Data Type after a ^^ Token", next);
                        }
                    }
                    else
                    {
                        //Just a string literal
                        objNode = context.Handler.CreateLiteralNode(obj.Value);
                    }
                    break;

                case Token.PLAINLITERAL:
                    //Plain Literals
                    Uri plt = TurtleSpecsHelper.InferPlainLiteralType((PlainLiteralToken)obj, TurtleSyntax.Original);
                    objNode = context.Handler.CreateLiteralNode(obj.Value, plt);
                    break;

                case Token.BLANKNODEWITHID:
                    //Blank Node with ID
                    objNode = context.Handler.CreateBlankNode(obj.Value.Substring(2));
                    break;

                case Token.LEFTSQBRACKET:
                    //Blank Node
                    next = context.Tokens.Peek();
                    if (next.TokenType == Token.RIGHTSQBRACKET)
                    {
                        //Anonymous Blank Node
                        context.Tokens.Dequeue();
                        objNode = context.Handler.CreateBlankNode();
                    }
                    else
                    {
                        //Blank Node Collection
                        objNode = context.Handler.CreateBlankNode();

                        //Do an extra call to TryParsePredicateObjectList to parse the Blank Node Collection
                        this.TryParsePredicateObjectList(context, graphUri, objNode);
                    }
                    break;

                case Token.RIGHTSQBRACKET:
                    //End of Blank Node Collection
                    if (!ok)
                    {
                        throw ParserHelper.Error("Unexpected Token '" + obj.GetType().ToString() + "' encountered before an Object list of a Blank Node Collection was parsed", obj);
                    }
                    return;

                case Token.LEFTBRACKET:
                    //Collection

                    //Check whether an Empty Collection
                    next = context.Tokens.Peek();
                    if (next.TokenType == Token.RIGHTBRACKET)
                    {
                        //Empty Collection
                        context.Tokens.Dequeue();
                        objNode = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListNil));
                    }
                    else
                    {
                        //Collection
                        objNode = context.Handler.CreateBlankNode();
                        this.TryParseCollection(context, graphUri, objNode);
                    }
                    break;

                case Token.EOF:
                    throw ParserHelper.Error("Unexpected End of File while trying to parse Object List", obj);

                case Token.DOT:
                case Token.RIGHTCURLYBRACKET:
                case Token.SEMICOLON:
                    if (!ok)
                    {
                        throw ParserHelper.Error("Unexpected Token '" + obj.GetType().ToString() + "' encountered before an Object list was parsed", obj);
                    }
                    return;

                default:
                    //Unexpected Token
                    throw ParserHelper.Error("Unexpected Token '" + obj.GetType().ToString() + "' encountered, expected a URI/QName/Blank Node as the Object of a Triple", obj);
                }

                ok = true;

                if (!context.Handler.HandleTriple(new Triple(subj, pred, objNode, graphUri)))
                {
                    ParserHelper.Stop();
                }
            } while (context.Tokens.Peek().TokenType == Token.COMMA); //Expect a comma if we are to continue
        }
        private void TryParseCollection(TriGParserContext context, Uri graphUri, INode subj)
        {
            //Create the Nodes we need
            IUriNode rdfFirst, rdfRest, rdfNil;

            rdfFirst = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListFirst));
            rdfRest  = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListRest));
            rdfNil   = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListNil));

            IToken next;
            INode  item, temp;

            item = null;
            do
            {
                next = context.Tokens.Dequeue();

                //Create a Node for this Token
                switch (next.TokenType)
                {
                case Token.COMMENT:
                    //Discard and continue;
                    continue;

                case Token.QNAME:
                case Token.URI:
                    item = ParserHelper.TryResolveUri(context, next);
                    break;

                case Token.LITERAL:
                case Token.LONGLITERAL:

                    break;

                case Token.PLAINLITERAL:
                    Uri plt = TurtleSpecsHelper.InferPlainLiteralType((PlainLiteralToken)next, TurtleSyntax.Original);
                    item = context.Handler.CreateLiteralNode(next.Value, plt);
                    break;

                case Token.LEFTSQBRACKET:
                    //Check whether an anonymous Blank Node or a Blank Node Collection
                    item = context.Handler.CreateBlankNode();

                    next = context.Tokens.Peek();
                    if (next.TokenType == Token.RIGHTSQBRACKET)
                    {
                        //Anonymous Blank Node
                        context.Tokens.Dequeue();
                    }
                    else
                    {
                        //Blank Node Collection
                        this.TryParsePredicateObjectList(context, graphUri, item);
                    }
                    break;

                case Token.LEFTBRACKET:
                    //Check whether an Empty Collection
                    next = context.Tokens.Peek();
                    if (next.TokenType == Token.RIGHTBRACKET)
                    {
                        //Empty Collection
                        context.Tokens.Dequeue();
                        item = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListNil));
                    }
                    else
                    {
                        //Collection
                        item = context.Handler.CreateBlankNode();
                        this.TryParseCollection(context, graphUri, item);
                    }
                    break;

                case Token.EOF:
                    throw ParserHelper.Error("Unexpected End of File while trying to parse a Collection", next);

                default:
                    //Unexpected Token
                    throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered, expected a URI/QName/Literal/Blank Node as an item in a Collection", next);
                }

                //Create the subj rdf:first item Triple
                if (!context.Handler.HandleTriple((new Triple(subj, rdfFirst, item, graphUri))))
                {
                    ParserHelper.Stop();
                }

                //Create the rdf:rest Triple
                if (context.Tokens.Peek().TokenType == Token.RIGHTBRACKET)
                {
                    //End of Collection
                    context.Tokens.Dequeue();
                    if (!context.Handler.HandleTriple(new Triple(subj, rdfRest, rdfNil, graphUri)))
                    {
                        ParserHelper.Stop();
                    }
                    return;
                }
                else
                {
                    //Continuing Collection
                    temp = context.Handler.CreateBlankNode();
                    if (!context.Handler.HandleTriple(new Triple(subj, rdfRest, temp, graphUri)))
                    {
                        ParserHelper.Stop();
                    }
                    subj = temp;
                }
            } while (true);
        }
        private void TryParseTriples(TriGParserContext context, Uri graphUri)
        {
            do
            {
                //Try to get the Subject
                IToken subj = context.Tokens.Dequeue();
                INode  subjNode;

                //Turn the Subject Token into a Node
                switch (subj.TokenType)
                {
                case Token.COMMENT:
                    //Discard and continue
                    continue;

                case Token.QNAME:
                case Token.URI:
                    subjNode = ParserHelper.TryResolveUri(context, subj);
                    break;

                case Token.BLANKNODEWITHID:
                    //Blank Node with ID
                    subjNode = context.Handler.CreateBlankNode(subj.Value.Substring(2));
                    break;

                case Token.LEFTSQBRACKET:
                    //Blank Node
                    IToken next = context.Tokens.Peek();
                    if (next.TokenType == Token.RIGHTSQBRACKET)
                    {
                        //Anonymous Blank Node
                        context.Tokens.Dequeue();
                        subjNode = context.Handler.CreateBlankNode();
                    }
                    else
                    {
                        //Blank Node Collection
                        subjNode = context.Handler.CreateBlankNode();

                        //Do an extra call to TryParsePredicateObjectList to parse the Blank Node Collection
                        this.TryParsePredicateObjectList(context, graphUri, subjNode);
                    }
                    break;

                case Token.LEFTBRACKET:
                    //Collection

                    //Check whether an Empty Collection
                    next = context.Tokens.Peek();
                    if (next.TokenType == Token.RIGHTBRACKET)
                    {
                        //Empty Collection
                        context.Tokens.Dequeue();
                        subjNode = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListNil));
                    }
                    else
                    {
                        //Collection
                        subjNode = context.Handler.CreateBlankNode();
                        this.TryParseCollection(context, graphUri, subjNode);
                    }
                    break;

                case Token.PREFIXDIRECTIVE:
                case Token.BASEDIRECTIVE:
                    if (context.Syntax == TriGSyntax.Original)
                    {
                        throw ParserHelper.Error("@base/@prefix directives are not permitted to occur inside a Graph in this version of TriG, later versions of TriG support this feature and may be enabled by changing your syntax setting when you create a TriG Parser", subj);
                    }

                    //Parse the directive then continue
                    this.TryParseDirective(context, subj);
                    continue;

                case Token.EOF:
                    throw ParserHelper.Error("Unexpected End of File while trying to parse Triples", subj);

                default:
                    //Unexpected Token
                    throw ParserHelper.Error("Unexpected Token '" + subj.GetType().ToString() + "' encountered, expected a URI/QName/Blank Node as the Subject of a Triple", subj);
                }

                //Parse the Predicate Object List
                this.TryParsePredicateObjectList(context, graphUri, subjNode);

                //Expect a Dot to Terminate
                if (context.Tokens.LastTokenType != Token.DOT && context.Tokens.LastTokenType != Token.RIGHTCURLYBRACKET)
                {
                    //We only do this if we haven't returned because we already hit the Dot Token/Right Curly Bracket
                    IToken dot = context.Tokens.Dequeue();
                    if (dot.TokenType != Token.DOT && dot.TokenType != Token.RIGHTCURLYBRACKET)
                    {
                        throw ParserHelper.Error("Unexpected Token '" + dot.GetType().ToString() + "' encountered, expected a Dot (Line Terminator) Token to terminate Triples", dot);
                    }
                }

                //If we already hit the Right Curly Bracket return
                if (context.Tokens.LastTokenType == Token.RIGHTCURLYBRACKET)
                {
                    return;
                }
            } while (context.Tokens.Peek().TokenType != Token.RIGHTCURLYBRACKET);

            //Discard the ending Right Curly Bracket
            context.Tokens.Dequeue();
        }
        private void TryParsePredicateObjectList(TriGParserContext context, Uri graphUri, INode subj)
        {
            bool ok = false;

            do
            {
                //After our first run through we'll need to discard semicolons here
                if (ok)
                {
                    context.Tokens.Dequeue();

                    //Watch out for Trailing Semicolons
                    if (context.Tokens.Peek().TokenType == Token.RIGHTSQBRACKET)
                    {
                        //Allow trailing semicolons to terminate Blank Node Collections
                        context.Tokens.Dequeue();
                        return;
                    }
                }

                //Try to get the Predicate
                IToken pred = context.Tokens.Dequeue();
                INode  predNode;

                switch (pred.TokenType)
                {
                case Token.COMMENT:
                    //Discard and continue
                    ok = false;
                    continue;

                case Token.QNAME:
                case Token.URI:
                    predNode = ParserHelper.TryResolveUri(context, pred);
                    break;

                case Token.KEYWORDA:
                    //'a' Keyword
                    predNode = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfType));
                    break;

                case Token.EOF:
                    throw ParserHelper.Error("Unexpected End of File while trying to parse Predicate Object list", pred);

                case Token.DOT:
                case Token.RIGHTCURLYBRACKET:
                    if (!ok)
                    {
                        throw ParserHelper.Error("Unexpected Token '" + pred.GetType().ToString() + "' encountered before a Predicate Object list was parsed", pred);
                    }
                    return;

                case Token.RIGHTSQBRACKET:
                    if (!ok)
                    {
                        throw ParserHelper.Error("Unexpected Token '" + pred.GetType().ToString() + "' encountered before a Predicate Object list of a Blank Node Collection was parsed", pred);
                    }
                    return;

                default:
                    //Unexpected Token
                    throw ParserHelper.Error("Unexpected Token '" + pred.GetType().ToString() + "' encountered, expected a URI/QName as the Predicate of a Triple", pred);
                }

                ok = true;

                //Parse the Object List
                this.TryParseObjectList(context, graphUri, subj, predNode);

                //Return if we hit the Dot Token/Right Curly Bracket/Right Square Bracket
                if (context.Tokens.LastTokenType == Token.DOT ||
                    context.Tokens.LastTokenType == Token.RIGHTCURLYBRACKET ||
                    context.Tokens.LastTokenType == Token.RIGHTSQBRACKET)
                {
                    return;
                }

                //Check for End of Blank Node Collections
                if (context.Tokens.Peek().TokenType == Token.RIGHTSQBRACKET)
                {
                    context.Tokens.Dequeue();
                    return;
                }
            } while (context.Tokens.Peek().TokenType == Token.SEMICOLON); //Expect a semicolon if we are to continue
        }
        /// <summary>
        /// Tries to parse Object lists.
        /// </summary>
        /// <param name="context">Parse Context.</param>
        /// <param name="subj">Subject of the Triples.</param>
        /// <param name="pred">Predicate of the Triples.</param>
        /// <param name="bnodeList">Whether this is a Blank Node Object list.</param>
        private void TryParseObjectList(TurtleParserContext context, INode subj, INode pred, bool bnodeList)
        {
            IToken objToken, next;
            INode  obj = null;

            do
            {
                objToken = context.Tokens.Dequeue();

                if (context.TraceParsing)
                {
                    Console.WriteLine("Attempting to parse an Object List from the Object Token '" + objToken.GetType().ToString() + "'");
                }

                switch (objToken.TokenType)
                {
                case Token.BLANKNODE:
                    obj = context.Handler.CreateBlankNode();
                    break;

                case Token.BLANKNODEWITHID:
                    obj = context.Handler.CreateBlankNode(objToken.Value.Substring(2));
                    break;

                case Token.COMMA:
                    // Discard and continue - set object to null so we know we're expected to complete a triple
                    if (obj != null)
                    {
                        obj = null;
                        continue;
                    }
                    else
                    {
                        throw ParserHelper.Error("Unexpected Comma Triple terminator encountered, expected a valid Object for the current Triple", objToken);
                    }

                case Token.COMMENT:
                    // Discard and ignore
                    continue;

                case Token.DOT:
                    if (obj != null)
                    {
                        // OK to return if we've seen a valid Triple
                        return;
                    }
                    else
                    {
                        throw ParserHelper.Error("Unexpected Dot Triple terminator encountered, expected a valid Object for the current Triple", objToken);
                    }

                case Token.LEFTBRACKET:
                    // Start of a collection so create a new Blank Node to be it's first subject
                    next = context.Tokens.Peek();
                    if (next.TokenType == Token.RIGHTBRACKET)
                    {
                        // Empty Collection => rdf:nil
                        context.Tokens.Dequeue();
                        obj = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListNil));
                    }
                    else
                    {
                        obj = context.Handler.CreateBlankNode();
                        TryParseCollection(context, obj);
                    }
                    break;

                case Token.LEFTSQBRACKET:
                    // Start of a Blank Node collection?
                    next = context.Tokens.Peek();
                    if (next.TokenType == Token.RIGHTSQBRACKET)
                    {
                        // An anonymous Blank Node
                        context.Tokens.Dequeue();
                        obj = context.Handler.CreateBlankNode();
                    }
                    else
                    {
                        // Start of a Blank Node Collection
                        obj = context.Handler.CreateBlankNode();
                        TryParsePredicateObjectList(context, obj, true);
                    }
                    break;

                case Token.LITERAL:
                case Token.LITERALWITHDT:
                case Token.LITERALWITHLANG:
                case Token.LONGLITERAL:
                case Token.PLAINLITERAL:
                    obj = TryParseLiteral(context, objToken);
                    break;

                case Token.RIGHTSQBRACKET:
                    if (bnodeList)
                    {
                        if (obj != null)
                        {
                            // Ok to return if we've seen a Triple
                            return;
                        }
                        else
                        {
                            throw ParserHelper.Error("Unexpected Right Square Bracket encountered, expecting a valid object for the current Blank Node Predicate Object list", objToken);
                        }
                    }
                    else
                    {
                        throw ParserHelper.Error("Unexpected Right Square Bracket encountered but not expecting the end of a Blank Node Predicate Object list", objToken);
                    }

                case Token.SEMICOLON:
                    if (obj != null)
                    {
                        // Ok to return if we've seen a Triple
                        return;
                    }
                    else
                    {
                        throw ParserHelper.Error("Unexpected Semicolon Triple terminator encountered, expected a valid Object for the current Triple", objToken);
                    }

                case Token.QNAME:
                case Token.URI:
                    obj = ParserHelper.TryResolveUri(context, objToken, false, context.QNameUnescapeFunction);
                    break;

                case Token.EOF:
                    throw ParserHelper.Error("Unexpected end of file while trying to parse an Object list", objToken);

                default:
                    throw ParserHelper.Error("Unexpected Token '" + objToken.GetType().ToString() + "' encountered while trying to parse an Object list", objToken);
                }

                // Assert the Triple
                if (!context.Handler.HandleTriple(new Triple(subj, pred, obj)))
                {
                    ParserHelper.Stop();
                }

                // Expect a comma/semicolon/dot terminator if we are to continue
                next = context.Tokens.Peek();
                if (bnodeList)
                {
                    // If in a Blank Node list a dot is not permitted but a ] is
                    if (next.TokenType != Token.COMMA && next.TokenType != Token.SEMICOLON && next.TokenType != Token.RIGHTSQBRACKET)
                    {
                        throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered while trying to parse a Blank Node Object List, expected a comma, semicolon or ] to terminate the current Triple/list", next);
                    }
                }
                else if (next.TokenType != Token.COMMA && next.TokenType != Token.SEMICOLON && next.TokenType != Token.DOT)
                {
                    throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered while trying to parse an Object list, expected a comma, semicolon or dot to terminate the current Triple", next);
                }
            } while (true);
        }
        /// <summary>
        /// Tries to parse Collections.
        /// </summary>
        /// <param name="context">Parser Context.</param>
        /// <param name="firstSubj">Blank Node which is the head of the collection.</param>
        private void TryParseCollection(TurtleParserContext context, INode firstSubj)
        {
            // The opening bracket of the collection will already have been discarded when we get called
            IToken next;
            INode  subj = firstSubj;
            INode  obj = null, nextSubj;
            INode  rdfFirst = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListFirst));
            INode  rdfRest  = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListRest));
            INode  rdfNil   = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListNil));

            do
            {
                next = context.Tokens.Dequeue();

                if (context.TraceParsing)
                {
                    Console.WriteLine("Trying to parse a Collection item from Token '" + next.GetType().ToString() + "'");
                }

                switch (next.TokenType)
                {
                case Token.BLANKNODE:
                    obj = context.Handler.CreateBlankNode();
                    break;

                case Token.BLANKNODEWITHID:
                    obj = context.Handler.CreateBlankNode(next.Value.Substring(2));
                    break;

                case Token.COMMENT:
                    // Discard and continue
                    continue;

                case Token.LEFTBRACKET:
                    // Start of a collection so create a new Blank Node to be it's first subject
                    next = context.Tokens.Peek();
                    if (next.TokenType == Token.RIGHTBRACKET)
                    {
                        // Empty Collection => rdf:nil
                        context.Tokens.Dequeue();
                        obj = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListNil));
                    }
                    else
                    {
                        obj = context.Handler.CreateBlankNode();
                        TryParseCollection(context, obj);
                    }
                    break;

                case Token.LEFTSQBRACKET:
                    // Allowed Blank Node Collections as part of a Collection
                    IToken temp = context.Tokens.Peek();
                    if (temp.TokenType == Token.RIGHTSQBRACKET)
                    {
                        // Anonymous Blank Node
                        context.Tokens.Dequeue();
                        obj = context.Handler.CreateBlankNode();
                    }
                    else
                    {
                        // Blank Node Collection
                        obj = context.Handler.CreateBlankNode();
                        TryParsePredicateObjectList(context, obj, true);
                    }
                    break;

                case Token.LITERAL:
                case Token.LITERALWITHDT:
                case Token.LITERALWITHLANG:
                case Token.LONGLITERAL:
                case Token.PLAINLITERAL:
                    obj = TryParseLiteral(context, next);
                    break;

                case Token.QNAME:
                case Token.URI:
                    obj = ParserHelper.TryResolveUri(context, next, false, context.QNameUnescapeFunction);
                    break;

                case Token.RIGHTBRACKET:
                    // We might terminate here if someone put a comment before the end of the Collection
                    if (!context.Handler.HandleTriple(new Triple(subj, rdfFirst, obj)))
                    {
                        ParserHelper.Stop();
                    }
                    if (!context.Handler.HandleTriple(new Triple(subj, rdfRest, rdfNil)))
                    {
                        ParserHelper.Stop();
                    }
                    return;

                default:
                    throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered while trying to parse a Collection", next);
                }

                // Assert the relevant Triples
                if (!context.Handler.HandleTriple(new Triple(subj, rdfFirst, obj)))
                {
                    ParserHelper.Stop();
                }
                if (context.Tokens.Peek().TokenType == Token.RIGHTBRACKET)
                {
                    // End of the Collection
                    context.Tokens.Dequeue();
                    if (!context.Handler.HandleTriple(new Triple(subj, rdfRest, rdfNil)))
                    {
                        ParserHelper.Stop();
                    }
                    return;
                }
                else
                {
                    // More stuff in the collection
                    nextSubj = context.Handler.CreateBlankNode();
                    if (!context.Handler.HandleTriple(new Triple(subj, rdfRest, nextSubj)))
                    {
                        ParserHelper.Stop();
                    }
                    subj = nextSubj;
                }
            } while (true);
        }
        /// <summary>
        /// Tries to parse Predicate Object lists.
        /// </summary>
        /// <param name="context">Parse Context.</param>
        /// <param name="subj">Subject of the Triples.</param>
        /// <param name="bnodeList">Whether this is a Blank Node Predicate Object list.</param>
        private void TryParsePredicateObjectList(TurtleParserContext context, INode subj, bool bnodeList)
        {
            IToken predToken;
            INode  pred = null;

            do
            {
                predToken = context.Tokens.Dequeue();

                if (context.TraceParsing)
                {
                    Console.WriteLine("Attempting to parse Predicate Object List from the Predicate Token '" + predToken.GetType().ToString() + "'");
                }

                switch (predToken.TokenType)
                {
                case Token.COMMENT:
                    // Discard and continue
                    continue;

                case Token.KEYWORDA:
                    // 'a' Keyword
                    pred = context.Handler.CreateUriNode(UriFactory.Create(NamespaceMapper.RDF + "type"));
                    break;

                case Token.RIGHTSQBRACKET:
                    // If the last token was a semicolon and we're parsing a Blank Node Predicate Object list
                    // then a trailing semicolon is permitted
                    if (bnodeList)
                    {
                        if (context.Tokens.LastTokenType == Token.SEMICOLON)
                        {
                            return;
                        }
                        else
                        {
                            // If Predicate is not null then we've seen at least one valid Triple and this is just the end of the Blank Node Predicate Object list
                            if (pred != null)
                            {
                                return;
                            }
                            else
                            {
                                throw ParserHelper.Error("Unexpected Right Square Bracket encountered while trying to parse a Blank Node Predicate Object list, expected a valid Predicate", predToken);
                            }
                        }
                    }
                    else
                    {
                        throw ParserHelper.Error("Unexpected Right Square Bracket encountered while trying to parse a Predicate Object list", predToken);
                    }

                case Token.QNAME:
                case Token.URI:
                    pred = ParserHelper.TryResolveUri(context, predToken, false, context.QNameUnescapeFunction);
                    break;

                case Token.EOF:
                    throw ParserHelper.Error("Unexpected end of file while trying to parse a Predicate Object list", predToken);

                case Token.SEMICOLON:
                    if (_syntax == TurtleSyntax.Original)
                    {
                        goto default;
                    }

                    // May get a sequence of semicolons
                    IToken next = context.Tokens.Peek();
                    while (next.TokenType == Token.SEMICOLON)
                    {
                        context.Tokens.Dequeue();
                        next = context.Tokens.Peek();
                    }
                    // Bail out of these are followed by a DOT
                    if (next.TokenType == Token.DOT && !bnodeList)
                    {
                        context.Tokens.Dequeue();
                        return;
                    }
                    TryParsePredicateObjectList(context, subj, bnodeList);
                    return;

                default:
                    throw ParserHelper.Error("Unexpected Token '" + predToken.GetType().ToString() + "' encountered while trying to parse a Predicate Object list", predToken);
                }

                TryParseObjectList(context, subj, pred, bnodeList);
                if (context.Tokens.LastTokenType == Token.DOT && !bnodeList)
                {
                    return;                                                          //Dot terminates a normal Predicate Object list
                }
                if (context.Tokens.LastTokenType == Token.RIGHTSQBRACKET && bnodeList)
                {
                    return;                                                                    //Trailing semicolon may terminate a Blank Node Predicate Object list
                }
                if (context.Tokens.LastTokenType == Token.SEMICOLON && context.Tokens.Peek().TokenType == Token.DOT)
                {
                    // Dot terminates a Predicate Object list with a trailing semicolon
                    context.Tokens.Dequeue();
                    return;
                }
            } while (true);
        }
        /// <summary>
        /// Tries to parse Triples.
        /// </summary>
        /// <param name="context">Parser Context.</param>
        private void TryParseTriples(TurtleParserContext context)
        {
            IToken subjToken = context.Tokens.Dequeue();
            IToken next;
            INode  subj;

            if (context.TraceParsing)
            {
                Console.WriteLine("Attempting to parse Triples from the Subject Token '" + subjToken.GetType().ToString() + "'");
            }

            switch (subjToken.TokenType)
            {
            case Token.BLANKNODE:
                subj = context.Handler.CreateBlankNode();
                break;

            case Token.BLANKNODEWITHID:
                subj = context.Handler.CreateBlankNode(subjToken.Value.Substring(2));
                break;

            case Token.LEFTBRACKET:
                // Start of a collection so create a new Blank Node to be it's first subject
                next = context.Tokens.Peek();
                if (next.TokenType == Token.RIGHTBRACKET)
                {
                    // An Empty Collection => rdf:nil
                    context.Tokens.Dequeue();
                    subj = context.Handler.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfListNil));
                }
                else
                {
                    subj = context.Handler.CreateBlankNode();
                    TryParseCollection(context, subj);
                }
                break;

            case Token.LEFTSQBRACKET:
                // Start of a Blank Node collection?
                next = context.Tokens.Peek();
                if (next.TokenType == Token.RIGHTSQBRACKET)
                {
                    // An anoynmous Blank Node
                    context.Tokens.Dequeue();
                    subj = context.Handler.CreateBlankNode();
                }
                else
                {
                    // Start of a Blank Node Collection
                    subj = context.Handler.CreateBlankNode();
                    TryParsePredicateObjectList(context, subj, true);

                    // In W3C Turtle we are allowed to have a dot to terminate a top level blank node predicate list
                    if (_syntax == TurtleSyntax.W3C)
                    {
                        next = context.Tokens.Peek();
                        if (next.TokenType == Token.DOT)
                        {
                            context.Tokens.Dequeue();
                            return;
                        }
                    }
                }
                break;

            case Token.QNAME:
            case Token.URI:
                subj = ParserHelper.TryResolveUri(context, subjToken, false, context.QNameUnescapeFunction);
                break;

            default:
                throw ParserHelper.Error("Unexpected Token '" + subjToken.GetType().ToString() + "' encountered, this Token is not valid as the subject of a Triple", subjToken);
            }

            TryParsePredicateObjectList(context, subj, false);
        }
        /// <summary>
        /// Internal Helper method which parses the child element of a &lt;binding&gt; element into an <see cref="INode">INode</see>
        /// </summary>
        /// <param name="context">Parser Context</param>
        /// <returns></returns>
        private INode ParseValue(SparqlXmlParserContext context)
        {
            if (context.Input.Name.Equals("uri"))
            {
                return(ParserHelper.TryResolveUri(context, context.Input.ReadElementContentAsString()));
            }
            else if (context.Input.Name.Equals("literal"))
            {
                if (context.Input.AttributeCount == 0)
                {
                    // Literal with no Data Type/Language Specifier
                    return(context.Handler.CreateLiteralNode(HttpUtility.HtmlDecode(context.Input.ReadInnerXml())));
                }
                else if (context.Input.AttributeCount >= 1)
                {
                    String lang = null;
                    Uri    dt   = null;
                    while (context.Input.MoveToNextAttribute())
                    {
                        if (context.Input.Name.Equals("xml:lang"))
                        {
                            // Language is specified
                            lang = context.Input.Value;
                        }
                        else if (context.Input.Name.Equals("datatype"))
                        {
                            // Data Type is specified
                            dt = ((IUriNode)ParserHelper.TryResolveUri(context, context.Input.Value)).Uri;
                        }
                        else
                        {
                            RaiseWarning("SPARQL Result Set has a <literal> element with an unknown attribute '" + context.Input.Name + "'!");
                        }
                    }

                    if (lang != null && dt != null)
                    {
                        throw new RdfParseException("Cannot have both a 'xml:lang' and a 'datatype' attribute on a <literal> element");
                    }

                    context.Input.MoveToContent();
                    if (lang != null)
                    {
                        return(context.Handler.CreateLiteralNode(context.Input.ReadElementContentAsString(), lang));
                    }
                    else if (dt != null)
                    {
                        return(context.Handler.CreateLiteralNode(context.Input.ReadElementContentAsString(), dt));
                    }
                    else
                    {
                        // Just a plain literal with lots of custom attributes
                        return(context.Handler.CreateLiteralNode(HttpUtility.HtmlDecode(context.Input.ReadInnerXml())));
                    }
                }
                else
                {
                    throw new RdfParseException("Unable to Parse a SPARQL Result Set since a <literal> element has too many Attributes, only 1 of 'xml:lang' or 'datatype' may be specified!");
                }
            }
            else if (context.Input.Name.Equals("bnode"))
            {
                String bnodeID = context.Input.ReadElementContentAsString();
                if (bnodeID.StartsWith("_:"))
                {
                    return(context.Handler.CreateBlankNode(bnodeID.Substring(2)));
                }
                else if (bnodeID.Contains("://"))
                {
                    return(context.Handler.CreateBlankNode(bnodeID.Substring(bnodeID.IndexOf("://") + 3)));
                }
                else if (bnodeID.Contains(":"))
                {
                    return(context.Handler.CreateBlankNode(bnodeID.Substring(bnodeID.LastIndexOf(':') + 1)));
                }
                else
                {
                    return(context.Handler.CreateBlankNode(bnodeID));
                }
            }
            else if (context.Input.Name.Equals("unbound"))
            {
                // HACK: This is a really ancient feature of the SPARQL Results XML format (from Working Draft in 2005) which we support to ensure compatability with old pre-standardisation SPARQL endpoints (like 3store based ones)
                context.Input.ReadInnerXml();
                return(null);
            }
            else
            {
                throw new RdfParseException("Unable to Parse a SPARQL Result Set since a <binding> element contains an unexpected element <" + context.Input.Name + ">!");
            }
        }
Exemple #13
0
        /// <summary>
        /// Parser method which parses a Bound Variable Object which occurs within a Binding Object
        /// </summary>
        /// <param name="context">Parser Context</param>
        /// <param name="var">Variable Name</param>
        /// <param name="r">Result Object that is being constructed from the Binding Object</param>
        /// <param name="headSeen"></param>
        private void ParseBoundVariable(SparqlJsonParserContext context, string var, SparqlResult r, bool headSeen)
        {
            String nodeType, nodeLang, nodeDatatype;
            string nodeValue = nodeType = nodeLang = nodeDatatype = null;

            //Can we read the start of an Object
            if (context.Input.Read())
            {
                if (context.Input.TokenType == JsonToken.StartObject)
                {
                    context.Input.Read();

                    while (context.Input.TokenType != JsonToken.EndObject)
                    {
                        String token = context.Input.Value.ToString().ToLower();

                        //Check that we get a Property Value as a String
                        context.Input.Read();
                        if (!IsValidValue(context))
                        {
                            throw Error(context, "Unexpected Token '" + context.Input.TokenType + "' with value '" + context.Input.Value + "' encountered, expected a Property Value describing one of the properties of an Variable Binding");
                        }

                        //Extract the Information from the Object
                        if (token.Equals("value"))
                        {
                            nodeValue = context.Input.Value.ToString();
                        }
                        else if (token.Equals("type"))
                        {
                            nodeType = context.Input.Value.ToString().ToLower();
                        }
                        else if (token.Equals("lang") || token.Equals("xml:lang"))
                        {
                            if (nodeLang == null && nodeDatatype == null)
                            {
                                nodeLang = context.Input.Value.ToString();
                            }
                            else
                            {
                                throw Error(context, "Unexpected Language Property specified for an Object Node where a Language or Datatype has already been specified");
                            }
                        }
                        else if (token.Equals("datatype"))
                        {
                            if (nodeDatatype == null && nodeLang == null)
                            {
                                nodeDatatype = context.Input.Value.ToString();
                            }
                            else
                            {
                                throw Error(context, "Unexpected Datatype Property specified for an Object Node where a Language or Datatype has already been specified");
                            }
                        }
                        else
                        {
                            throw Error(context, "Unexpected Property '" + token + "' specified for an Object Node, only 'value', 'type', 'lang' and 'datatype' are valid properties");
                        }

                        //Get Next Token
                        if (!context.Input.Read())
                        {
                            throw new RdfParseException("Unexpected End of Input while trying to parse a Bound Variable Object");
                        }
                    }

                    //Validate the Information
                    if (nodeType == null)
                    {
                        throw new RdfParseException("Cannot parse a Node from the JSON where no 'type' property was specified in the JSON Object representing the Node");
                    }
                    if (nodeValue == null)
                    {
                        throw new RdfParseException("Cannot parse a Node from the JSON where no 'value' property was specified in the JSON Object representing the Node");
                    }

                    //Turn this information into a Node
                    INode n;
                    if (nodeType.Equals("uri"))
                    {
                        n = ParserHelper.TryResolveUri(context, nodeValue);
                    }
                    else if (nodeType.Equals("bnode"))
                    {
                        if (nodeValue.StartsWith("_:"))
                        {
                            n = context.Handler.CreateBlankNode(nodeValue.Substring(2));
                        }
                        else if (nodeValue.Contains("://"))
                        {
                            n = context.Handler.CreateBlankNode(nodeValue.Substring(nodeValue.IndexOf("://", StringComparison.Ordinal) + 3));
                        }
                        else if (nodeValue.Contains(":"))
                        {
                            n = context.Handler.CreateBlankNode(nodeValue.Substring(nodeValue.LastIndexOf(':') + 1));
                        }
                        else
                        {
                            n = context.Handler.CreateBlankNode(nodeValue);
                        }
                    }
                    else if (nodeType.Equals("literal") || nodeType.Equals("typed-literal"))
                    {
                        if (nodeLang != null)
                        {
                            n = context.Handler.CreateLiteralNode(nodeValue, nodeLang);
                        }
                        else if (nodeDatatype != null)
                        {
                            Uri dtUri = ((IUriNode)ParserHelper.TryResolveUri(context, nodeDatatype)).Uri;
                            n = context.Handler.CreateLiteralNode(nodeValue, dtUri);
                        }
                        else
                        {
                            n = context.Handler.CreateLiteralNode(nodeValue);
                        }
                    }
                    else
                    {
                        throw new RdfParseException("Cannot parse a Node from the JSON where the 'type' property has a value of '" + nodeType + "' which is not one of the permitted values 'uri', 'bnode', 'literal' or 'typed-literal' in the JSON Object representing the Node");
                    }

                    //Check that the Variable was defined in the Header
                    if (!context.Variables.Contains(var))
                    {
                        if (headSeen)
                        {
                            throw new RdfParseException("Unable to Parse a SPARQL Result Set since a Binding Object attempts to bind a value to the variable '" + var + "' which is not defined in the Header Object in the value for the 'vars' property!");
                        }
                        context.Variables.Add(var);
                    }

                    //Add to the result
                    r.SetValue(var, n);
                }
                else
                {
                    throw Error(context, "Unexpected Token '" + context.Input.TokenType + "' with value '" + context.Input.Value + "' encountered, expected the start of a Bound Variable Object");
                }
            }
            else
            {
                throw Error(context, "Unexpected End of Input while trying to parse a Bound Variable Object");
            }
        }
Exemple #14
0
        /// <summary>
        /// Tries to parse Triples
        /// </summary>
        /// <param name="context">Parser Context</param>
        private void TryParseTriples(TokenisingParserContext context)
        {
            IToken subjToken = context.Tokens.Dequeue();
            IToken next;
            INode  subj;

            if (context.TraceParsing)
            {
                Console.WriteLine("Attempting to parse Triples from the Subject Token '" + subjToken.GetType().ToString() + "'");
            }

            switch (subjToken.TokenType)
            {
            case Token.BLANKNODE:
                subj = context.Handler.CreateBlankNode();
                break;

            case Token.BLANKNODEWITHID:
                subj = context.Handler.CreateBlankNode(subjToken.Value.Substring(2));
                break;

            case Token.LEFTBRACKET:
                //Start of a collection so create a new Blank Node to be it's first subject
                next = context.Tokens.Peek();
                if (next.TokenType == Token.RIGHTBRACKET)
                {
                    //An Empty Collection => rdf:nil
                    context.Tokens.Dequeue();
                    subj = context.Handler.CreateUriNode(new Uri(RdfSpecsHelper.RdfListNil));
                }
                else
                {
                    subj = context.Handler.CreateBlankNode();
                    this.TryParseCollection(context, subj);
                }
                break;

            case Token.LEFTSQBRACKET:
                //Start of a Blank Node collection?
                next = context.Tokens.Peek();
                if (next.TokenType == Token.RIGHTSQBRACKET)
                {
                    //An anoynmous Blank Node
                    context.Tokens.Dequeue();
                    subj = context.Handler.CreateBlankNode();
                }
                else
                {
                    //Start of a Blank Node Collection
                    subj = context.Handler.CreateBlankNode();
                    this.TryParsePredicateObjectList(context, subj, true);
                }
                break;

            case Token.QNAME:
            case Token.URI:
                subj = ParserHelper.TryResolveUri(context, subjToken);
                break;

            default:
                throw ParserHelper.Error("Unexpected Token '" + subjToken.GetType().ToString() + "' encountered, this Token is not valid as the subject of a Triple", subjToken);
            }

            this.TryParsePredicateObjectList(context, subj, false);
        }