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();
}
}
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();
}
}
}
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();
}
}
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();
}
}
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();
}
Aggregations