Search in sources :

Example 31 with QuerySolution

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);
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Resource(org.apache.jena.rdf.model.Resource) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution)

Example 32 with QuerySolution

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);
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Resource(org.apache.jena.rdf.model.Resource) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution)

Example 33 with QuerySolution

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);
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Resource(org.apache.jena.rdf.model.Resource) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution) Test(org.junit.Test)

Example 34 with QuerySolution

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);
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Resource(org.apache.jena.rdf.model.Resource) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution) Test(org.junit.Test)

Example 35 with QuerySolution

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);
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Dataset(org.apache.jena.query.Dataset) Resource(org.apache.jena.rdf.model.Resource) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution) Test(org.junit.Test)

Aggregations

QuerySolution (org.apache.jena.query.QuerySolution)129 ResultSet (org.apache.jena.query.ResultSet)106 QueryExecution (org.apache.jena.query.QueryExecution)99 Test (org.junit.Test)71 ArrayList (java.util.ArrayList)70 Query (org.apache.jena.query.Query)47 Dataset (org.apache.jena.query.Dataset)44 Resource (org.apache.jena.rdf.model.Resource)43 Literal (org.apache.jena.rdf.model.Literal)22 RDFNode (org.apache.jena.rdf.model.RDFNode)21 Model (org.apache.jena.rdf.model.Model)15 HashMap (java.util.HashMap)7 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)6 Extractor (infoeval.main.WikiData.Extractor)4 IOException (java.io.IOException)4 Node (org.apache.jena.graph.Node)4 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 Date (java.sql.Date)3 SimpleDateFormat (java.text.SimpleDateFormat)3 LinkedList (java.util.LinkedList)3