use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class Rational method testRDFLangString_1.
public void testRDFLangString_1() {
// Registration
RDFDatatype dt = TypeMapper.getInstance().getTypeByName(RDF.langString.getURI());
assertEquals(RDF.dtLangString, dt);
assertTrue(RDF.dtLangString == dt);
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class JenaReader method convert.
private static Node convert(ALiteral lit) {
String dtURI = lit.getDatatypeURI();
if (dtURI == null)
return NodeFactory.createLiteral(lit.toString(), lit.getLang());
if (lit.isWellFormedXML()) {
return NodeFactory.createLiteral(lit.toString(), null, true);
}
RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(dtURI);
return NodeFactory.createLiteral(lit.toString(), dt);
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class NodeFactoryExtra method createLiteralNode.
/** Create a literal Node, when the datatype, if given, is a string */
public static Node createLiteralNode(String lex, String lang, String datatypeURI) {
if (datatypeURI != null && datatypeURI.equals(""))
datatypeURI = null;
if (lang != null && lang.equals(""))
lang = null;
RDFDatatype dType = null;
if (datatypeURI != null)
dType = TypeMapper.getInstance().getSafeTypeByName(datatypeURI);
Node n = NodeFactory.createLiteral(lex, lang, dType);
return n;
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class TextQueryPF method objectToStruct.
/** Deconstruct the node or list object argument and make a StrMatch
* The 'executionTime' flag indciates whether this is for a build time
* static check, or for runtime execution.
*/
private StrMatch objectToStruct(PropFuncArg argObject, boolean executionTime) {
EntityDefinition docDef = textIndex.getDocDef();
if (argObject.isNode()) {
Node o = argObject.getArg();
if (!o.isLiteral()) {
if (executionTime)
log.warn("Object to text query is not a literal");
return null;
}
RDFDatatype dt = o.getLiteralDatatype();
if (dt != null && dt != XSDDatatype.XSDstring) {
log.warn("Object to text query is not a string");
return null;
}
String qs = o.getLiteralLexicalForm();
return new StrMatch(null, qs, null, -1, 0);
}
List<Node> list = argObject.getArgList();
if (list.size() == 0 || list.size() > 4)
throw new TextIndexException("Change in object list size");
Node predicate = null;
// Do not prepend the field name - rely on default field
String field = null;
int idx = 0;
Node x = list.get(0);
// Property?
if (x.isURI()) {
predicate = x;
idx++;
if (idx >= list.size())
throw new TextIndexException("Property specificed but no query string : " + list);
x = list.get(idx);
field = docDef.getField(predicate);
if (field == null) {
log.warn("Predicate not indexed: " + predicate);
return null;
}
}
// String!
if (!x.isLiteral()) {
if (executionTime)
log.warn("Text query string is not a literal " + list);
return null;
}
if (x.getLiteralDatatype() != null && !x.getLiteralDatatype().equals(XSDDatatype.XSDstring)) {
log.warn("Text query is not a string " + list);
return null;
}
String queryString = x.getLiteralLexicalForm();
idx++;
int limit = -1;
float score = 0;
if (idx < list.size()) {
// Limit?
x = list.get(idx);
idx++;
if (!x.isLiteral()) {
if (executionTime)
log.warn("Text query limit is not an integer " + x);
return null;
}
int v = NodeFactoryExtra.nodeToInt(x);
limit = (v < 0) ? -1 : v;
}
//extract extra lang arg if present and if is usable.
String lang = extractArg("lang", list);
if (lang != null && textIndex.getDocDef().getLangField() == null)
log.warn("lang argument is ignored if langField not set in the index configuration");
return new StrMatch(predicate, queryString, lang, limit, score);
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class FBRuleInfGraph method checkLiteral.
/**
* Check a given literal value for a property against the set of
* known range constraints for it.
* @param prop the property node whose range is under scrutiny
* @param triple the statement whose object value is to be checked.
* @return null if the range is legal, otherwise a ValidityReport.Report
* which describes the problem.
*/
public ValidityReport.Report checkLiteral(Node prop, Triple triple) {
Node value = triple.getObject();
List<RDFDatatype> range = getDTRange().get(prop);
if (range != null) {
if (value.isBlank())
return null;
if (!value.isLiteral()) {
return new ValidityReport.Report(true, "dtRange", "Property " + prop + " has a typed range but was given a non literal value " + value);
}
LiteralLabel ll = value.getLiteral();
for (RDFDatatype dt : range) {
if (!dt.isValidLiteral(ll)) {
return new ValidityReport.Report(true, "dtRange", "Property " + prop + " has a typed range " + dt + "that is not compatible with " + value, triple);
}
}
}
return null;
}
Aggregations