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();
}
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;
}
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);
}
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;
}
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;
}
Aggregations