use of org.apache.jena.query.QuerySolution in project jena by apache.
the class GenericPropertyFunctionTest method testExecEvaluated_unbound.
/**
* Test of execEvaluated method, of class GenericPropertyFunction.
*/
@Test
public void testExecEvaluated_unbound() {
String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "\n" + "SELECT ?subj ?obj\n" + "WHERE{\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);
}
}
// Blank nodes limit a value check.
boolean expResult = true;
boolean result = subjects.size() == 25 && objects.size() == 25;
//
//
assertEquals(expResult, result);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class GenericPropertyFunctionTest method testExecEvaluated_subject_bound_geometry.
/**
* Test of execEvaluated method, of class GenericPropertyFunction.
*/
@Test
public void testExecEvaluated_subject_bound_geometry() {
String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "\n" + "SELECT ?obj\n" + "WHERE{\n" + " BIND(<http://example.org#GeometryA> AS ?subj) \n" + " ?subj geo:sfContains ?obj .\n" + "}ORDER by ?obj";
List<Resource> objects = new ArrayList<>();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
Resource result = qs.getResource("obj");
objects.add(result);
}
}
// Blank nodes limit a value check.
int expResult = 7;
int result = objects.size();
assertEquals(expResult, result);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class GenericPropertyFunctionTest method testExecEvaluated_both_bound_geo.
/**
* Test of execEvaluated method, of class GenericPropertyFunction.
*/
@Test
public void testExecEvaluated_both_bound_geo() {
String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "\n" + "SELECT ?subj ?obj\n" + "WHERE{\n" + " BIND(<http://example.org#GeoFeatureY> AS ?subj) \n" + " BIND(<http://example.org#GeoFeatureZ> 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(GEO_FEATURE_Y);
List<Resource> expObjects = Arrays.asList(GEO_FEATURE_Z);
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 GenericPropertyFunctionTest method testExecEvaluated_subject_bound.
/**
* Test of execEvaluated method, of class GenericPropertyFunction.
*/
@Test
public void testExecEvaluated_subject_bound() {
String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "\n" + "SELECT ?obj\n" + "WHERE{\n" + " BIND(<http://example.org#FeatureA> AS ?subj) \n" + " ?subj geo:sfContains ?obj .\n" + "}ORDER by ?obj";
List<Resource> objects = new ArrayList<>();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
Resource result = qs.getResource("obj");
objects.add(result);
}
}
// Blank nodes limit a value check.
int expResult = 6;
int result = objects.size();
//
assertEquals(expResult, result);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class ResultSetUtils method resultSetToStringList.
/**
* Extracts a List filled with the binding of selectElement variable for each
* query solution, turned into a string (URIs or lexical forms).
* Exhausts the result set. Create a rewindable one to use multiple times.
* @see org.apache.jena.query.ResultSetFactory
*/
public static List<String> resultSetToStringList(ResultSet rs, String selectElement, String literalOrResource) {
// feature suggested by James Howison
List<String> items = new ArrayList<>();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
RDFNode rn = qs.get(selectElement);
if (rn.isLiteral())
items.add(((Literal) rn).getLexicalForm());
else if (rn.isURIResource())
items.add(((Resource) rn).getURI());
else if (rn.isAnon()) {
items.add(((Resource) rn).getId().getLabelString());
} else
throw new ARQException("Unknow thing in results : " + rn);
}
return items;
}
Aggregations