Search in sources :

Example 41 with SailRepositoryConnection

use of org.openrdf.repository.sail.SailRepositoryConnection in project incubator-rya by apache.

the class MongoGeoTemporalIndexIT method variableSubjQuery_Test.

@Test
public void variableSubjQuery_Test() throws Exception {
    final Sail sail = GeoRyaSailFactory.getInstance(conf);
    final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
    try {
        addStatements(conn);
        final String query = "PREFIX time: <http://www.w3.org/2006/time#> \n" + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" + "SELECT * " + "WHERE { " + "  ?subj time:atTime ?time . " + "  ?subj geo:asWKT ?point . " + "  FILTER(geof:sfWithin(?point, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " + "  FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) " + "}";
        final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
        final List<BindingSet> results = new ArrayList<>();
        while (rez.hasNext()) {
            final BindingSet bs = rez.next();
            results.add(bs);
        }
        final MapBindingSet expected1 = new MapBindingSet();
        expected1.addBinding("point", VF.createLiteral("POINT (0 0)"));
        expected1.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z"));
        final MapBindingSet expected2 = new MapBindingSet();
        expected2.addBinding("point", VF.createLiteral("POINT (1 1)"));
        expected2.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z"));
        assertEquals(2, results.size());
        assertEquals(expected1, results.get(0));
        assertEquals(expected2, results.get(1));
    } finally {
        conn.close();
        sail.shutDown();
    }
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) ArrayList(java.util.ArrayList) MapBindingSet(org.openrdf.query.impl.MapBindingSet) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) TupleQueryResult(org.openrdf.query.TupleQueryResult) Test(org.junit.Test)

Example 42 with SailRepositoryConnection

use of org.openrdf.repository.sail.SailRepositoryConnection in project incubator-rya by apache.

the class MongoGeoTemporalIndexIT method constantSubjQuery_Test.

