Search in sources :

Example 1 with MongoEntityIndexer

use of org.apache.rya.indexing.entity.update.mongo.MongoEntityIndexer in project incubator-rya by apache.

the class MongoEntityIndexIT method sparqlQuery_Test.

@Test
public void sparqlQuery_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);
        final String query = "SELECT * WHERE { " + "<urn:strawberry> <" + RDF.TYPE + "> <urn:icecream> ." + "<urn:strawberry> <urn:brand> ?brand . " + "<urn:strawberry> <urn:flavor> ?flavor . " + "}";
        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("flavor", ValueFactoryImpl.getInstance().createLiteral("Strawberry"));
        expected.addBinding("brand", ValueFactoryImpl.getInstance().createLiteral("Awesome Icecream"));
        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) 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 2 with MongoEntityIndexer

use of org.apache.rya.indexing.entity.update.mongo.MongoEntityIndexer in project incubator-rya by apache.

the class MongoEntityIndexIT method ensureInEntityStore_Test.

@Test
public void ensureInEntityStore_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);
        final EntityStorage entities = indexer.getEntityStorage();
        final RyaURI subject = new RyaURI("urn:alice");
        final Optional<Entity> alice = entities.get(subject);
        assertTrue(alice.isPresent());
    } finally {
        conn.close();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) Entity(org.apache.rya.indexing.entity.model.Entity) MongoEntityIndexer(org.apache.rya.indexing.entity.update.mongo.MongoEntityIndexer) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) Test(org.junit.Test)

Example 3 with MongoEntityIndexer

use of org.apache.rya.indexing.entity.update.mongo.MongoEntityIndexer 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)

Aggregations

MongoEntityIndexer (org.apache.rya.indexing.entity.update.mongo.MongoEntityIndexer)3 Test (org.junit.Test)3 SailRepository (org.openrdf.repository.sail.SailRepository)3 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)3 Sail (org.openrdf.sail.Sail)3 HashSet (java.util.HashSet)2 BindingSet (org.openrdf.query.BindingSet)2 TupleQueryResult (org.openrdf.query.TupleQueryResult)2 MapBindingSet (org.openrdf.query.impl.MapBindingSet)2 RyaURI (org.apache.rya.api.domain.RyaURI)1 Entity (org.apache.rya.indexing.entity.model.Entity)1 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)1 ValueFactory (org.openrdf.model.ValueFactory)1