Search in sources :

Example 16 with Token

use of org.apache.jena.riot.tokens.Token in project jena by apache.

the class LangTurtleBase method triplesNode.

// A structure of triples that itself generates a node.
// Special checks for [] and ().
protected final Node triplesNode() {
    if (lookingAt(NODE)) {
        Node n = node();
        nextToken();
        return n;
    }
    // Special words.
    if (lookingAt(TokenType.KEYWORD)) {
        Token tErr = peekToken();
        // Location independent node words
        String image = peekToken().getImage();
        nextToken();
        if (image.equals(KW_TRUE))
            return NodeConst.nodeTrue;
        if (image.equals(KW_FALSE))
            return NodeConst.nodeFalse;
        if (image.equals(KW_A))
            exception(tErr, "Keyword 'a' not legal at this point");
        exception(tErr, "Unrecognized keyword: " + image);
    }
    return triplesNodeCompound();
}
Also used : Node(org.apache.jena.graph.Node) Token(org.apache.jena.riot.tokens.Token)

Example 17 with Token

use of org.apache.jena.riot.tokens.Token in project jena by apache.

the class LangTurtleBase method triplesBlankNode.

protected final Node triplesBlankNode() {
    // Skip [
    Token t = nextToken();
    Node subject = profile.createBlankNode(currentGraph, t.getLine(), t.getColumn());
    triplesBlankNode(subject);
    return subject;
}
Also used : Node(org.apache.jena.graph.Node) Token(org.apache.jena.riot.tokens.Token)

Example 18 with Token

use of org.apache.jena.riot.tokens.Token in project jena by apache.

the class LangTurtleBase method directiveBase.

protected final void directiveBase() {
    Token token = peekToken();
    if (!lookingAt(IRI))
        exception(token, "@base requires an IRI (found '" + token + "')");
    String baseStr = token.getImage();
    IRI baseIRI = profile.makeIRI(baseStr, currLine, currCol);
    emitBase(baseIRI.toString());
    nextToken();
    IRIResolver newResolver = IRIResolver.create(baseIRI);
    profile.setIRIResolver(newResolver);
}
Also used : IRI(org.apache.jena.riot.tokens.TokenType.IRI) IRI(org.apache.jena.iri.IRI) Token(org.apache.jena.riot.tokens.Token)

Example 19 with Token

use of org.apache.jena.riot.tokens.Token in project jena by apache.

the class JSONInputIterator method parseNode.

private Node parseNode() {
    String type, value, lang, datatype;
    type = value = lang = datatype = null;
    if (lookingAt(TokenType.LBRACE)) {
        Token pos = nextToken();
        // Collect the Properties
        do {
            if (isPropertyName()) {
                Token t = nextToken();
                String name = t.getImage();
                checkColon();
                if (name.equals("type")) {
                    if (type != null)
                        exception(t, "Illegal duplicate type property");
                    type = parseNodeInfo("type");
                } else if (name.equals("value")) {
                    if (value != null)
                        exception(t, "Illegal duplicate value property");
                    value = parseNodeInfo("value");
                } else if (name.equals("datatype")) {
                    if (datatype != null)
                        exception(t, "Illegal duplicate datatype property");
                    datatype = parseNodeInfo("datatype");
                } else if (name.equals("xml:lang")) {
                    if (lang != null)
                        exception(t, "Illegal duplicate xml:lang property");
                    lang = parseNodeInfo("xml:lang");
                } else {
                    exception(t, "Unexpected Property Name '%s', expected one of type, value, datatype or xml:lang", name);
                }
            } else if (lookingAt(TokenType.RBRACE)) {
                nextToken();
                break;
            } else {
                exception(peekToken(), "Unexpected Token, expected a property name as part of a Node object");
            }
        } while (true);
        // Error if missing type or value
        if (type == null)
            exception(pos, "Encountered a Node object with no type property");
        if (value == null)
            exception(pos, "Encountered a Node object with no value property");
        // Generate a Node based on the properties we saw
        if (type.equals("uri")) {
            return NodeFactory.createURI(value);
        } else if (type.equals("literal")) {
            if (datatype != null) {
                return NodeFactory.createLiteral(value, TypeMapper.getInstance().getSafeTypeByName(datatype));
            } else if (lang != null) {
                return NodeFactory.createLiteral(value, lang);
            } else {
                return NodeFactory.createLiteral(value);
            }
        } else if (type.equals("bnode")) {
            return NodeFactory.createBlankNode(value);
        } else {
            exception(pos, "Encountered a Node object with an invalid type value '%s', expected one of uri, literal or bnode", type);
        }
    } else {
        exception(peekToken(), "Unexpected Token, expected a { for the start of a Node object");
    }
    return null;
}
Also used : Token(org.apache.jena.riot.tokens.Token)

Example 20 with Token

use of org.apache.jena.riot.tokens.Token in project jena by apache.

the class JSONInputIterator method parseNextBinding.

private boolean parseNextBinding() {
    if (lookingAt(TokenType.LBRACE)) {
        nextToken();
        BindingMap b = BindingFactory.create();
        do {
            if (isPropertyName()) {
                Token t = nextToken();
                String var = t.getImage();
                checkColon();
                Node n = parseNode();
                b.add(Var.alloc(var), n);
                checkComma(TokenType.RBRACE);
            } else if (lookingAt(TokenType.RBRACE)) {
                nextToken();
                checkComma(TokenType.RBRACKET);
                break;
            } else {
                exception(peekToken(), "Unexpected Token encountered, expected a property name to indicate the value for a variable");
            }
        } while (true);
        this.binding = b;
        return true;
    } else if (lookingAt(TokenType.RBRACKET)) {
        // End of Bindings Array
        nextToken();
        if (lookingAt(TokenType.RBRACE)) {
            nextToken();
            parseToEnd();
        } else {
            exception(peekToken(), "Unexpected Token encountered, expected a } to end the results object");
        }
    } else {
        exception(peekToken(), "Unexpected Token encountered, expected a { for the start of a binding of ] to end the array of bindings");
    }
    return false;
}
Also used : Node(org.apache.jena.graph.Node) Token(org.apache.jena.riot.tokens.Token) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Aggregations

Token (org.apache.jena.riot.tokens.Token)40 Node (org.apache.jena.graph.Node)16 RiotException (org.apache.jena.riot.RiotException)4 Tokenizer (org.apache.jena.riot.tokens.Tokenizer)4 AtlasException (org.apache.jena.atlas.AtlasException)2 RiotParseException (org.apache.jena.riot.RiotParseException)2 InputStream (java.io.InputStream)1 NoSuchElementException (java.util.NoSuchElementException)1 NotImplemented (org.apache.jena.atlas.lib.NotImplemented)1 Timer (org.apache.jena.atlas.lib.Timer)1 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)1 IRI (org.apache.jena.iri.IRI)1 LabelToNode (org.apache.jena.riot.lang.LabelToNode)1 StreamRowRDF (org.apache.jena.riot.system.StreamRowRDF)1 StringType (org.apache.jena.riot.tokens.StringType)1 IRI (org.apache.jena.riot.tokens.TokenType.IRI)1 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)1 TDBException (org.apache.jena.tdb.TDBException)1