Search in sources :

Example 41 with MapBindingSet

use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.

the class GeoFunctionsIT method GeoDistance.

@Test
public void GeoDistance() throws Exception {
    final String sparql = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> " + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> " + "PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/> " + "SELECT ?cityA ?cityB " + "WHERE { " + "?cityA <urn:containedIn> ?continent. " + "?cityB <urn:containedIn> ?continent. " + "?cityA geo:asWKT ?coord1 . " + "?cityB geo:asWKT ?coord2 . " + // from brussels 173km to amsterdam
    " FILTER ( 500000 > geof:distance(?coord1, ?coord2, uom:metre)  ) . " + " FILTER ( !sameTerm (?cityA, ?cityB) ) " + "}";
    final ValueFactory vf = new ValueFactoryImpl();
    final URI wktTypeUri = vf.createURI("http://www.opengis.net/ont/geosparql#wktLiteral");
    final URI asWKT = vf.createURI("http://www.opengis.net/ont/geosparql#asWKT");
    final Set<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#dakar"), asWKT, vf.createLiteral("Point(-17.45 14.69)", wktTypeUri)), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#dakar2"), asWKT, vf.createLiteral("Point(-17.45 14.69)", wktTypeUri)), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#canberra"), asWKT, vf.createLiteral("Point(149.12 -35.31)", wktTypeUri)), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#brussels"), asWKT, vf.createLiteral("Point(4.35 50.85)", wktTypeUri)), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#amsterdam"), asWKT, vf.createLiteral("Point(4.9 52.37)", wktTypeUri)), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#amsterdam"), vf.createURI("urn:containedIn"), vf.createLiteral("Europe")), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#dakar"), vf.createURI("urn:containedIn"), vf.createLiteral("Africa")), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#dakar2"), vf.createURI("urn:containedIn"), vf.createLiteral("Africa")), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#brussels"), vf.createURI("urn:containedIn"), vf.createLiteral("Europe")));
    // The expected results of the SPARQL query once the PCJ has been computed.l
    final Set<BindingSet> expectedResults = new HashSet<>();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("cityA", vf.createURI("tag:rya.apache.org,2017:ex#dakar"));
    bs.addBinding("cityB", vf.createURI("tag:rya.apache.org,2017:ex#dakar2"));
    expectedResults.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("cityA", vf.createURI("tag:rya.apache.org,2017:ex#dakar2"));
    bs.addBinding("cityB", vf.createURI("tag:rya.apache.org,2017:ex#dakar"));
    expectedResults.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("cityA", vf.createURI("tag:rya.apache.org,2017:ex#brussels"));
    bs.addBinding("cityB", vf.createURI("tag:rya.apache.org,2017:ex#amsterdam"));
    expectedResults.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("cityA", vf.createURI("tag:rya.apache.org,2017:ex#amsterdam"));
    bs.addBinding("cityB", vf.createURI("tag:rya.apache.org,2017:ex#brussels"));
    expectedResults.add(bs);
    runTest(sparql, statements, expectedResults);
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) URI(org.openrdf.model.URI) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 42 with MapBindingSet

use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.

the class GeoFunctionsIT method withGeoFilters.

