Search in sources :

Example 1 with SailRepositoryConnection

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

the class RyaGeoDirectExample method main.

public static void main(final String[] args) throws Exception {
    final Configuration conf = getConf();
    conf.set(PrecomputedJoinIndexerConfig.PCJ_STORAGE_TYPE, PrecomputedJoinStorageType.ACCUMULO.name());
    conf.setBoolean(ConfigUtils.DISPLAY_QUERY_PLAN, PRINT_QUERIES);
    conf.setBoolean(OptionalConfigUtils.USE_GEO, true);
    log.info("Creating the tables as root.");
    SailRepository repository = null;
    SailRepositoryConnection conn = null;
    try {
        log.info("Connecting to Geo Sail Repository.");
        final Sail extSail = GeoRyaSailFactory.getInstance(conf);
        repository = new SailRepository(extSail);
        conn = repository.getConnection();
        final long start = System.currentTimeMillis();
        log.info("Running SPARQL Example: Add Point and Geo Search with PCJ");
        testAddPointAndWithinSearchWithPCJ(conn);
        log.info("Running SPARQL Example: Temporal, Freetext, and Geo Search");
        testTemporalFreeGeoSearch(conn);
        log.info("Running SPARQL Example: Geo, Freetext, and PCJ Search");
        testGeoFreetextWithPCJSearch(conn);
        log.info("Running SPARQL Example: Delete Geo Data");
        testDeleteGeoData(conn);
        log.info("TIME: " + (System.currentTimeMillis() - start) / 1000.);
    } finally {
        log.info("Shutting down");
        closeQuietly(conn);
        closeQuietly(repository);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) AccumuloIndexingConfiguration(org.apache.rya.indexing.accumulo.AccumuloIndexingConfiguration) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) Sail(org.eclipse.rdf4j.sail.Sail) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection)

Example 2 with SailRepositoryConnection

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

the class MongoGeoIndexerFilterIT method tooManyArgumentsTest.

@Test(expected = QueryEvaluationException.class)
public void tooManyArgumentsTest() throws Exception {
    final Sail sail = GeoRyaSailFactory.getInstance(conf);
    final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
    try {
        populateRya(conn);
        // Only captial
        final String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n" + // 
        "SELECT * \n" + "WHERE { \n" + "  <urn:geo> geo:asWKT ?point .\n" + "  FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 100, 1000, 10))" + "}";
        conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
    } finally {
        conn.close();
        sail.shutDown();
    }
}
Also used : SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) Sail(org.eclipse.rdf4j.sail.Sail) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) Test(org.junit.Test)

Example 3 with SailRepositoryConnection

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

the class MongoGeoIndexerFilterIT method nearHappyUsesTest.

@Test
public void nearHappyUsesTest() throws Exception {
    final Sail sail = GeoRyaSailFactory.getInstance(conf);
    final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
    try {
        populateRya(conn);
        // Only captial
        String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n" + // 
        "SELECT * \n" + "WHERE { \n" + "  <urn:geo> geo:asWKT ?point .\n" + "  FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 0.0, 2000))" + "}";
        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);
        }
        assertEquals(1, results.size());
        assertEquals(CAPITAL_BUILDING, bindingToGeo(results.get(0)));
        // all but capital
        query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n" + // 
        "SELECT * \n" + "WHERE { \n" + "  <urn:geo> geo:asWKT ?point .\n" + "  FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 2000))" + "}";
        rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
        results.clear();
        while (rez.hasNext()) {
            final BindingSet bs = rez.next();
            results.add(bs);
        }
        assertEquals(3, results.size());
        assertEquals(WASHINGTON_MONUMENT, bindingToGeo(results.get(0)));
        assertEquals(WHITE_HOUSE, bindingToGeo(results.get(1)));
        assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(2)));
        // all of them
        query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n" + // 
        "SELECT * \n" + "WHERE { \n" + "  <urn:geo> geo:asWKT ?point .\n" + "  FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 6000, 000))" + "}";
        rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
        results.clear();
        while (rez.hasNext()) {
            final BindingSet bs = rez.next();
            results.add(bs);
        }
        assertEquals(4, results.size());
        assertEquals(WASHINGTON_MONUMENT, bindingToGeo(results.get(0)));
        assertEquals(WHITE_HOUSE, bindingToGeo(results.get(1)));
        assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(2)));
        assertEquals(CAPITAL_BUILDING, bindingToGeo(results.get(3)));
        // donut, only 2
        query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n" + // 
        "SELECT * \n" + "WHERE { \n" + "  <urn:geo> geo:asWKT ?point .\n" + "  FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, 2000, 100))" + "}";
        rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
        results.clear();
        while (rez.hasNext()) {
            final BindingSet bs = rez.next();
            results.add(bs);
        }
        assertEquals(2, results.size());
        assertEquals(WHITE_HOUSE, bindingToGeo(results.get(0)));
        assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(1)));
        // all of them
        query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n" + // 
        "SELECT * \n" + "WHERE { \n" + "  <urn:geo> geo:asWKT ?point .\n" + "  FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral))" + "}";
        rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
        results.clear();
        while (rez.hasNext()) {
            final BindingSet bs = rez.next();
            results.add(bs);
        }
        assertEquals(4, results.size());
        assertEquals(WASHINGTON_MONUMENT, bindingToGeo(results.get(0)));
        assertEquals(WHITE_HOUSE, bindingToGeo(results.get(1)));
        assertEquals(LINCOLN_MEMORIAL, bindingToGeo(results.get(2)));
        assertEquals(CAPITAL_BUILDING, bindingToGeo(results.get(3)));
    } finally {
        conn.close();
        sail.shutDown();
    }
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) Sail(org.eclipse.rdf4j.sail.Sail) ArrayList(java.util.ArrayList) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) Test(org.junit.Test)

