Search in sources :

Example 41 with URI

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

the class GeoIndexerTest method testDcSearchWithContext.

@Test
public void testDcSearchWithContext() throws Exception {
    // test a ring around dc
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(conf);
        final ValueFactory vf = new ValueFactoryImpl();
        final Resource subject = vf.createURI("foo:subj");
        final URI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createURI("foo:context");
        final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();
        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        // query with correct context
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));
        // query with wrong context
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) StatementConstraints(org.apache.rya.indexing.StatementConstraints) Value(org.openrdf.model.Value) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence) Test(org.junit.Test)

Example 42 with URI

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

the class GeoIndexerTest method testDcSearchWithSubjectAndContext.

@Test
public void testDcSearchWithSubjectAndContext() throws Exception {
    // test a ring around dc
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(conf);
        final ValueFactory vf = new ValueFactoryImpl();
        final Resource subject = vf.createURI("foo:subj");
        final URI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createURI("foo:context");
        final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();
        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        // query with correct context subject
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject))));
        // query with wrong context
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
        // query with wrong subject
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) StatementConstraints(org.apache.rya.indexing.StatementConstraints) Value(org.openrdf.model.Value) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence) Test(org.junit.Test)

Example 43 with URI

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

the class GeoIndexerTest method testDcSearchWithSubject.

@Test
public void testDcSearchWithSubject() throws Exception {
    // test a ring around dc
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(conf);
        final ValueFactory vf = new ValueFactoryImpl();
        final Resource subject = vf.createURI("foo:subj");
        final URI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createURI("foo:context");
        final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();
        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        // query with correct subject
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject))));
        // query with wrong subject
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) StatementConstraints(org.apache.rya.indexing.StatementConstraints) Value(org.openrdf.model.Value) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence) Test(org.junit.Test)

Example 44 with URI

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

the class GeoIndexerTest method testDcSearchWithPredicate.

@Test
public void testDcSearchWithPredicate() throws Exception {
    // test a ring around dc
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(conf);
        final ValueFactory vf = new ValueFactoryImpl();
        final Resource subject = vf.createURI("foo:subj");
        final URI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createURI("foo:context");
        final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();
        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        // query with correct Predicate
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate)))));
        // query with wrong predicate
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createURI("other:pred"))))));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) StatementConstraints(org.apache.rya.indexing.StatementConstraints) Value(org.openrdf.model.Value) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence) Test(org.junit.Test)

Example 45 with URI

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

the class GeoIndexerTest method testPrimeMeridianSearch.

@Test
public void testPrimeMeridianSearch() throws Exception {
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(conf);
        final ValueFactory vf = new ValueFactoryImpl();
        final Resource subject = vf.createURI("foo:subj");
        final URI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createURI("foo:context");
        final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();
        final double[] ONE = { 1, 1, -1, 1, -1, -1, 1, -1, 1, 1 };
        final double[] TWO = { 2, 2, -2, 2, -2, -2, 2, -2, 2, 2 };
        final double[] THREE = { 3, 3, -3, 3, -3, -3, 3, -3, 3, 3 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
        final LinearRing r2 = gf.createLinearRing(new PackedCoordinateSequence.Double(TWO, 2));
        final LinearRing r3 = gf.createLinearRing(new PackedCoordinateSequence.Double(THREE, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        final Polygon p2 = gf.createPolygon(r2, new LinearRing[] {});
        final Polygon p3 = gf.createPolygon(r3, new LinearRing[] {});
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS)));
        // Test a ring with a hole in it
        final Polygon p3m2 = gf.createPolygon(r3, new LinearRing[] { r2 });
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS)));
        // test a ring outside the point
        final double[] OUT = { 3, 3, 1, 3, 1, 1, 3, 1, 3, 3 };
        final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
        final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) Value(org.openrdf.model.Value) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence) Test(org.junit.Test)

Aggregations

URI (org.openrdf.model.URI)368 Test (org.junit.Test)138 Value (org.openrdf.model.Value)122 Resource (org.openrdf.model.Resource)110 Statement (org.openrdf.model.Statement)96 ValueFactory (org.openrdf.model.ValueFactory)83 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)67 URIImpl (org.openrdf.model.impl.URIImpl)58 HashSet (java.util.HashSet)36 RyaURI (org.apache.rya.api.domain.RyaURI)34 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)34 Literal (org.openrdf.model.Literal)34 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)34 StatementImpl (org.openrdf.model.impl.StatementImpl)32 LiteralImpl (org.openrdf.model.impl.LiteralImpl)29 Var (org.openrdf.query.algebra.Var)28 ArrayList (java.util.ArrayList)25 SailConnection (org.openrdf.sail.SailConnection)25 LinearRing (com.vividsolutions.jts.geom.LinearRing)24 Polygon (com.vividsolutions.jts.geom.Polygon)24