use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class SpatialOperationWithCircleBase method objectToStruct.
/** Deconstruct the node or list object argument and make a NearbyMatch */
@Override
protected SpatialMatch objectToStruct(PropFuncArg argObject) {
// EntityDefinition docDef = server.getDocDef();
if (argObject.isNode()) {
log.warn("Object not a List: " + argObject);
return null;
}
List<Node> list = argObject.getArgList();
if (list.size() < 3 || list.size() > 5)
throw new SpatialIndexException("Change in object list size");
int idx = 0;
Node x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Latitude is not a literal " + list);
return null;
}
if (!SpatialValueUtil.isDecimal(x)) {
log.warn("Latitude is not a decimal " + list);
return null;
}
Double latitude = Double.parseDouble(x.getLiteralLexicalForm());
idx++;
x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Longitude is not a literal " + list);
return null;
}
if (!SpatialValueUtil.isDecimal(x)) {
log.warn("Longitude is not a decimal " + list);
return null;
}
Double longtitude = Double.parseDouble(x.getLiteralLexicalForm());
idx++;
x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Radius is not a literal " + list);
return null;
}
if (!SpatialValueUtil.isDecimal(x)) {
log.warn("Radius is not a decimal " + list);
return null;
}
Double radius = Double.parseDouble(x.getLiteralLexicalForm());
if (radius <= 0) {
log.warn("Radius is not a correct decimal " + list);
return null;
}
// Kilometres
String units = DistanceUnitsUtils.defaultDistanceUnit;
int limit = -1;
idx++;
if (idx < list.size()) {
x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Units or limit is not a literal " + list);
return null;
}
if (x.getLiteralDatatype() == null || x.getLiteralDatatype().equals(XSDDatatype.XSDstring)) {
String u = x.getLiteralLexicalForm();
if (DistanceUnitsUtils.isSupportedUnits(u)) {
idx++;
units = u;
} else {
log.warn("Units are not a supported " + list);
return null;
}
}
}
if (idx < list.size()) {
x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Limit is not a literal " + list);
return null;
}
LiteralLabel lit = x.getLiteral();
if (!XSDDatatype.XSDinteger.isValidLiteral(lit)) {
log.warn("Limit is not an integer " + list);
return null;
}
int v = NodeFactoryExtra.nodeToInt(x);
limit = (v < 0) ? -1 : v;
idx++;
if (idx < list.size()) {
log.warn("Limit is not the last parameter " + list);
return null;
}
}
SpatialMatch match = new SpatialMatch(latitude, longtitude, radius, units, limit, this.getSpatialOperation());
if (log.isDebugEnabled())
log.debug("Trying SpatialMatch: " + match.toString());
return match;
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class NodeValue method nodeToNodeValue.
// ----------------------------------------------------------------
// ---- Setting : used when a node is used to make a NodeValue
private static NodeValue nodeToNodeValue(Node node) {
if (node.isVariable())
Log.warn(NodeValue.class, "Variable passed to NodeValue.nodeToNodeValue");
if (!node.isLiteral())
// Not a literal - no value to extract
return new NodeValueNode(node);
boolean hasLangTag = NodeUtils.isLangString(node);
boolean isPlainLiteral = (node.getLiteralDatatypeURI() == null && !hasLangTag);
if (isPlainLiteral)
return new NodeValueString(node.getLiteralLexicalForm(), node);
if (hasLangTag) {
// Works for RDF 1.0 and RDF 1.1
if (node.getLiteralDatatype() != null && !RDF.dtLangString.equals(node.getLiteralDatatype())) {
if (NodeValue.VerboseWarnings)
Log.warn(NodeValue.class, "Lang tag and datatype (datatype ignored)");
}
return new NodeValueLang(node);
}
// Typed literal
LiteralLabel lit = node.getLiteral();
// Use this - already calculated when the node is formed.
if (!node.getLiteral().isWellFormed()) {
if (NodeValue.VerboseWarnings) {
String tmp = FmtUtils.stringForNode(node);
Log.warn(NodeValue.class, "Datatype format exception: " + tmp);
}
// Invalid lexical form.
return new NodeValueNode(node);
}
NodeValue nv = _setByValue(node);
if (nv != null)
return nv;
return new NodeValueNode(node);
// raise(new ExprException("NodeValue.nodeToNodeValue: Unknown Node type: "+n)) ;
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class ModelCom method createTypedLiteral.
/**
* Build a typed literal from its lexical form. The
* lexical form will be parsed now and the value stored. If
* the form is not legal this will throw an exception.
*
* @param lex the lexical form of the literal
* @param typeURI the uri of the type of the literal, null for old style "plain" literals
* @throws DatatypeFormatException if lex is not a legal form of dtype
*/
@Override
public Literal createTypedLiteral(String lex, String typeURI) {
RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(typeURI);
LiteralLabel ll = LiteralLabelFactory.create(lex, dt);
return new LiteralImpl(NodeFactory.createLiteral(ll), this);
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class Rational method testBinary2.
public void testBinary2() {
// Check round tripping from value
LiteralLabel l2 = m.createTypedLiteral("DCpj", XSDDatatype.XSDbase64Binary).asNode().getLiteral();
Object data2 = l2.getValue();
assertTrue("binary test 3", data2 instanceof byte[]);
byte[] data2b = (byte[]) data2;
assertEquals("binary test 4", data2b[0], data[0]);
assertEquals("binary test 5", data2b[1], data[1]);
assertEquals("binary test 6", data2b[2], data[2]);
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class Rational method doTestRoundTrip.
/**
* Check parse/unparse loop.
*/
public void doTestRoundTrip(String lex, RDFDatatype dt, boolean testeq) {
LiteralLabel ll = LiteralLabelFactory.create(lex, dt);
String lex2 = dt.unparse(ll.getValue());
if (testeq) {
assertEquals(lex, lex2);
}
LiteralLabel ll2 = LiteralLabelFactory.create(lex2, dt);
assertTrue(ll2.isWellFormed());
}
Aggregations