Search in sources :

Example 86 with URIImpl

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);
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Literal(org.openrdf.model.Literal) URIImpl(org.openrdf.model.impl.URIImpl) BooleanLiteralImpl(org.openrdf.model.impl.BooleanLiteralImpl)

Example 87 with URIImpl

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));
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType)

Example 88 with URIImpl

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;
}
Also used : RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException) URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType)

Example 89 with URIImpl

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());
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) JoinBatchInformation(org.apache.rya.indexing.pcj.fluo.app.batch.JoinBatchInformation) BatchInformation(org.apache.rya.indexing.pcj.fluo.app.batch.BatchInformation) URIImpl(org.openrdf.model.impl.URIImpl) JoinBatchInformation(org.apache.rya.indexing.pcj.fluo.app.batch.JoinBatchInformation) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 90 with URIImpl

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)));
}
Also used : Var(org.openrdf.query.algebra.Var) URIImpl(org.openrdf.model.impl.URIImpl) IndexingExpr(org.apache.rya.indexing.IndexingExpr)

Aggregations

URIImpl (org.openrdf.model.impl.URIImpl)170 Test (org.junit.Test)120 LiteralImpl (org.openrdf.model.impl.LiteralImpl)62 URI (org.openrdf.model.URI)58 BindingSet (org.openrdf.query.BindingSet)50 MapBindingSet (org.openrdf.query.impl.MapBindingSet)36 RyaURI (org.apache.rya.api.domain.RyaURI)33 HashSet (java.util.HashSet)31 Statement (org.openrdf.model.Statement)30 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)30 ArrayList (java.util.ArrayList)29 RyaType (org.apache.rya.api.domain.RyaType)25 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)24 RyaStatement (org.apache.rya.api.domain.RyaStatement)23 Value (org.openrdf.model.Value)22 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)22 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)21 StatementPattern (org.openrdf.query.algebra.StatementPattern)20 StatementImpl (org.openrdf.model.impl.StatementImpl)19 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)16