use of org.openrdf.repository.sail.SailRepository 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.SailRepository in project incubator-rya by apache.
the class InferenceEngineTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
dao = new AccumuloRyaDAO();
connector = new MockInstance().getConnector("", new PasswordToken(""));
dao.setConnector(connector);
conf = new AccumuloRdfConfiguration();
dao.setConf(conf);
dao.init();
store = new RdfCloudTripleStore();
store.setConf(conf);
store.setRyaDAO(dao);
inferenceEngine = new InferenceEngine();
inferenceEngine.setRyaDAO(dao);
store.setInferenceEngine(inferenceEngine);
inferenceEngine.refreshGraph();
store.initialize();
repository = new SailRepository(store);
conn = repository.getConnection();
}
use of org.openrdf.repository.sail.SailRepository 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.SailRepository in project incubator-rya by apache.
the class PcjIntegrationTestingUtil method getAccumuloNonPcjRepo.
public static SailRepository getAccumuloNonPcjRepo(final String tablePrefix, final String instance) throws AccumuloException, AccumuloSecurityException, RyaDAOException, RepositoryException, InferenceEngineException, NumberFormatException, UnknownHostException, SailException {
final AccumuloRdfConfiguration nonPcjConf = new AccumuloRdfConfiguration();
populateAccumuloConfig(instance, tablePrefix, nonPcjConf);
final Sail nonPcjSail = RyaSailFactory.getInstance(nonPcjConf);
final SailRepository nonPcjRepo = new SailRepository(nonPcjSail);
return nonPcjRepo;
}
use of org.openrdf.repository.sail.SailRepository 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