Search in sources :

Example 61 with StatementImpl

use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.

the class StatementSerializerTest method testObjectLiteralWithAtSignGarbage.

@Test
public void testObjectLiteralWithAtSignGarbage() throws Exception {
    // test with some garbage in the literal that may throw off the parser
    ValueFactory vf = new ValueFactoryImpl();
    Statement s;
    String str;
    str = "Alice @en";
    s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str));
    Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
    s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str, "en"));
    Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
    s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str, vf.createURI("xsd:string")));
    Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
}
Also used : Statement(org.openrdf.model.Statement) ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) Test(org.junit.Test)

Example 62 with StatementImpl

use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.

the class StatementSerializerTest method testSimpleObjectLiteral.

@Test
public void testSimpleObjectLiteral() throws Exception {
    ValueFactory vf = new ValueFactoryImpl();
    Statement s;
    String str;
    s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createURI("foo:object"));
    Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
    str = "Alice Palace";
    s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str));
    Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
    s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str, "en"));
    Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
    s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str, vf.createURI("xsd:string")));
    Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
}
Also used : Statement(org.openrdf.model.Statement) ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) Test(org.junit.Test)

Example 63 with StatementImpl

use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.

the class Fact method readFields.

@Override
public void readFields(DataInput in) throws IOException {
    derivation = null;
    int tripleLength = in.readInt();
    if (tripleLength == 0) {
        triple = null;
    } else {
        byte[] tripleBytes = new byte[tripleLength];
        in.readFully(tripleBytes);
        String tripleString = new String(tripleBytes, StandardCharsets.UTF_8);
        String[] parts = tripleString.split(SEP);
        ValueFactory factory = ValueFactoryImpl.getInstance();
        String context = parts[0];
        Resource s = null;
        URI p = factory.createURI(parts[2]);
        Value o = null;
        // Subject: either bnode or URI
        if (parts[1].startsWith("_")) {
            s = factory.createBNode(parts[1].substring(2));
        } else {
            s = factory.createURI(parts[1]);
        }
        // Object: literal, bnode, or URI
        if (parts[3].startsWith("_")) {
            o = factory.createBNode(parts[3].substring(2));
        } else if (parts[3].startsWith("\"")) {
            // literal: may have language or datatype
            int close = parts[3].lastIndexOf("\"");
            int length = parts[3].length();
            String label = parts[3].substring(1, close);
            if (close == length - 1) {
                // Just a string enclosed in quotes
                o = factory.createLiteral(label);
            } else {
                String data = parts[3].substring(close + 1);
                if (data.startsWith("@")) {
                    String lang = data.substring(1);
                    o = factory.createLiteral(label, lang);
                } else if (data.startsWith("^^<")) {
                    o = factory.createLiteral(label, factory.createURI(data.substring(3, data.length() - 1)));
                }
            }
        } else {
            o = factory.createURI(parts[3]);
        }
        // Create a statement with or without context
        if (context.isEmpty()) {
            triple = new StatementImpl(s, p, o);
        } else {
            triple = new ContextStatementImpl(s, p, o, factory.createURI(context));
        }
    }
    useful = in.readBoolean();
    if (in.readBoolean()) {
        derivation = new Derivation();
        derivation.readFields(in);
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Resource(org.openrdf.model.Resource) Value(org.openrdf.model.Value) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI)

Example 64 with StatementImpl

use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.

the class GeoFilterIT method statement.

private static Statement statement(final Geometry geo) {
    final ValueFactory vf = new ValueFactoryImpl();
    final Resource subject = vf.createURI("urn:event1");
    final URI predicate = GeoConstants.GEO_AS_WKT;
    final WKTWriter w = new WKTWriter();
    final Value object = vf.createLiteral(w.write(geo), GeoConstants.XMLSCHEMA_OGC_WKT);
    return new StatementImpl(subject, predicate, object);
}
Also used : WKTWriter(com.vividsolutions.jts.io.WKTWriter) StatementImpl(org.openrdf.model.impl.StatementImpl) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) Value(org.openrdf.model.Value) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI)

Example 65 with StatementImpl

use of org.openrdf.model.impl.StatementImpl in project blueprints by tinkerpop.

the class SailGraph method addEdge.

public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label) {
    if (label == null)
        throw ExceptionFactory.edgeLabelCanNotBeNull();
    Value outVertexValue = ((SailVertex) outVertex).getRawVertex();
    Value inVertexValue = ((SailVertex) inVertex).getRawVertex();
    if (!(outVertexValue instanceof Resource)) {
        throw new IllegalArgumentException(outVertex.toString() + " is not a legal URI or blank node");
    }
    try {
        URI labelURI = new URIImpl(this.expandPrefix(label));
        Statement statement = new StatementImpl((Resource) outVertexValue, labelURI, inVertexValue);
        SailHelper.addStatement(statement, this.sailConnection.get());
        return new SailEdge(statement, this);
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : Statement(org.openrdf.model.Statement) StatementImpl(org.openrdf.model.impl.StatementImpl) Value(org.openrdf.model.Value) Resource(org.openrdf.model.Resource) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) SailException(org.openrdf.sail.SailException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RDFHandlerException(org.openrdf.rio.RDFHandlerException)

Aggregations

StatementImpl (org.openrdf.model.impl.StatementImpl)66 Statement (org.openrdf.model.Statement)40 Test (org.junit.Test)34 URI (org.openrdf.model.URI)32 ValueFactory (org.openrdf.model.ValueFactory)27 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)26 Resource (org.openrdf.model.Resource)19 Value (org.openrdf.model.Value)19 URIImpl (org.openrdf.model.impl.URIImpl)19 HashSet (java.util.HashSet)16 LiteralImpl (org.openrdf.model.impl.LiteralImpl)16 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)15 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)14 BindingSet (org.openrdf.query.BindingSet)14 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)14 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)10 PcjTableNameFactory (org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory)10 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)10 TupleQuery (org.openrdf.query.TupleQuery)7 RepositoryConnection (org.openrdf.repository.RepositoryConnection)7