Search in sources :

Example 31 with StatementImpl

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

the class StatementSerializer method readStatement.

public static Statement readStatement(String subjectString, String predicateString, String objectString, String contextString) {
    Resource subject = createResource(subjectString);
    URI predicate = VALUE_FACTORY.createURI(predicateString);
    boolean isObjectLiteral = objectString.startsWith("\"");
    Value object = null;
    if (isObjectLiteral) {
        object = parseLiteral(objectString);
    } else {
        object = createResource(objectString);
    }
    if (contextString == null || contextString.isEmpty()) {
        return new StatementImpl(subject, predicate, object);
    } else {
        Resource context = VALUE_FACTORY.createURI(contextString);
        return new ContextStatementImpl(subject, predicate, object, context);
    }
}
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) URI(org.openrdf.model.URI)

Example 32 with StatementImpl

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

the class GeoWaveIndexerSfTest method genericStatementGml.

private static Statement genericStatementGml(final Geometry geo, final URI encodingMethod) {
    final ValueFactory vf = new ValueFactoryImpl();
    final Resource subject = vf.createURI("uri:" + NAMES.get(geo));
    final URI predicate = GeoConstants.GEO_AS_GML;
    final String gml;
    if (encodingMethod == USE_JTS_LIB_ENCODING) {
        gml = geoToGmlUseJtsLib(geo);
    } else if (encodingMethod == USE_ROUGH_ENCODING) {
        gml = geoToGmlRough(geo);
    } else {
        throw new Error("invalid encoding method: " + encodingMethod);
    // System.out.println("===created GML====");
    // System.out.println(gml);
    // System.out.println("========== GML====");
    }
    final Value object = vf.createLiteral(gml, GeoConstants.XMLSCHEMA_OGC_GML);
    return new StatementImpl(subject, predicate, object);
}
Also used : 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) LineString(com.vividsolutions.jts.geom.LineString) URI(org.openrdf.model.URI)

Example 33 with StatementImpl

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

the class GeoWaveIndexerSfTest method genericStatementWkt.

private static Statement genericStatementWkt(final Geometry geo) {
    final ValueFactory vf = new ValueFactoryImpl();
    final Resource subject = vf.createURI("uri:" + NAMES.get(geo));
    final URI predicate = GeoConstants.GEO_AS_WKT;
    final Value object = vf.createLiteral(geo.toString(), GeoConstants.XMLSCHEMA_OGC_WKT);
    return new StatementImpl(subject, predicate, object);
}
Also used : 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 34 with StatementImpl

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

the class AccumuloTemporalIndexerTest method testStoreStatementBadInterval.

/**
 * Test method for {@link AccumuloTemporalIndexer#storeStatement(convertStatement(org.openrdf.model.Statement)}
 *
 * @throws NoSuchAlgorithmException
 */
@Test
public void testStoreStatementBadInterval() throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, NoSuchAlgorithmException {
    // count rows expected to store:
    int rowsStoredExpected = 0;
    ValueFactory vf = new ValueFactoryImpl();
    URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
    // Test: Should not store an improper date interval, and log a warning (log warning not tested).
    final String invalidDateIntervalString = "[bad,interval]";
    // Silently logs a warning for bad dates.
    tIndexer.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj1"), pred1_atTime, vf.createLiteral(invalidDateIntervalString))));
    final String validDateIntervalString = "[2016-12-31T20:59:59-05:00,2016-12-31T21:00:00-05:00]";
    tIndexer.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), pred1_atTime, vf.createLiteral(validDateIntervalString))));
    rowsStoredExpected++;
    tIndexer.flush();
    int rowsStoredActual = printTables("junit testing: Temporal intervals stored in testStoreStatement", null, null);
    // 2 index entries per interval statement
    Assert.assertEquals("Only good intervals should be stored.", rowsStoredExpected * 2, rowsStoredActual);
}
Also used : StatementImpl(org.openrdf.model.impl.StatementImpl) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 35 with StatementImpl

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

the class AccumuloTemporalIndexerTest method testStoreStatementsSameTime.

@Test
public void testStoreStatementsSameTime() throws IOException, NoSuchAlgorithmException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {
    ValueFactory vf = new ValueFactoryImpl();
    URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
    URI pred2_circa = vf.createURI(URI_PROPERTY_CIRCA);
    // These are the same datetime instant but from different time
    // zones.
    // This is an arbitrary zone, BRST=Brazil, better if not local.
    final String ZONETestDateInBRST = "2014-12-31T23:59:59-02:00";
    final String ZONETestDateInZulu = "2015-01-01T01:59:59Z";
    final String ZONETestDateInET = "2014-12-31T20:59:59-05:00";
    // These all should be stored because they are in the predicate list.
    // BUT they will get converted to the same exact datetime in UTC.
    // So we have to make the key distinct! Good luck indexer!
    Statement s1 = new StatementImpl(vf.createURI("foo:subj1"), pred2_circa, vf.createLiteral(ZONETestDateInET));
    Statement s2 = new StatementImpl(vf.createURI("foo:subj2"), pred1_atTime, vf.createLiteral(ZONETestDateInZulu));
    Statement s3 = new StatementImpl(vf.createURI("foo:subj3"), pred1_atTime, vf.createLiteral(ZONETestDateInBRST));
    int rowsStoredExpected = 0;
    tIndexer.storeStatement(convertStatement(s1));
    rowsStoredExpected++;
    tIndexer.storeStatement(convertStatement(s2));
    rowsStoredExpected++;
    tIndexer.storeStatement(convertStatement(s3));
    rowsStoredExpected++;
    int rowsStoredActual = printTables("junit testing: Duplicate times stored", null, /*System.out*/
    null);
    Assert.assertEquals("Number of Duplicate times stored, 1 means duplicates not handled correctly.", rowsStoredExpected * 4, rowsStoredActual);
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) StatementImpl(org.openrdf.model.impl.StatementImpl) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) Test(org.junit.Test)

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