use of org.apache.jena.query.QuerySolution in project jena by apache.
the class MainTest method testMain.
/**
* Test of main method, of class Main.
*/
@Test
public void testMain() {
// System.out.println("main");
String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "\n" + "SELECT ?obj\n" + "WHERE{\n" + " <http://example.org/Geometry#PolygonH> geo:sfContains ?obj .\n" + "}ORDER by ?obj";
List<Resource> result = new ArrayList<>();
try (QueryExecution qe = QueryExecution.service(SERVER.getLocalServiceURL()).query(query).build()) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
Resource obj = qs.getResource("obj");
result.add(obj);
}
// ResultSetFormatter.outputAsTSV(rs);
}
List<Resource> expResult = new ArrayList<>();
expResult.add(ResourceFactory.createResource("http://example.org/Feature#A"));
expResult.add(ResourceFactory.createResource("http://example.org/Feature#D"));
expResult.add(ResourceFactory.createResource("http://example.org/Feature#H"));
expResult.add(ResourceFactory.createResource("http://example.org/Feature#K"));
expResult.add(ResourceFactory.createResource("http://example.org/Geometry#LineStringD"));
expResult.add(ResourceFactory.createResource("http://example.org/Geometry#PointA"));
expResult.add(ResourceFactory.createResource("http://example.org/Geometry#PolygonH"));
expResult.add(ResourceFactory.createResource("http://example.org/Geometry#PolygonK"));
// System.out.println("Exp: " + expResult);
// System.out.println("Res: " + result);
assertEquals(expResult, result);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class TDBTest method testMain.
/**
* Test of main method, of class Main.
*/
@Test
public void testMain() {
// System.out.println("main");
String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "\n" + "SELECT ?obj\n" + "WHERE{\n" + " <http://example.org/Geometry#PolygonH> geo:sfContains ?obj .\n" + "}ORDER by ?obj";
List<Resource> result = new ArrayList<>();
try (QueryExecution qe = QueryExecution.service(SERVER.getLocalServiceURL()).query(query).build()) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
Resource obj = qs.getResource("obj");
result.add(obj);
}
// ResultSetFormatter.outputAsTSV(rs);
}
List<Resource> expResult = new ArrayList<>();
expResult.add(ResourceFactory.createResource("http://example.org/Feature#A"));
expResult.add(ResourceFactory.createResource("http://example.org/Feature#D"));
expResult.add(ResourceFactory.createResource("http://example.org/Feature#H"));
expResult.add(ResourceFactory.createResource("http://example.org/Feature#K"));
expResult.add(ResourceFactory.createResource("http://example.org/Geometry#LineStringD"));
expResult.add(ResourceFactory.createResource("http://example.org/Geometry#PointA"));
expResult.add(ResourceFactory.createResource("http://example.org/Geometry#PolygonH"));
expResult.add(ResourceFactory.createResource("http://example.org/Geometry#PolygonK"));
// System.out.println("Exp: " + expResult);
// System.out.println("Res: " + result);
assertEquals(expResult, result);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class GenericPropertyFunctionTest method testExecEvaluated_object_bound.
/**
* Test of execEvaluated method, of class GenericPropertyFunction.
*/
@Test
public void testExecEvaluated_object_bound() {
String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "\n" + "SELECT ?subj\n" + "WHERE{\n" + " BIND(<http://example.org#FeatureB> AS ?obj) \n" + " ?subj geo:sfContains ?obj .\n" + "}ORDER by ?subj";
List<Resource> results = new ArrayList<>();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
Resource result = qs.getResource("subj");
results.add(result);
}
}
List<Resource> expResults = Arrays.asList(FEATURE_A, FEATURE_B, GEOMETRY_A, GEOMETRY_B);
//
//
assertEquals(expResults, results);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class GenericPropertyFunctionTest method testExecEvaluated_both_bound.
/**
* Test of execEvaluated method, of class GenericPropertyFunction.
*/
@Test
public void testExecEvaluated_both_bound() {
String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "\n" + "SELECT ?subj ?obj\n" + "WHERE{\n" + " BIND(<http://example.org#FeatureA> AS ?subj) \n" + " BIND(<http://example.org#FeatureB> AS ?obj) \n" + " ?subj geo:sfContains ?obj .\n" + "}ORDER by ?subj ?obj";
List<Resource> subjects = new ArrayList<>();
List<Resource> objects = new ArrayList<>();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
Resource subject = qs.getResource("subj");
subjects.add(subject);
Resource object = qs.getResource("obj");
objects.add(object);
}
}
boolean expResult = true;
List<Resource> expSubjects = Arrays.asList(FEATURE_A);
List<Resource> expObjects = Arrays.asList(FEATURE_B);
boolean result = subjects.equals(expSubjects) && objects.equals(expObjects);
assertEquals(expResult, result);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class SouthGeomPFTest method testExecEvaluated.
/**
* Test of execEvaluated method, of class SouthGeomPF.
*/
@Test
public void testExecEvaluated() {
Dataset dataset = SpatialIndexTestData.createTestDataset();
String query = "PREFIX spatial: <http://jena.apache.org/spatial#>\n" + "\n" + "SELECT ?subj\n" + "WHERE{\n" + " BIND( \"<http://www.opengis.net/def/crs/EPSG/0/4326> POINT(48.857487 2.373047)\"^^<http://www.opengis.net/ont/geosparql#wktLiteral> AS ?geom)" + " ?subj spatial:southGeom(?geom) .\n" + "}ORDER by ?subj";
List<Resource> result = new ArrayList<>();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
Resource feature = qs.getResource("subj");
result.add(feature);
}
}
List<Resource> expResult = Arrays.asList(SpatialIndexTestData.AUCKLAND_FEATURE, SpatialIndexTestData.HONOLULU_FEATURE, SpatialIndexTestData.NEW_YORK_FEATURE, SpatialIndexTestData.PERTH_FEATURE);
assertEquals(expResult, result);
}
Aggregations