use of org.apache.jena.query.QuerySolution in project jena by apache.
the class AzimuthDegreesFFTest method testExec_query.
/**
* Test of exec method, of class AzimuthDegreesFF.
*/
@Test
public void testExec_query() {
Dataset dataset = SpatialIndexTestData.createTestDataset();
String query = "PREFIX spatialF: <http://jena.apache.org/function/spatial#>\n" + "\n" + "SELECT ?degs\n" + "WHERE{\n" + " BIND( spatialF:azimuthDeg(0, 0, 0, 10) AS ?degs) \n" + "}ORDER by ?degs";
List<Literal> results = new ArrayList<>();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
Literal result = qs.getLiteral("degs");
results.add(result);
}
}
List<Literal> expResults = Arrays.asList(ResourceFactory.createTypedLiteral("90.0e0", XSDDatatype.XSDdouble));
//
//
assertEquals(expResults, results);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class ConvertLatLonBoxFFTest method testExec_query.
/**
* Test of exec method, of class ConvertLatLonBoxFF.
*/
@Test
public void testExec_query() {
Dataset dataset = SpatialIndexTestData.createTestDataset();
String query = "PREFIX spatialF: <http://jena.apache.org/function/spatial#>\n" + "\n" + "SELECT ?result\n" + "WHERE{\n" + " BIND( spatialF:convertLatLonBox(0.0, 1.0, 10.0, 11.0) AS ?result) \n" + "}ORDER by ?result";
List<Literal> results = new ArrayList<>();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
Literal result = qs.getLiteral("result");
results.add(result);
}
}
List<Literal> expResults = Arrays.asList(ResourceFactory.createTypedLiteral("<http://www.opengis.net/def/crs/EPSG/0/4326> POLYGON((0 1, 10 1, 10 11, 0 11, 0 1))", WKTDatatype.INSTANCE));
//
//
assertEquals(expResults, results);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class AngleDegreesFFTest method testExec_query.
/**
* Test of exec method, of class AngleDegreesFF.
*/
@Test
public void testExec_query() {
Dataset dataset = SpatialIndexTestData.createTestDataset();
String query = "PREFIX spatialF: <http://jena.apache.org/function/spatial#>\n" + "\n" + "SELECT ?degs\n" + "WHERE{\n" + " BIND( spatialF:angleDeg(25, 45, 75, 100) AS ?degs) \n" + "}ORDER by ?degs";
List<Literal> results = new ArrayList<>();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
Literal result = qs.getLiteral("degs");
results.add(result);
}
}
List<Literal> expResults = Arrays.asList(ResourceFactory.createTypedLiteral("42.273689e0", XSDDatatype.XSDdouble));
assertEquals(expResults, results);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class TestDatasetWithLuceneStoredLiterals method doTestSearchWithLiterals.
protected Map<String, Literal> doTestSearchWithLiterals(String turtle, String queryString, Set<String> expectedEntityURIs) {
Model model = dataset.getDefaultModel();
Reader reader = new StringReader(turtle);
dataset.begin(ReadWrite.WRITE);
model.read(reader, "", "TURTLE");
dataset.commit();
Map<String, Literal> literals = new HashMap<>();
Query query = QueryFactory.create(queryString);
dataset.begin(ReadWrite.READ);
try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
ResultSet results = qexec.execSelect();
assertEquals(expectedEntityURIs.size() > 0, results.hasNext());
int count;
for (count = 0; results.hasNext(); count++) {
QuerySolution soln = results.nextSolution();
String entityUri = soln.getResource("s").getURI();
assertTrue(expectedEntityURIs.contains(entityUri));
Literal literal = soln.getLiteral("literal");
assertNotNull(literal);
literals.put(entityUri, literal);
}
assertEquals(expectedEntityURIs.size(), count);
} finally {
dataset.end();
}
return literals;
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class TestTextGraphIndexExtra2 method doTestSearchWithGraphs.
protected Map<String, String> doTestSearchWithGraphs(String queryString, Set<String> expectedEntityURIs) {
Map<String, String> graphs = new HashMap<>();
Query query = QueryFactory.create(queryString);
dataset.begin(ReadWrite.READ);
try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
ResultSet results = qexec.execSelect();
assertEquals(expectedEntityURIs.size() > 0, results.hasNext());
int count;
for (count = 0; results.hasNext(); count++) {
QuerySolution soln = results.nextSolution();
String entityUri = soln.getResource("s").getURI();
assertTrue(expectedEntityURIs.contains(entityUri));
String grafURI = soln.getResource("g").getURI();
assertNotNull(grafURI);
graphs.put(entityUri, grafURI);
}
assertEquals(expectedEntityURIs.size(), count);
} finally {
dataset.end();
}
return graphs;
}
Aggregations