@Test
public void constantSubjQuery_Test() throws Exception {
    final Sail sail = GeoRyaSailFactory.getInstance(conf);
    final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
    try {
        addStatements(conn);
        final String query = "PREFIX time: <http://www.w3.org/2006/time#> \n" + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" + "SELECT * " + "WHERE { " + "  <urn:event1> time:atTime ?time . " + "  <urn:event1> geo:asWKT ?point . " + "  FILTER(geof:sfWithin(?point, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " + "  FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) " + "}";
        final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
        final Set<BindingSet> results = new HashSet<>();
        while (rez.hasNext()) {
            final BindingSet bs = rez.next();
            results.add(bs);
        }
        final MapBindingSet expected = new MapBindingSet();
        expected.addBinding("point", VF.createLiteral("POINT (0 0)"));
        expected.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z"));
        assertEquals(1, results.size());
        assertEquals(expected, results.iterator().next());
    } finally {
        conn.close();
        sail.shutDown();
    }
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) MapBindingSet(org.openrdf.query.impl.MapBindingSet) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) TupleQueryResult(org.openrdf.query.TupleQueryResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 43 with SailRepositoryConnection

use of org.openrdf.repository.sail.SailRepositoryConnection in project incubator-rya by apache.

the class RyaMongoGeoDirectExample method main.

public static void main(String[] args) throws Exception {
    Configuration conf = getConf();
    conf.setBoolean(ConfigUtils.DISPLAY_QUERY_PLAN, PRINT_QUERIES);
    // Note also the use of "GeoRyaSailFactory" below.
    conf.setBoolean(OptionalConfigUtils.USE_GEO, true);
    // Note also the use of "GeoRyaSailFactory" below.
    conf.setStrings(OptionalConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
    SailRepository repository = null;
    SailRepositoryConnection conn = null;
    try {
        log.info("Connecting to Indexing Sail Repository.");
        Sail sail = GeoRyaSailFactory.getInstance(conf);
        repository = new SailRepository(sail);
        conn = repository.getConnection();
        long start = System.currentTimeMillis();
        // uses geospatial features
        testAddPointAndWithinSearch(conn);
        log.info("TIME: " + (System.currentTimeMillis() - start) / 1000.);
    } finally {
        log.info("Shutting down");
        closeQuietly(conn);
        closeQuietly(repository);
        if (mock != null) {
            mock.shutdown();
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) MongoIndexingConfiguration(org.apache.rya.indexing.mongodb.MongoIndexingConfiguration) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection)

Example 44 with SailRepositoryConnection

use of org.openrdf.repository.sail.SailRepositoryConnection in project incubator-rya by apache.

the class MongoEntityIndexIT method partialQuery_Test.

@Test
public void partialQuery_Test() throws Exception {
    final Sail sail = RyaSailFactory.getInstance(conf);
    SailRepositoryConnection conn = new SailRepository(sail).getConnection();
    conn.begin();
    try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
        indexer.setConf(conf);
        indexer.init();
        setupTypes(indexer);
        addStatements(conn);
        conn.commit();
        final String query = "SELECT * WHERE { " + "<urn:george> <" + RDF.TYPE + "> <urn:person> ." + "<urn:george> <urn:name> ?name . " + "<urn:george> <urn:eye> ?eye . " + "}";
        final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
        final Set<BindingSet> results = new HashSet<>();
        while (rez.hasNext()) {
            final BindingSet bs = rez.next();
            System.out.println(bs);
            results.add(bs);
        }
        final ValueFactory vf = ValueFactoryImpl.getInstance();
        final MapBindingSet expected = new MapBindingSet();
        // expected.addBinding("name", vf.createURI("http://www.w3.org/2001/SMLSchema#string", "George"));
        expected.addBinding("name", vf.createLiteral("George"));
        expected.addBinding("eye", vf.createLiteral("blue"));
        assertEquals(1, results.size());
        assertEquals(expected, results.iterator().next());
    } finally {
        conn.close();
    }
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) MongoEntityIndexer(org.apache.rya.indexing.entity.update.mongo.MongoEntityIndexer) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) TupleQueryResult(org.openrdf.query.TupleQueryResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 45 with SailRepositoryConnection

use of org.openrdf.repository.sail.SailRepositoryConnection in project incubator-rya by apache.

the class MongoPcjIntegrationTest method testEvaluateOneIndex.

@Test
public void testEvaluateOneIndex() throws Exception {
    final Sail nonPcjSail = RyaSailFactory.getInstance(conf);
    final MongoDBRdfConfiguration pcjConf = conf.clone();
    pcjConf.setBoolean(ConfigUtils.USE_PCJ, true);
    final Sail pcjSail = RyaSailFactory.getInstance(pcjConf);
    final SailRepositoryConnection conn = new SailRepository(nonPcjSail).getConnection();
    final SailRepositoryConnection pcjConn = new SailRepository(pcjSail).getConnection();
    addPCJS(pcjConn);
    try {
        final URI superclass = new URIImpl("uri:superclass");
        final URI superclass2 = new URIImpl("uri:superclass2");
        conn.add(subclass, RDF.TYPE, superclass);
        conn.add(subclass2, RDF.TYPE, superclass2);
        conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
        conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
        final String indexSparqlString = // 
        "" + // 
        "SELECT ?dog ?pig ?duck  " + // 
        "{" + // 
        "  ?pig a ?dog . " + // 
        "  ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + // 
        "}";
        final CountingResultHandler crh1 = new CountingResultHandler();
        final CountingResultHandler crh2 = new CountingResultHandler();
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 1, conf.getRyaInstanceName(), indexSparqlString);
        conn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString).evaluate(crh1);
        PcjIntegrationTestingUtil.deleteCoreRyaTables(getMongoClient(), conf.getRyaInstanceName(), conf.getTriplesCollectionName());
        pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString).evaluate(crh2);
        assertEquals(crh1.count, crh2.count);
    } finally {
        conn.close();
        pcjConn.close();
        nonPcjSail.shutDown();
        pcjSail.shutDown();
    }
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) URIImpl(org.openrdf.model.impl.URIImpl) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) URI(org.openrdf.model.URI) Test(org.junit.Test)

Aggregations

SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)58 SailRepository (org.openrdf.repository.sail.SailRepository)41 Sail (org.openrdf.sail.Sail)39 Test (org.junit.Test)33 BindingSet (org.openrdf.query.BindingSet)23 HashSet (java.util.HashSet)17 MapBindingSet (org.openrdf.query.impl.MapBindingSet)15 TupleQueryResult (org.openrdf.query.TupleQueryResult)13 Statement (org.openrdf.model.Statement)11 LiteralImpl (org.openrdf.model.impl.LiteralImpl)9 RepositoryException (org.openrdf.repository.RepositoryException)9 ArrayList (java.util.ArrayList)8 Connector (org.apache.accumulo.core.client.Connector)8 Configuration (org.apache.hadoop.conf.Configuration)8 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)8 URIImpl (org.openrdf.model.impl.URIImpl)8 TupleQuery (org.openrdf.query.TupleQuery)8 RyaClientException (org.apache.rya.api.client.RyaClientException)7 RyaStatement (org.apache.rya.api.domain.RyaStatement)7 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)7