@Test
public void withGeoFilters() throws Exception {
    final String sparql = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> " + "PREFIX ryageo: <tag:rya.apache.org,2017:function/geo#> " + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> " + "SELECT ?feature ?point ?wkt {" + " ?feature a geo:Feature . " + " ?feature geo:hasGeometry ?point . " + " ?point a geo:Point . " + " ?point geo:asWKT ?wkt . " + " FILTER(ryageo:ehContains(?wkt, \"POLYGON((-77 39, -76 39, -76 38, -77 38, -77 39))\"^^geo:wktLiteral)) " + "}";
    final ValueFactory vf = new ValueFactoryImpl();
    final Set<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#feature"), vf.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), vf.createURI("http://www.opengis.net/ont/geosparql#Feature")), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#feature"), vf.createURI("http://www.opengis.net/ont/geosparql#hasGeometry"), vf.createURI("tag:rya.apache.org,2017:ex#test_point")), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#test_point"), vf.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), vf.createURI("http://www.opengis.net/ont/geosparql#Point")), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#test_point"), vf.createURI("http://www.opengis.net/ont/geosparql#asWKT"), vf.createLiteral("Point(-77.03524 38.889468)", vf.createURI("http://www.opengis.net/ont/geosparql#wktLiteral"))));
    // Create a Geo function.
    final Function geoFunction = new Function() {

        @Override
        public String getURI() {
            return "tag:rya.apache.org,2017:function/geo#ehContains";
        }

        @Override
        public Value evaluate(final ValueFactory valueFactory, final Value... args) throws ValueExprEvaluationException {
            if (args.length != 2) {
                throw new ValueExprEvaluationException(getURI() + " requires exactly 3 arguments, got " + args.length);
            }
            return valueFactory.createLiteral(true);
        }
    };
    // Add our new function to the registry
    FunctionRegistry.getInstance().add(geoFunction);
    // The expected results of the SPARQL query once the PCJ has been computed.
    final Set<BindingSet> expectedResults = new HashSet<>();
    final MapBindingSet bs = new MapBindingSet();
    bs.addBinding("wkt", vf.createLiteral("Point(-77.03524 38.889468)", vf.createURI("http://www.opengis.net/ont/geosparql#wktLiteral")));
    bs.addBinding("feature", vf.createURI("tag:rya.apache.org,2017:ex#feature"));
    bs.addBinding("point", vf.createURI("tag:rya.apache.org,2017:ex#test_point"));
    expectedResults.add(bs);
    runTest(sparql, statements, expectedResults);
}
Also used : Function(org.openrdf.query.algebra.evaluation.function.Function) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Value(org.openrdf.model.Value) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) ValueExprEvaluationException(org.openrdf.query.algebra.evaluation.ValueExprEvaluationException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 43 with MapBindingSet

use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.

the class GeoFunctionsIT method withTemporal.

@Test
public void withTemporal() throws Exception {
    // Find all stored dates.
    final String sparql = "PREFIX time: <http://www.w3.org/2006/time#> " + "PREFIX xml: <http://www.w3.org/2001/XMLSchema#> " + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> " + "SELECT ?event ?time { " + "?event time:inXSDDateTime ?time . " + // after 3 seconds
    "FILTER(?time > '2001-01-01T01:01:03-08:00'^^xml:dateTime) " + // 2006/12/31 include 2006, not 2007,8
    "FILTER('2007-01-01T01:01:01+09:00'^^xml:dateTime > ?time ) " + "}";
    // create some resources and literals to make statements out of
    final ValueFactory vf = new ValueFactoryImpl();
    final DatatypeFactory dtf = DatatypeFactory.newInstance();
    final URI dtPredUri = vf.createURI("http://www.w3.org/2006/time#inXSDDateTime");
    final URI eventz = vf.createURI("<http://eventz>");
    final Set<Statement> statements = Sets.newHashSet(vf.createStatement(eventz, vf.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), vf.createURI("<http://www.w3.org/2006/time#Instant>")), // 1 second
    vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T01:01:01-08:00"))), // 2 seconds
    vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T04:01:02.000-05:00"))), // 3 seconds
    vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T01:01:03-08:00"))), // 4 seconds
    vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T01:01:03.999-08:00"))), // 5 seconds
    vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T09:01:05Z"))), vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2006-01-01T05:00:00.000Z"))), vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2007-01-01T05:00:00.000Z"))), vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2008-01-01T05:00:00.000Z"))));
    final Set<BindingSet> expectedResults = new HashSet<>();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("time", vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T09:01:05.000Z")));
    bs.addBinding("event", eventz);
    expectedResults.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("time", vf.createLiteral(dtf.newXMLGregorianCalendar("2006-01-01T05:00:00.000Z")));
    bs.addBinding("event", eventz);
    expectedResults.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("time", vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T09:01:03.999Z")));
    bs.addBinding("event", eventz);
    expectedResults.add(bs);
    runTest(sparql, statements, expectedResults);
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) DatatypeFactory(javax.xml.datatype.DatatypeFactory) Statement(org.openrdf.model.Statement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) URI(org.openrdf.model.URI) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 44 with MapBindingSet

use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.

the class MongoDBQueryEngineIT method bindingSetsQuery.

@SuppressWarnings("unchecked")
@Test
public void bindingSetsQuery() throws Exception {
    final MongoDBRyaDAO dao = new MongoDBRyaDAO();
    try (final MongoDBQueryEngine engine = new MongoDBQueryEngine()) {
        engine.setConf(conf);
        // Add data.
        dao.setConf(conf);
        dao.init();
        dao.add(getStatement("u:a", "u:tt", "u:b"));
        dao.add(getStatement("u:a", "u:tt", "u:c"));
        // Run the test.
        final RyaStatement s = getStatement("u:a", null, null);
        final MapBindingSet bs1 = new MapBindingSet();
        bs1.addBinding("foo", new URIImpl("u:x"));
        final Map.Entry<RyaStatement, BindingSet> e1 = new RdfCloudTripleStoreUtils.CustomEntry<>(s, bs1);
        final Collection<Entry<RyaStatement, BindingSet>> stmts1 = Lists.newArrayList(e1);
        assertEquals(2, size(engine.queryWithBindingSet(stmts1, conf)));
        final MapBindingSet bs2 = new MapBindingSet();
        bs2.addBinding("foo", new URIImpl("u:y"));
        final Map.Entry<RyaStatement, BindingSet> e2 = new RdfCloudTripleStoreUtils.CustomEntry<>(s, bs2);
        final Collection<Entry<RyaStatement, BindingSet>> stmts2 = Lists.newArrayList(e1, e2);
        assertEquals(4, size(engine.queryWithBindingSet(stmts2, conf)));
    } finally {
        dao.destroy();
    }
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) Entry(java.util.Map.Entry) RyaStatement(org.apache.rya.api.domain.RyaStatement) URIImpl(org.openrdf.model.impl.URIImpl) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Map(java.util.Map) Test(org.junit.Test)

Example 45 with MapBindingSet

use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.

the class BindingSetStringConverterTest method toString_URIs.

@Test
public void toString_URIs() throws BindingSetConversionException {
    // Setup the binding set that will be converted.
    final MapBindingSet originalBindingSet = new MapBindingSet();
    originalBindingSet.addBinding("x", new URIImpl("http://a"));
    originalBindingSet.addBinding("y", new URIImpl("http://b"));
    originalBindingSet.addBinding("z", new URIImpl("http://c"));
    // Convert it to a String.
    final VariableOrder varOrder = new VariableOrder("y", "z", "x");
    final BindingSetConverter<String> converter = new BindingSetStringConverter();
    final String bindingSetString = converter.convert(originalBindingSet, varOrder);
    // Ensure it converted to the expected result.
    final String expected = "http://b<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::" + "http://c<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::" + "http://a<<~>>http://www.w3.org/2001/XMLSchema#anyURI";
    assertEquals(expected, bindingSetString);
}
Also used : URIImpl(org.openrdf.model.impl.URIImpl) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Aggregations

MapBindingSet (org.openrdf.query.impl.MapBindingSet)174 Test (org.junit.Test)155 ValueFactory (org.openrdf.model.ValueFactory)99 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)96 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)91 BindingSet (org.openrdf.query.BindingSet)84 HashSet (java.util.HashSet)81 Statement (org.openrdf.model.Statement)43 URIImpl (org.openrdf.model.impl.URIImpl)31 ArrayList (java.util.ArrayList)30 VisibilityStatement (org.apache.rya.api.model.VisibilityStatement)24 UUID (java.util.UUID)23 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)20 TopologyFactory (org.apache.rya.streams.kafka.topology.TopologyFactory)20 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)19 RandomUUIDFactory (org.apache.rya.api.function.projection.RandomUUIDFactory)19 Connector (org.apache.accumulo.core.client.Connector)18 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)16 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)15 RyaURI (org.apache.rya.api.domain.RyaURI)14