use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection in project incubator-rya by apache.
the class MongoRyaDirectExample method main.
public static void main(final String[] args) throws Exception {
if (IS_DETAILED_LOGGING_ENABLED) {
setupLogging();
}
final Configuration conf = getConf();
conf.setBoolean(ConfigUtils.DISPLAY_QUERY_PLAN, PRINT_QUERIES);
SailRepository repository = null;
SailRepositoryConnection conn = null;
try {
log.info("Connecting to Indexing Sail Repository.");
final Sail sail = RyaSailFactory.getInstance(conf);
repository = new SailRepository(sail);
conn = repository.getConnection();
final long start = System.currentTimeMillis();
if (USE_LUBM_QUERIES) {
log.info("Running LUBM Sample Queries");
testLubmFile(conn);
}
log.info("Running SPARQL Example: Add and Delete");
testAddAndDelete(conn);
testAddAndDeleteNoContext(conn);
testAddNamespaces(conn);
// testAddPointAndWithinSearch(conn);
testAddAndFreeTextSearchWithPCJ(conn);
// to test out inference, set inference to true in the conf
if (USE_INFER) {
testInfer(conn, sail);
testPropertyChainInference(conn, sail);
testPropertyChainInferenceAltRepresentation(conn, sail);
testSomeValuesFromInference(conn, sail);
testAllValuesFromInference(conn, sail);
testIntersectionOfInference(conn, sail);
testOneOfInference(conn, sail);
}
log.info("TIME: " + (System.currentTimeMillis() - start) / 1000.);
} finally {
log.info("Shutting down");
closeQuietly(conn);
closeQuietly(repository);
}
}
use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection 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.eclipse.rdf4j.repository.sail.SailRepositoryConnection 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();
}
}
use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection 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();
}
}
use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection 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();
}
}
}
Aggregations