Search in sources :

Example 46 with SailRepository

use of org.openrdf.repository.sail.SailRepository 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 47 with SailRepository

use of org.openrdf.repository.sail.SailRepository 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 48 with SailRepository

use of org.openrdf.repository.sail.SailRepository 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 49 with SailRepository

use of org.openrdf.repository.sail.SailRepository 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)

Example 50 with SailRepository

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

the class AccumuloStatementMetadataOptimizerIT method init.

@Before
public void init() throws Exception {
    conf = getConf();
    sail = RyaSailFactory.getInstance(conf);
    repo = new SailRepository(sail);
    conn = repo.getConnection();
    Connector conn = ConfigUtils.getConnector(conf);
    dao = new AccumuloRyaDAO();
    dao.setConnector(conn);
    dao.init();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) SailRepository(org.openrdf.repository.sail.SailRepository) Before(org.junit.Before)

Aggregations

SailRepository (org.openrdf.repository.sail.SailRepository)64 Sail (org.openrdf.sail.Sail)45 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)41 Test (org.junit.Test)27 BindingSet (org.openrdf.query.BindingSet)14 RepositoryException (org.openrdf.repository.RepositoryException)14 TupleQueryResult (org.openrdf.query.TupleQueryResult)13 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)11 TupleQuery (org.openrdf.query.TupleQuery)10 Configuration (org.apache.hadoop.conf.Configuration)9 SailException (org.openrdf.sail.SailException)9 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)7 AccumuloException (org.apache.accumulo.core.client.AccumuloException)7 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)7 RyaClientException (org.apache.rya.api.client.RyaClientException)7 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)7 Repository (org.openrdf.repository.Repository)7 IOException (java.io.IOException)6 RyaURI (org.apache.rya.api.domain.RyaURI)6