Search in sources :

Example 81 with Statement

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

the class MongoIndexerDeleteIT method populateRya.

private void populateRya(final SailRepositoryConnection conn) throws Exception {
    final ValueFactory VF = new ValueFactoryImpl();
    // geo 2x2 points
    final GeometryFactory GF = new GeometryFactory();
    for (int x = 0; x <= 1; x++) {
        for (int y = 0; y <= 1; y++) {
            final Geometry geo = GF.createPoint(new Coordinate(x + .5, y + .5));
            final RyaStatement stmnt = statement(geo);
            final Statement statement = RyaToRdfConversions.convertStatement(stmnt);
            conn.add(statement);
        }
    }
    // freetext
    final URI person = VF.createURI("http://example.org/ontology/Person");
    String uuid;
    uuid = "urn:people";
    conn.add(VF.createURI(uuid), RDF.TYPE, person);
    conn.add(VF.createURI(uuid), RDFS.LABEL, VF.createLiteral("Alice Palace Hose", VF.createURI("http://www.w3.org/2001/XMLSchema#string")));
    conn.add(VF.createURI(uuid), RDFS.LABEL, VF.createLiteral("Bob Snob Hose", "en"));
    // temporal
    final TemporalInstant instant = new TemporalInstantRfc3339(1, 2, 3, 4, 5, 6);
    conn.add(VF.createURI("foo:time"), VF.createURI("Property:atTime"), VF.createLiteral(instant.toString()));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactory(org.openrdf.model.ValueFactory) TemporalInstant(org.apache.rya.indexing.TemporalInstant) URI(org.openrdf.model.URI)

Example 82 with Statement

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

the class MongoGeoTemporalIndexer method updateEvent.

private void updateEvent(final RyaURI subject, final RyaStatement statement) throws IndexingException, ParseException {
    final EventStorage eventStore = events.get();
    checkState(events != null, "Must set this indexers configuration before storing statements.");
    new EventUpdater(eventStore).update(subject, old -> {
        final Event.Builder updated;
        if (!old.isPresent()) {
            updated = Event.builder().setSubject(subject);
        } else {
            updated = Event.builder(old.get());
        }
        final URI pred = statement.getObject().getDataType();
        if (pred.equals(GeoConstants.GEO_AS_WKT) || pred.equals(GeoConstants.GEO_AS_GML) || pred.equals(GeoConstants.XMLSCHEMA_OGC_WKT) || pred.equals(GeoConstants.XMLSCHEMA_OGC_GML)) {
            // is geo
            try {
                final Statement geoStatement = RyaToRdfConversions.convertStatement(statement);
                final Geometry geometry = GeoParseUtils.getGeometry(geoStatement, new GmlParser());
                updated.setGeometry(geometry);
            } catch (final ParseException e) {
                LOG.error(e.getMessage(), e);
            }
        } else {
            // is time
            final String dateTime = statement.getObject().getData();
            final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(dateTime);
            if (matcher.find()) {
                final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(dateTime);
                updated.setTemporalInterval(interval);
            } else {
                final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(dateTime));
                updated.setTemporalInstant(instant);
            }
        }
        return Optional.of(updated.build());
    });
}
Also used : Matcher(java.util.regex.Matcher) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) GmlParser(org.apache.rya.indexing.mongodb.geo.GmlParser) TemporalInstant(org.apache.rya.indexing.TemporalInstant) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) Geometry(com.vividsolutions.jts.geom.Geometry) Event(org.apache.rya.indexing.geotemporal.model.Event) ParseException(com.vividsolutions.jts.io.ParseException) TemporalInterval(org.apache.rya.indexing.TemporalInterval) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage)

Example 83 with Statement

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

the class StatementSerializerTest method testSimpleStatementObjectUri.

@Test
public void testSimpleStatementObjectUri() throws Exception {
    ValueFactory vf = new ValueFactoryImpl();
    Statement s;
    s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createURI("foo:object"));
    Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
    s = new ContextStatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createURI("foo:object"), vf.createURI("foo:context"));
    Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) 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 84 with Statement

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

the class StatementSerializerTest method testObjectLiteralWithDataTypeGarbage.

@Test
public void testObjectLiteralWithDataTypeGarbage() 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 ^^<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 85 with Statement

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

the class MongoExecuteSparqlQueryIT method makeTestStatements.

/**
 * @return some data to load
 */
private List<Statement> makeTestStatements() {
    final List<Statement> loadMe = new ArrayList<>();
    final ValueFactory vf = new ValueFactoryImpl();
    loadMe.add(vf.createStatement(vf.createURI("http://example#alice"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#bob")));
    loadMe.add(vf.createStatement(vf.createURI("http://example#bob"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#charlie")));
    loadMe.add(vf.createStatement(vf.createURI("http://example#charlie"), vf.createURI("http://example#likes"), vf.createURI("http://example#icecream")));
    return loadMe;
}
Also used : Statement(org.openrdf.model.Statement) ArrayList(java.util.ArrayList) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory)

Aggregations

Statement (org.openrdf.model.Statement)359 Test (org.junit.Test)209 ValueFactory (org.openrdf.model.ValueFactory)114 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)106 URI (org.openrdf.model.URI)96 HashSet (java.util.HashSet)88 Resource (org.openrdf.model.Resource)69 Value (org.openrdf.model.Value)67 BindingSet (org.openrdf.query.BindingSet)60 RyaStatement (org.apache.rya.api.domain.RyaStatement)56 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)54 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)53 MapBindingSet (org.openrdf.query.impl.MapBindingSet)43 ArrayList (java.util.ArrayList)41 LiteralImpl (org.openrdf.model.impl.LiteralImpl)40 StatementImpl (org.openrdf.model.impl.StatementImpl)40 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)36 URIImpl (org.openrdf.model.impl.URIImpl)30 LinearRing (com.vividsolutions.jts.geom.LinearRing)24 Polygon (com.vividsolutions.jts.geom.Polygon)24