use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class Rational method testBinary1.
/**
* Test binary types base64 and hexbinary
*/
public void testBinary1() {
// Check byte[] maps onto a binary type - specifically base64Binary.
byte[] data = new byte[] { 12, 42, 99 };
Literal l = m.createTypedLiteral(data);
LiteralLabel ll = l.asNode().getLiteral();
assertTrue("binary test 1", ll.getDatatype() instanceof XSDbinary);
// base64 is registered for byte[]
// hexBinary is not registered as a type for byte[]
assertTrue("binary test 1a", ll.getDatatype() instanceof XSDbase64Binary);
assertEquals("binary test 1b", "DCpj", ll.getLexicalForm());
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class Rational method testBinary3.
public void testBinary3() {
// Check hexBinary
Literal l = m.createTypedLiteral(data, XSDDatatype.XSDhexBinary);
LiteralLabel ll = l.asNode().getLiteral();
assertEquals("binary test 1b", ll.getDatatype(), XSDDatatype.XSDhexBinary);
assertEquals("binary test 2b", Hex.encodeHexString(data, false), ll.getLexicalForm());
// Check round tripping from value
LiteralLabel l2 = m.createTypedLiteral(ll.getLexicalForm(), XSDDatatype.XSDhexBinary).asNode().getLiteral();
Object data2 = l2.getValue();
assertTrue("binary test 3b", data2 instanceof byte[]);
byte[] data2b = ((byte[]) data2);
assertEquals("binary test 4b", data2b[0], data[0]);
assertEquals("binary test 5b", data2b[1], data[1]);
assertEquals("binary test 6b", data2b[2], data[2]);
assertEquals(l2, ll);
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class AbstractQueryBuilderTest method testMakeValueNodes.
@Test
public void testMakeValueNodes() {
List<Object> list = new ArrayList<Object>();
list.add(null);
list.add(RDF.type);
Node n2 = NodeFactory.createBlankNode();
list.add(n2);
builder.addPrefix("demo", "http://example.com/");
list.add("demo:type");
list.add("<one>");
list.add(Integer.valueOf(5));
Collection<Node> result = builder.makeValueNodes(list.iterator());
assertEquals(6, result.size());
assertTrue(result.contains(null));
assertTrue(result.contains(RDF.type.asNode()));
assertTrue(result.contains(n2));
assertTrue(result.contains(NodeFactory.createURI("http://example.com/type")));
assertTrue(result.contains(NodeFactory.createURI("one")));
LiteralLabel ll = LiteralLabelFactory.createTypedLiteral(Integer.valueOf(5));
assertTrue(result.contains(NodeFactory.createLiteral(ll)));
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class AbstractQueryBuilderTest method testMakeNode.
@Test
public void testMakeNode() {
Node n = builder.makeNode(null);
assertEquals(Node.ANY, n);
n = builder.makeNode(RDF.type);
assertEquals(RDF.type.asNode(), n);
Node n2 = NodeFactory.createBlankNode();
n = builder.makeNode(n2);
assertEquals(n2, n);
builder.addPrefix("demo", "http://example.com/");
n = builder.makeNode("demo:type");
assertEquals(NodeFactory.createURI("http://example.com/type"), n);
n = builder.makeNode("<one>");
assertEquals(NodeFactory.createURI("one"), n);
try {
n = builder.makeNode(builder);
fail("Should have thrown IllegalArgumentException");
} catch (IllegalArgumentException expected) {
// do nothing
}
n = builder.makeNode(Integer.valueOf(5));
assertTrue(n.isLiteral());
LiteralLabel ll = LiteralLabelFactory.createTypedLiteral(Integer.valueOf(5));
assertEquals(NodeFactory.createLiteral(ll), n);
n = builder.makeNode(NodeFactory.createVariable("foo"));
assertTrue(n.isVariable());
assertEquals("foo", n.getName());
assertTrue(n instanceof Var);
n = builder.makeNode("'text'@en");
assertTrue(n.isLiteral());
assertEquals("text", n.getLiteralLexicalForm());
assertEquals("en", n.getLiteralLanguage());
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class SpatialOperationWithBoxPFBase method objectToStruct.
/** Deconstruct the node or list object argument and make a SpatialMatch */
@Override
protected SpatialMatch objectToStruct(PropFuncArg argObject) {
if (argObject.isNode()) {
log.warn("Object not a List: " + argObject);
return null;
}
List<Node> list = argObject.getArgList();
if (list.size() < 4 || 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 1 is not a literal " + list);
return null;
}
if (!SpatialValueUtil.isDecimal(x)) {
log.warn("Latitude 1 is not a decimal " + list);
return null;
}
Double latitude1 = Double.parseDouble(x.getLiteralLexicalForm());
idx++;
x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Longitude 1 is not a literal " + list);
return null;
}
if (!SpatialValueUtil.isDecimal(x)) {
log.warn("Longitude 1 is not a decimal " + list);
return null;
}
Double longtitude1 = Double.parseDouble(x.getLiteralLexicalForm());
idx++;
x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Latitude 2 is not a literal " + list);
return null;
}
if (!SpatialValueUtil.isDecimal(x)) {
log.warn("Latitude 2 is not a decimal " + list);
return null;
}
Double latitude2 = Double.parseDouble(x.getLiteralLexicalForm());
idx++;
x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Longitude 2 is not a literal " + list);
return null;
}
if (!SpatialValueUtil.isDecimal(x)) {
log.warn("Longitude 2 is not a decimal " + list);
return null;
}
Double longtitude2 = Double.parseDouble(x.getLiteralLexicalForm());
idx++;
int limit = -1;
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(latitude1, longtitude1, latitude2, longtitude2, limit, getSpatialOperation());
if (log.isDebugEnabled())
log.debug("Trying SpatialMatch: " + match.toString());
return match;
}
Aggregations