Example 4 with SailRepositoryConnection

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

the class MongoGeoIndexerFilterIT method near_negativeDistance.

@Test(expected = IllegalArgumentException.class)
public void near_negativeDistance() throws Exception {
    final Sail sail = GeoRyaSailFactory.getInstance(conf);
    final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
    try {
        populateRya(conn);
        // Only captial
        final String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n" + // 
        "SELECT * \n" + "WHERE { \n" + "  <urn:geo> geo:asWKT ?point .\n" + "  FILTER(geof:sfNear(?point, \"POINT(38.8895 77.0353)\"^^geo:wktLiteral, -100))" + "}";
        final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
        while (rez.hasNext()) {
            rez.next();
        }
    } finally {
        conn.close();
        sail.shutDown();
    }
}
Also used : SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) Sail(org.eclipse.rdf4j.sail.Sail) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) Test(org.junit.Test)

Example 5 with SailRepositoryConnection

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

the class PcjDocumentsWithMockTest method populatePcj.

@Test
public void populatePcj() throws Exception {
    final RdfCloudTripleStore<StatefulMongoDBRdfConfiguration> ryaStore = new RdfCloudTripleStore<>();
    final MongoDBRyaDAO dao = new MongoDBRyaDAO();
    dao.setConf(new StatefulMongoDBRdfConfiguration(conf, getMongoClient()));
    dao.init();
    ryaStore.setRyaDAO(dao);
    ryaStore.initialize();
    final SailRepositoryConnection ryaConn = new RyaSailRepository(ryaStore).getConnection();
    try {
        // Load some Triples into Rya.
        final Set<Statement> triples = new HashSet<>();
        triples.add(VF.createStatement(VF.createIRI("http://Alice"), VF.createIRI("http://hasAge"), VF.createLiteral(BigInteger.valueOf(14))));
        triples.add(VF.createStatement(VF.createIRI("http://Alice"), VF.createIRI("http://playsSport"), VF.createLiteral("Soccer")));
        triples.add(VF.createStatement(VF.createIRI("http://Bob"), VF.createIRI("http://hasAge"), VF.createLiteral(BigInteger.valueOf(16))));
        triples.add(VF.createStatement(VF.createIRI("http://Bob"), VF.createIRI("http://playsSport"), VF.createLiteral("Soccer")));
        triples.add(VF.createStatement(VF.createIRI("http://Charlie"), VF.createIRI("http://hasAge"), VF.createLiteral(BigInteger.valueOf(12))));
        triples.add(VF.createStatement(VF.createIRI("http://Charlie"), VF.createIRI("http://playsSport"), VF.createLiteral("Soccer")));
        triples.add(VF.createStatement(VF.createIRI("http://Eve"), VF.createIRI("http://hasAge"), VF.createLiteral(BigInteger.valueOf(43))));
        triples.add(VF.createStatement(VF.createIRI("http://Eve"), VF.createIRI("http://playsSport"), VF.createLiteral("Soccer")));
        for (final Statement triple : triples) {
            ryaConn.add(triple);
        }
        // Create a PCJ table that will include those triples in its results.
        final String sparql = "SELECT ?name ?age " + "{" + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
        final String pcjTableName = new PcjTableNameFactory().makeTableName(conf.getRyaInstanceName(), "testPcj");
        final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
        pcjs.createAndPopulatePcj(ryaConn, pcjTableName, sparql);
        // Make sure the cardinality was updated.
        final PcjMetadata metadata = pcjs.getPcjMetadata(pcjTableName);
        assertEquals(4, metadata.getCardinality());
    } finally {
        ryaConn.close();
        ryaStore.shutDown();
    }
}
Also used : RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) Statement(org.eclipse.rdf4j.model.Statement) RyaSailRepository(org.apache.rya.rdftriplestore.RyaSailRepository) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SailRepositoryConnection (org.eclipse.rdf4j.repository.sail.SailRepositoryConnection)65 SailRepository (org.eclipse.rdf4j.repository.sail.SailRepository)44 Sail (org.eclipse.rdf4j.sail.Sail)37 Test (org.junit.Test)35 BindingSet (org.eclipse.rdf4j.query.BindingSet)24 HashSet (java.util.HashSet)17 MapBindingSet (org.eclipse.rdf4j.query.impl.MapBindingSet)15 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)13 Statement (org.eclipse.rdf4j.model.Statement)11 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)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 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)8 RyaStatement (org.apache.rya.api.domain.RyaStatement)7 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)7 StatefulMongoDBRdfConfiguration (org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration)7 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)7 RyaIRI (org.apache.rya.api.domain.RyaIRI)6