use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class IteratorStreamRDFText method moveToNext.
@Override
protected StreamRowRDF moveToNext() {
if (!in.hasNext())
return null;
List<Token> line = in.next();
StreamRowRDF row = line2row(line);
return row;
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class ParserProfileStd method create.
@Override
public Node create(Node currentGraph, Token token) {
// Dispatches to the underlying ParserFactory operation
long line = token.getLine();
long col = token.getColumn();
String str = token.getImage();
switch(token.getType()) {
case BNODE:
return createBlankNode(currentGraph, str, line, col);
case IRI:
return createURI(str, line, col);
case PREFIXED_NAME:
{
String prefix = str;
String suffix = token.getImage2();
String expansion = expandPrefixedName(prefix, suffix, token);
return createURI(expansion, line, col);
}
case DECIMAL:
return createTypedLiteral(str, XSDDatatype.XSDdecimal, line, col);
case DOUBLE:
return createTypedLiteral(str, XSDDatatype.XSDdouble, line, col);
case INTEGER:
return createTypedLiteral(str, XSDDatatype.XSDinteger, line, col);
case LITERAL_DT:
{
Token tokenDT = token.getSubToken2();
String uriStr;
switch(tokenDT.getType()) {
case IRI:
uriStr = tokenDT.getImage();
break;
case PREFIXED_NAME:
{
String prefix = tokenDT.getImage();
String suffix = tokenDT.getImage2();
uriStr = expandPrefixedName(prefix, suffix, tokenDT);
break;
}
default:
throw new RiotException("Expected IRI for datatype: " + token);
}
uriStr = resolveIRI(uriStr, tokenDT.getLine(), tokenDT.getColumn());
RDFDatatype dt = NodeFactory.getType(uriStr);
return createTypedLiteral(str, dt, line, col);
}
case LITERAL_LANG:
return createLangLiteral(str, token.getImage2(), line, col);
case STRING:
return createStringLiteral(str, line, col);
default:
{
Node x = createNodeFromToken(currentGraph, token, line, col);
if (x != null)
return x;
errorHandler.fatal("Not a valid token for an RDF term: " + token, line, col);
return null;
}
}
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class RiotLib method parse.
/** Parse a string to get one Node (the first token in the string) */
public static Node parse(String string) {
Tokenizer tokenizer = TokenizerFactory.makeTokenizerString(string);
if (!tokenizer.hasNext())
return null;
Token t = tokenizer.next();
Node n = profile.create(null, t);
if (tokenizer.hasNext())
Log.warn(RiotLib.class, "String has more than one token in it: " + string);
return n;
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class JSONInputIterator method parseVars.
private void parseVars() {
if (lookingAt(TokenType.LBRACKET)) {
nextToken();
vars.clear();
do {
if (lookingAt(TokenType.STRING)) {
Token t = nextToken();
String var = t.getImage();
vars.add(var);
checkComma(TokenType.RBRACKET);
} else if (lookingAt(TokenType.RBRACKET)) {
nextToken();
return;
} else {
exception(peekToken(), "Unexpected Token encountered while parsing the variables list in the head object");
}
} while (true);
} else {
exception(peekToken(), "Unexpected Token ecountered, expected a [ to start the array of variables in the head object");
}
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class NodecSSE method decode.
@Override
public Node decode(ByteBuffer bb, PrefixMapping pmap) {
// Ideally, this would be straight from the byte buffer.
// But currently we go bytes -> string -> node
// Byte -> String
String str = BlockUTF8.toString(bb);
// Easy cases.
if (str.startsWith("_:")) {
// Must be done this way.
// In particular, bnode labels can contain ":" from Jena
// TokenizerText does not recognize these.
str = str.substring(2);
return NodeFactory.createBlankNode(str);
}
if (str.startsWith("<")) {
// Do directly.
// (is it quicker?)
str = str.substring(1, str.length() - 1);
str = StrUtils.unescapeString(str);
str = StrUtils.decodeHex(str, MarkerChar);
return NodeFactory.createURI(str);
}
Tokenizer tokenizer = TokenizerFactory.makeTokenizerString(str);
if (!tokenizer.hasNext())
throw new TDBException("Failed to tokenise: " + str);
Token t = tokenizer.next();
try {
Node n = t.asNode();
if (n == null)
throw new TDBException("Not a node: " + str);
return n;
} catch (RiotException ex) {
throw new TDBException("Bad string for node: " + str);
}
}
Aggregations