use of org.apache.jena.datatypes.RDFDatatype 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.datatypes.RDFDatatype in project jena by apache.
the class CanonicalizeLiteral method apply.
@Override
public Node apply(Node node) {
if (!node.isLiteral())
return node;
if (!node.getLiteralDatatype().isValid(node.getLiteralLexicalForm()))
// Invalid lexical form for the datatype - do nothing.
return node;
RDFDatatype dt = node.getLiteralDatatype();
Node n2;
if (NodeUtils.isLangString(node)) {
// RDF 1.0, no datatype ; RDF 1.1 : datatype is rdf:langString
if (node.getLiteralLanguage().equals(""))
//n2 = NormalizeValue.dtSimpleLiteral.handle(node, node.getLiteralLexicalForm(), null) ;
return node;
else
n2 = canonicalLangtag(node.getLiteralLexicalForm(), node.getLiteralLanguage());
} else if (dt == null) {
// RDF 1.0 / no lang.
n2 = NormalizeValue.dtSimpleLiteral.handle(node, node.getLiteralLexicalForm(), null);
} else {
// Dataype, not rdf:langString (RDF 1.1).
DatatypeHandler handler = dispatch.get(dt);
if (handler == null)
return node;
n2 = handler.handle(node, node.getLiteralLexicalForm(), dt);
}
if (n2 == null)
return node;
return n2;
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class XSDDatatype method isBaseTypeCompatible.
/**
* Test if the given typed value is in the right partition of the XSD type space.
* If this test passes then if the typed value has a legal lexical form for
* this type then it is a legal instance.
*/
public boolean isBaseTypeCompatible(LiteralLabel lit) {
XSTypeDefinition base = getFoundingType();
RDFDatatype litDT = lit.getDatatype();
if (litDT instanceof XSDDatatype) {
XSTypeDefinition litBase = ((XSDDatatype) litDT).getFoundingType();
return base.equals(litBase);
} else if (litDT == null && lit.language().equals("")) {
// Special RDF case, a plain literal is type compatible with and xsd:string-based type
return base.equals(XSDstring.typeDeclaration);
} else {
return false;
}
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class ModelCom method createTypedLiteral.
/**
* Build a typed literal from its value form.
*
* @param value the value of the literal
* @param typeURI the URI of the type of the literal, null for old style "plain" literals
*/
@Override
public Literal createTypedLiteral(Object value, String typeURI) {
RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(typeURI);
LiteralLabel ll = LiteralLabelFactory.createByValue(value, "", dt);
return new LiteralImpl(NodeFactory.createLiteral(ll), this);
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class NodeUtils method stringLiteral.
/** Get lexical for of anything that looks like a string literal.
* Returns the string value of plain literal (simple literal
* or lang string) or XSD string.
*/
public static String stringLiteral(Node literal) {
if (!literal.isLiteral())
return null;
RDFDatatype dType = literal.getLiteralDatatype();
String langTag = literal.getLiteralLanguage();
// Language?
if (langTag != null && !langTag.equals(""))
return literal.getLiteralLexicalForm();
if (dType == null || dType.equals(XSDDatatype.XSDstring))
return literal.getLiteralLexicalForm();
return null;
}
Aggregations