GenericPropertyFunction extends PFuncSimple { protected final Boolean queryRewrite(Graph graph, Node subject, Node predicate, Node object, QueryRewriteIndex queryRewriteIndex) { if (graph.contains(subject, predicate, object)) { return true; } if (!queryRewriteIndex.isIndexActive()) { return false; } SpatialObjectGeometryLiteral subjectSpatialLiteral = SpatialObjectGeometryLiteral.retrieve(graph, subject); if (!subjectSpatialLiteral.isValid()) { return false; } SpatialObjectGeometryLiteral objectSpatialLiteral = SpatialObjectGeometryLiteral.retrieve(graph, object); if (!objectSpatialLiteral.isValid()) { return false; } Property predicateProp = ResourceFactory.createProperty(predicate.getURI()); Boolean isPositive = queryRewriteIndex.test(subjectSpatialLiteral.getGeometryLiteral(), predicateProp, objectSpatialLiteral.getGeometryLiteral(), this); return isPositive; } GenericPropertyFunction(GenericFilterFunction filterFunction); @Override QueryIterator execEvaluated(Binding binding, Node subject, Node predicate, Node object, ExecutionContext execCxt); Boolean testFilterFunction(Node subjectGeometryLiteral, Node objectGeometryLiteral);  }
@Test public void testQueryRewrite_geometry_geometry() { Graph graph = model.getGraph(); Node subject = GEOMETRY_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = GEOMETRY_B.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = true; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }
@Test public void testQueryRewrite_geometry_geometry_blank() { Graph graph = model.getGraph(); Node subject = GEOMETRY_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = GEOMETRY_C_BLANK.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = true; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }
@Test public void testQueryRewrite_geometry_geometry_disabled() { GeoSPARQLConfig.setup(IndexOption.MEMORY, Boolean.FALSE); Graph graph = model.getGraph(); Node subject = GEOMETRY_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = FEATURE_B.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = false; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); GeoSPARQLConfig.setup(IndexOption.MEMORY, Boolean.TRUE); assertEquals(expResult, result); }
@Test public void testQueryRewrite_feature_geometry() { Graph graph = model.getGraph(); Node subject = FEATURE_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = GEOMETRY_B.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = true; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }
@Test public void testQueryRewrite_feature_feature() { Graph graph = model.getGraph(); Node subject = FEATURE_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = FEATURE_B.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = true; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }
@Test public void testQueryRewrite_geometry_feature() { Graph graph = model.getGraph(); Node subject = GEOMETRY_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = FEATURE_B.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = true; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }
@Test public void testQueryRewrite_geometry_feature_disabled() { GeoSPARQLConfig.setup(IndexOption.MEMORY, Boolean.FALSE); Graph graph = model.getGraph(); Node subject = GEOMETRY_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = FEATURE_B.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = false; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); GeoSPARQLConfig.setup(IndexOption.MEMORY, Boolean.TRUE); assertEquals(expResult, result); }
@Test public void testQueryRewrite_geometry_geometry_false() { Graph graph = model.getGraph(); Node subject = GEOMETRY_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = GEOMETRY_D.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = false; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }
@Test public void testQueryRewrite_feature_geometry_false() { Graph graph = model.getGraph(); Node subject = FEATURE_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = GEOMETRY_D.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = false; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }
@Test public void testQueryRewrite_feature_feature_false() { Graph graph = model.getGraph(); Node subject = FEATURE_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = FEATURE_D.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = false; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }
@Test public void testQueryRewrite_geometry_feature_false() { Graph graph = model.getGraph(); Node subject = GEOMETRY_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = FEATURE_D.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = false; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }
@Test public void testQueryRewrite_geometry_geometry_asserted() { Graph graph = model.getGraph(); Node subject = GEOMETRY_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = GEOMETRY_F.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = true; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }
@Test public void testQueryRewrite_geometry_geometry_asserted_disabled() { GeoSPARQLConfig.setup(IndexOption.MEMORY, Boolean.FALSE); Graph graph = model.getGraph(); Node subject = GEOMETRY_A.asNode(); Node predicate = Geo.SF_CONTAINS_NODE; Node object = GEOMETRY_F.asNode(); GenericPropertyFunction instance = new SfContainsPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = true; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); GeoSPARQLConfig.setup(IndexOption.MEMORY, Boolean.TRUE); assertEquals(expResult, result); }
@Test public void testQueryRewrite_feature_feature_disjoint() { Graph graph = model.getGraph(); Node subject = FEATURE_A.asNode(); Node predicate = Geo.SF_DISJOINT_NODE; Node object = FEATURE_D.asNode(); GenericPropertyFunction instance = new SfDisjointPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = true; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }
@Test public void testQueryRewrite_feature_feature_disjoint_false() { Graph graph = model.getGraph(); Node subject = FEATURE_A.asNode(); Node predicate = Geo.SF_DISJOINT_NODE; Node object = FEATURE_B.asNode(); GenericPropertyFunction instance = new SfDisjointPF(); QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.createDefault(); Boolean expResult = false; Boolean result = instance.queryRewrite(graph, subject, predicate, object, queryRewriteIndex); assertEquals(expResult, result); }