use of org.openrdf.repository.sail.SailRepositoryConnection in project incubator-rya by apache.
the class GeowaveDirectExample 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);
conf.setEnum(OptionalConfigUtils.GEO_INDEXER_TYPE, GeoIndexerType.GEO_WAVE);
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);
}
}
use of org.openrdf.repository.sail.SailRepositoryConnection in project incubator-rya by apache.
the class MongoIndexerDeleteIT method deleteTest.
@Test
public void deleteTest() throws Exception {
final Sail sail = GeoRyaSailFactory.getInstance(conf);
final SailRepositoryConnection conn = new SailRepository(sail).getConnection();
try {
populateRya(conn);
final MongoClient client = conf.getMongoClient();
// The extra 1 is from the person type defined in freetext
assertEquals(8, client.getDatabase(conf.getMongoDBName()).getCollection(conf.getTriplesCollectionName()).count());
assertEquals(4, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_geo").count());
assertEquals(1, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_temporal").count());
assertEquals(2, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_freetext").count());
// free text -- remove one from many
String delete = //
"DELETE DATA \n" + "{\n" + " <urn:people> <http://www.w3.org/2000/01/rdf-schema#label> \"Alice Palace Hose\" " + "}";
Update update = conn.prepareUpdate(QueryLanguage.SPARQL, delete);
update.execute();
// temporal -- remove one from one
delete = //
"DELETE DATA \n" + "{\n" + " <foo:time> <Property:atTime> \"0001-02-03T04:05:06Z\" " + "}";
update = conn.prepareUpdate(QueryLanguage.SPARQL, delete);
update.execute();
// geo -- remove many from many
delete = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n" + //
"DELETE \n" + "{\n" + " <urn:geo> geo:asWKT ?point \n" + "}" + "WHERE { \n" + " <urn:geo> geo:asWKT ?point .\n" + " FILTER(geof:sfWithin(?point, \"POLYGON((0 0, 2 0, 2 1, 0 1, 0 0))\"^^geo:wktLiteral))" + "}";
update = conn.prepareUpdate(QueryLanguage.SPARQL, delete);
update.execute();
assertEquals(2, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_geo").count());
assertEquals(0, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_temporal").count());
assertEquals(1, client.getDatabase(conf.getMongoDBName()).getCollection("ryatest_freetext").count());
assertEquals(4, client.getDatabase(conf.getMongoDBName()).getCollection(conf.getTriplesCollectionName()).count());
} finally {
conn.close();
sail.shutDown();
}
}
use of org.openrdf.repository.sail.SailRepositoryConnection in project incubator-rya by apache.
the class PropertyChainTest method testGraphConfiguration.
@Test
public void testGraphConfiguration() throws Exception {
// build a connection
RdfCloudTripleStore store = new RdfCloudTripleStore();
store.setConf(conf);
store.setRyaDAO(ryaDAO);
InferenceEngine inferenceEngine = new InferenceEngine();
inferenceEngine.setRyaDAO(ryaDAO);
store.setInferenceEngine(inferenceEngine);
inferenceEngine.refreshGraph();
store.initialize();
SailRepository repository = new SailRepository(store);
SailRepositoryConnection conn = repository.getConnection();
String query = //
"INSERT DATA\n" + //
"{ GRAPH <http://updated/test> {\n" + " <urn:greatMother> owl:propertyChainAxiom <urn:12342> . " + " <urn:12342> <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:node1atjakcvbx15023 . " + " _:node1atjakcvbx15023 <http://www.w3.org/2002/07/owl#inverseOf> <urn:isChildOf> . " + " <urn:12342> <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:node1atjakcvbx15123 . " + " _:node1atjakcvbx15123 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> . " + " _:node1atjakcvbx15123 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <urn:MotherOf> . }}";
Update update = conn.prepareUpdate(QueryLanguage.SPARQL, query);
update.execute();
inferenceEngine.refreshGraph();
List<URI> chain = inferenceEngine.getPropertyChain(vf.createURI("urn:greatMother"));
Assert.assertEquals(chain.size(), 2);
Assert.assertEquals(chain.get(0), new InverseURI(vf.createURI("urn:isChildOf")));
Assert.assertEquals(chain.get(1), vf.createURI("urn:MotherOf"));
}
use of org.openrdf.repository.sail.SailRepositoryConnection in project incubator-rya by apache.
the class RdfController method loadRdf.
@RequestMapping(value = "/loadrdf", method = RequestMethod.POST)
public void loadRdf(@RequestParam(required = false) final String format, @RequestParam(value = RdfCloudTripleStoreConfiguration.CONF_CV, required = false) final String cv, @RequestParam(required = false) final String graph, @RequestBody final String body, final HttpServletResponse response) throws RepositoryException, IOException, RDFParseException {
RDFFormat format_r = RDFFormat.RDFXML;
if (format != null) {
format_r = RDFFormat.valueOf(format);
if (format_r == null) {
throw new RuntimeException("RDFFormat[" + format + "] not found");
}
}
// add named graph as context (if specified).
final List<Resource> contextList = new ArrayList<Resource>();
if (graph != null) {
contextList.add(VALUE_FACTORY.createURI(graph));
}
SailRepositoryConnection conn = null;
try {
conn = repository.getConnection();
if (conn.getSailConnection() instanceof RdfCloudTripleStoreConnection && cv != null) {
final RdfCloudTripleStoreConnection<?> sailConnection = (RdfCloudTripleStoreConnection<?>) conn.getSailConnection();
sailConnection.getConf().set(RdfCloudTripleStoreConfiguration.CONF_CV, cv);
}
conn.add(new StringReader(body), "", format_r, contextList.toArray(new Resource[contextList.size()]));
conn.commit();
} finally {
if (conn != null) {
conn.close();
}
}
}
use of org.openrdf.repository.sail.SailRepositoryConnection in project incubator-rya by apache.
the class MongoPCJIndexIT method sparqlQuery_Test_complex.
@Test
public void sparqlQuery_Test_complex() throws Exception {
// Setup a Rya Client.
final MongoConnectionDetails connectionDetails = getConnectionDetails();
final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, getMongoClient());
final String pcjQuery = "SELECT ?name WHERE {" + " ?name <urn:likes> <urn:icecream> ." + " ?name <urn:hasEyeColor> <urn:blue> ." + " }";
final String testQuery = "SELECT ?name WHERE {" + " ?name <urn:hasHairColor> <urn:brown> ." + " ?name <urn:likes> <urn:icecream> ." + " ?name <urn:hasEyeColor> <urn:blue> ." + " }";
// Install an instance of Rya and load statements.
conf.setBoolean(ConfigUtils.USE_PCJ, true);
conf.setBoolean(ConfigUtils.USE_OPTIMAL_PCJ, true);
conf.setBoolean(ConfigUtils.DISPLAY_QUERY_PLAN, true);
ryaClient.getInstall().install(conf.getRyaInstanceName(), InstallConfiguration.builder().setEnablePcjIndex(true).build());
ryaClient.getLoadStatements().loadStatements(conf.getRyaInstanceName(), getStatements());
final String pcjId = ryaClient.getCreatePCJ().createPCJ(conf.getRyaInstanceName(), pcjQuery);
ryaClient.getBatchUpdatePCJ().batchUpdate(conf.getRyaInstanceName(), pcjId);
System.out.println("Triples: " + getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection(conf.getTriplesCollectionName()).count());
System.out.println("PCJS: " + getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection("pcjs").count());
// run the query. since the triples collection is gone, if the results match, they came from the PCJ index.
final Sail sail = RyaSailFactory.getInstance(conf);
SailRepositoryConnection conn = new SailRepository(sail).getConnection();
conn.begin();
final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, testQuery);
tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERYPLAN_FLAG, RdfCloudTripleStoreConstants.VALUE_FACTORY.createLiteral(true));
final TupleQueryResult rez = tupleQuery.evaluate();
final Set<BindingSet> results = new HashSet<>();
while (rez.hasNext()) {
final BindingSet bs = rez.next();
results.add(bs);
}
// Verify the correct results were loaded into the PCJ table.
final Set<BindingSet> expectedResults = new HashSet<>();
MapBindingSet bs = new MapBindingSet();
bs = new MapBindingSet();
bs.addBinding("name", VF.createURI("urn:David"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", VF.createURI("urn:Eve"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", VF.createURI("urn:Frank"));
expectedResults.add(bs);
assertEquals(3, results.size());
assertEquals(expectedResults, results);
}
Aggregations