Search in sources :

Example 56 with Sail

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

the class RyaSinkTaskTest method singleRecord.

@Test
public void singleRecord() {
    // Create the Statements that will be put by the task.
    final ValueFactory vf = SimpleValueFactory.getInstance();
    final Set<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createIRI("urn:Alice"), vf.createIRI("urn:WorksAt"), vf.createIRI("urn:Taco Shop"), vf.createIRI("urn:graph1")), vf.createStatement(vf.createIRI("urn:Bob"), vf.createIRI("urn:TalksTo"), vf.createIRI("urn:Charlie"), vf.createIRI("urn:graph2")), vf.createStatement(vf.createIRI("urn:Eve"), vf.createIRI("urn:ListensTo"), vf.createIRI("urn:Alice"), vf.createIRI("urn:graph1")));
    // Create the task that will be tested.
    final InMemoryRyaSinkTask task = new InMemoryRyaSinkTask();
    // Setup the properties that will be used to configure the task. We don't actually need to set anything
    // here since we're always returning true for ryaInstanceExists(...) and use an in memory RDF store.
    final Map<String, String> props = new HashMap<>();
    try {
        // Start the task.
        task.start(props);
        // Put the statements as a SinkRecord.
        task.put(Collections.singleton(new SinkRecord("topic", 1, null, "key", null, statements, 0)));
        // Flush the statements.
        task.flush(new HashMap<>());
        // Fetch the stored Statements to show they match the original set.
        final Set<Statement> fetched = new HashSet<>();
        final Sail sail = task.makeSail(props);
        try (SailConnection conn = sail.getConnection();
            CloseableIteration<? extends Statement, SailException> it = conn.getStatements(null, null, null, false)) {
            while (it.hasNext()) {
                fetched.add(it.next());
            }
        }
        assertEquals(statements, fetched);
    } finally {
        // Stop the task.
        task.stop();
    }
}
Also used : HashMap(java.util.HashMap) Statement(org.eclipse.rdf4j.model.Statement) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory) SailException(org.eclipse.rdf4j.sail.SailException) SinkRecord(org.apache.kafka.connect.sink.SinkRecord) SailConnection(org.eclipse.rdf4j.sail.SailConnection) Sail(org.eclipse.rdf4j.sail.Sail) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 57 with Sail

use of org.eclipse.rdf4j.sail.Sail 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 : BindingSet(org.eclipse.rdf4j.query.BindingSet) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) Sail(org.eclipse.rdf4j.sail.Sail) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 58 with Sail

use of org.eclipse.rdf4j.sail.Sail 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 : BindingSet(org.eclipse.rdf4j.query.BindingSet) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) Sail(org.eclipse.rdf4j.sail.Sail) ArrayList(java.util.ArrayList) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) Test(org.junit.Test)

Example 59 with Sail

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

the class MongoGeoIndexerFilterIT method near_invalidDistance.

@Test(expected = MalformedQueryException.class)
public void near_invalidDistance() 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, distance))" + "}";
        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 60 with Sail

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

the class RyaMongoGeoDirectExample method main.

public static void main(final String[] args) throws Exception {
    final 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.");
        final Sail sail = GeoRyaSailFactory.getInstance(conf);
        repository = new SailRepository(sail);
        conn = repository.getConnection();
        final 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.eclipse.rdf4j.repository.sail.SailRepository) Sail(org.eclipse.rdf4j.sail.Sail) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection)

Aggregations

Sail (org.eclipse.rdf4j.sail.Sail)68 SailRepository (org.eclipse.rdf4j.repository.sail.SailRepository)49 SailRepositoryConnection (org.eclipse.rdf4j.repository.sail.SailRepositoryConnection)37 Test (org.junit.Test)33 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)15 BindingSet (org.eclipse.rdf4j.query.BindingSet)13 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)13 SailException (org.eclipse.rdf4j.sail.SailException)13 HashSet (java.util.HashSet)11 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)11 SailConnection (org.eclipse.rdf4j.sail.SailConnection)11 RyaClient (org.apache.rya.api.client.RyaClient)9 ArrayList (java.util.ArrayList)8 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)8 Configuration (org.apache.hadoop.conf.Configuration)8 RyaClientException (org.apache.rya.api.client.RyaClientException)8 MongoDBRdfConfiguration (org.apache.rya.mongodb.MongoDBRdfConfiguration)7 RyaSailRepository (org.apache.rya.rdftriplestore.RyaSailRepository)7 MapBindingSet (org.eclipse.rdf4j.query.impl.MapBindingSet)7 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)7