use of org.apache.jena.query.QuerySolution in project rdf2neo by Rothamsted.
the class CypherHandlersIT method testRelations.
/**
* Tests {@link CyRelationLoadingHandler} to see if relations are mapped from RDF and loaded into Neo4J.
*/
@Test
public void testRelations() throws Exception {
try (Driver neoDriver = GraphDatabase.driver("bolt://127.0.0.1:7687", AuthTokens.basic("neo4j", "test"));
CyRelationLoadingHandler handler = new CyRelationLoadingHandler();
RdfDataManager rdfMgr = new RdfDataManager(RdfDataManagerTest.TDB_PATH);
Neo4jDataManager neoMgr = new Neo4jDataManager(neoDriver)) {
handler.setRdfDataManager(rdfMgr);
handler.setNeo4jDataManager(neoMgr);
handler.setRelationTypesSparql(RdfDataManagerTest.SPARQL_REL_TYPES);
handler.setRelationPropsSparql(RdfDataManagerTest.SPARQL_REL_PROPS);
Set<QuerySolution> relSparqlRows = new HashSet<>();
Dataset dataSet = rdfMgr.getDataSet();
Txn.executeRead(dataSet, () -> SparqlUtils.select(RdfDataManagerTest.SPARQL_REL_TYPES, rdfMgr.getDataSet().getDefaultModel()).forEachRemaining(row -> relSparqlRows.add(row)));
handler.accept(relSparqlRows);
Session session = neoDriver.session(AccessMode.READ);
StatementResult cursor = session.run("MATCH ()-[r]->() RETURN COUNT ( r ) AS ct");
Assert.assertEquals("Wrong count for relations", 3, cursor.next().get("ct").asLong());
cursor = session.run("MATCH p = (:TestNode{ iri:$iri1 })-[:relatedTo]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:1"), "iri2", iri("ex:2")));
Assert.assertEquals("Wrong count for {1 relatedTo 2}!", 1, cursor.next().get("ct").asLong());
cursor = session.run("MATCH p = (:SuperTestNode{ iri:$iri1 })-[:derivedFrom]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:3"), "iri2", iri("ex:1")));
Assert.assertEquals("Wrong count for {3 derivedFrom 1}!", 1, cursor.next().get("ct").asLong());
cursor = session.run("MATCH (:TestNode{ iri:$iri1 })-[r:relatedTo]->(:AdditionalLabel{ iri:$iri2 }) RETURN r.note AS note", parameters("iri1", iri("ex:2"), "iri2", iri("ex:3")));
assertTrue("{2 relatedTo 3} not found!", cursor.hasNext());
Set<String> values = cursor.next().get("note").asList().stream().map(v -> (String) v).collect(Collectors.toSet());
Set<String> refValues = new HashSet<>(Arrays.asList(new String[] { "Reified Relation", "Another Note" }));
assertTrue("reified relation, wrong property value for 'note'!", Sets.difference(values, refValues).isEmpty());
}
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class EastPFTest method testExecEvaluated.
/**
* Test of execEvaluated method, of class EastPF.
*/
@Test
public void testExecEvaluated() {
Dataset dataset = SpatialIndexTestData.createTestDataset();
String query = "PREFIX spatial: <http://jena.apache.org/spatial#>\n" + "\n" + "SELECT ?subj\n" + "WHERE{\n" + " ?subj spatial:east(48.857487 2.373047) .\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.PERTH_FEATURE);
assertEquals(expResult, result);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class NorthPFTest method testExecEvaluated.
/**
* Test of execEvaluated method, of class NorthPF.
*/
@Test
public void testExecEvaluated() {
Dataset dataset = SpatialIndexTestData.createTestDataset();
String query = "PREFIX spatial: <http://jena.apache.org/spatial#>\n" + "\n" + "SELECT ?subj\n" + "WHERE{\n" + " ?subj spatial:north(48.857487 2.373047) .\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.LONDON_FEATURE);
assertEquals(expResult, result);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class NearbyPFTest method testExecEvaluated_fail.
/**
* Test of execEvaluated method, of class NearbyPF.<br>
* Close enough for first filter but rejected by second filter.
*/
@Test
public void testExecEvaluated_fail() {
Dataset dataset = SpatialIndexTestData.createTestDataset();
String query = "PREFIX spatial: <http://jena.apache.org/spatial#>\n" + "\n" + "SELECT ?subj\n" + "WHERE{\n" + " ?subj spatial:nearby(48.857487 2.373047 340) .\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 = new ArrayList<>();
assertEquals(expResult, result);
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class AngleFFTest method testExec_query.
/**
* Test of exec method, of class AngleFF.
*/
@Test
public void testExec_query() {
Dataset dataset = SpatialIndexTestData.createTestDataset();
String query = "PREFIX spatialF: <http://jena.apache.org/function/spatial#>\n" + "\n" + "SELECT ?rads\n" + "WHERE{\n" + " BIND( spatialF:angle(25, 45, 75, 100) AS ?rads) \n" + "}ORDER by ?rads";
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("rads");
results.add(result);
}
}
List<Literal> expResults = Arrays.asList(ResourceFactory.createTypedLiteral("0.7378150601204649e0", XSDDatatype.XSDdouble));
//
//
assertEquals(expResults, results);
}
Aggregations