use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class FunctionAdapter method adaptValue.
/**
* Convert from OpenRDF to rdf4j value used by Geo Functions.
*
* @param value
* Must be a URIImpl, Literal or a BooleanLiteralImpl, or throws error. Ignores language.
* @param rdf4jValueFactory
* @return an rdf4j Literal copied from the input
*/
public org.eclipse.rdf4j.model.Value adaptValue(Value value, org.eclipse.rdf4j.model.ValueFactory rdf4jValueFactory) {
if (value instanceof URIImpl) {
URIImpl uri = (URIImpl) value;
return rdf4jValueFactory.createIRI(uri.stringValue());
} else if (!(value instanceof Literal)) {
throw new UnsupportedOperationException("Not supported, value must be literal type, it was: " + value.getClass() + " value=" + value);
}
if (value instanceof BooleanLiteralImpl) {
BooleanLiteralImpl bl = (BooleanLiteralImpl) value;
if (bl.booleanValue())
return org.eclipse.rdf4j.model.impl.BooleanLiteral.TRUE;
else
return org.eclipse.rdf4j.model.impl.BooleanLiteral.FALSE;
}
final Literal literalValue = (Literal) value;
org.eclipse.rdf4j.model.ValueFactory vf = org.eclipse.rdf4j.model.impl.SimpleValueFactory.getInstance();
final String label = literalValue.getLabel();
final IRI datatype = vf.createIRI(literalValue.getDatatype().stringValue());
return vf.createLiteral(label, datatype);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class RyaContextTest method testDefaultSerialization.
public void testDefaultSerialization() throws Exception {
RyaContext instance = RyaContext.getInstance();
// plain string
RyaType ryaType = new RyaType("mydata");
byte[] serialize = instance.serialize(ryaType);
assertEquals(ryaType, instance.deserialize(serialize));
// uri
RyaURI ryaURI = new RyaURI("urn:test#1234");
serialize = instance.serialize(ryaURI);
RyaType deserialize = instance.deserialize(serialize);
assertEquals(ryaURI, deserialize);
// custom type
ryaType = new RyaType(new URIImpl("urn:test#customDataType"), "mydata");
serialize = instance.serialize(ryaType);
assertEquals(ryaType, instance.deserialize(serialize));
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class CustomDatatypeResolver method deserialize.
@Override
public RyaType deserialize(final byte[] bytes) throws RyaTypeResolverException {
if (!deserializable(bytes)) {
throw new RyaTypeResolverException("Bytes not deserializable");
}
final RyaType rt = newInstance();
final int length = bytes.length;
final int indexOfType = Bytes.indexOf(bytes, TYPE_DELIM_BYTE);
if (indexOfType < 1) {
throw new RyaTypeResolverException("Not a datatype literal");
}
final String label = deserializeData(new String(bytes, 0, indexOfType, StandardCharsets.UTF_8));
rt.setDataType(new URIImpl(new String(bytes, indexOfType + 1, (length - indexOfType) - 3, StandardCharsets.UTF_8)));
rt.setData(label);
return rt;
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class BatchInformationSerializerTest method testJoinBatchInformationSerialization.
@Test
public void testJoinBatchInformationSerialization() {
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("a", new URIImpl("urn:123"));
bs.addBinding("b", new URIImpl("urn:456"));
VisibilityBindingSet vBis = new VisibilityBindingSet(bs, "FOUO");
JoinBatchInformation batch = JoinBatchInformation.builder().setBatchSize(1000).setTask(Task.Update).setColumn(FluoQueryColumns.PERIODIC_QUERY_BINDING_SET).setSpan(Span.prefix(Bytes.of("prefix346"))).setJoinType(JoinType.LEFT_OUTER_JOIN).setSide(Side.RIGHT).setBs(vBis).build();
byte[] batchBytes = BatchInformationSerializer.toBytes(batch);
Optional<BatchInformation> decodedBatch = BatchInformationSerializer.fromBytes(batchBytes);
assertEquals(batch, decodedBatch.get());
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class GeoTemporalIndexSetProvider method addFilter.
private void addFilter(final FunctionCall call) {
filterURI = new URIImpl(call.getURI());
final Var objVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(filterURI, call.getArgs());
filterMap.put(objVar, new IndexingExpr(filterURI, objectPatterns.get(objVar), GeoParseUtils.extractArguments(objVar.getName(), call)));
}
Aggregations