Search in sources :

Example 56 with QuerySolution

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

Example 57 with QuerySolution

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

Example 58 with QuerySolution

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

Example 59 with QuerySolution

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;
}
Also used : Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) QuerySolution(org.apache.jena.query.QuerySolution) Literal(org.apache.jena.rdf.model.Literal) Model(org.apache.jena.rdf.model.Model) StringReader(java.io.StringReader) ResultSet(org.apache.jena.query.ResultSet) Reader(java.io.Reader) StringReader(java.io.StringReader) QueryExecution(org.apache.jena.query.QueryExecution)

Example 60 with QuerySolution

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

Aggregations

QuerySolution (org.apache.jena.query.QuerySolution)125 ResultSet (org.apache.jena.query.ResultSet)103 QueryExecution (org.apache.jena.query.QueryExecution)96 ArrayList (java.util.ArrayList)70 Test (org.junit.Test)69 Dataset (org.apache.jena.query.Dataset)44 Query (org.apache.jena.query.Query)44 Resource (org.apache.jena.rdf.model.Resource)43 Literal (org.apache.jena.rdf.model.Literal)21 RDFNode (org.apache.jena.rdf.model.RDFNode)20 Model (org.apache.jena.rdf.model.Model)12 HashMap (java.util.HashMap)7 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)6 Extractor (infoeval.main.WikiData.Extractor)4 Node (org.apache.jena.graph.Node)4 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 IOException (java.io.IOException)3 Date (java.sql.Date)3 SimpleDateFormat (java.text.SimpleDateFormat)3 LinkedList (java.util.LinkedList)3