You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rya.apache.org by mi...@apache.org on 2016/10/12 20:28:41 UTC
[1/6] incubator-rya git commit: RYA-177 adding optional geoindexing
profile
Repository: incubator-rya
Updated Branches:
refs/heads/master 5913670b6 -> 59570b4f7
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java b/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java
new file mode 100644
index 0000000..bd4092a
--- /dev/null
+++ b/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java
@@ -0,0 +1,401 @@
+package mvm.rya.indexing.accumulo.geo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static mvm.rya.api.resolver.RdfToRyaConversions.convertStatement;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.admin.TableOperations;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.impl.ContextStatementImpl;
+import org.openrdf.model.impl.StatementImpl;
+import org.openrdf.model.impl.ValueFactoryImpl;
+
+import com.google.common.collect.Sets;
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.LinearRing;
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.geom.Polygon;
+import com.vividsolutions.jts.geom.PrecisionModel;
+import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;
+
+import info.aduna.iteration.CloseableIteration;
+import mvm.rya.accumulo.AccumuloRdfConfiguration;
+import mvm.rya.indexing.GeoConstants;
+import mvm.rya.indexing.StatementConstraints;
+import mvm.rya.indexing.accumulo.ConfigUtils;
+
+/**
+ * Tests higher level functioning of the geoindexer parse WKT, predicate list,
+ * prime and anti meridian, delete, search, context, search with Statement Constraints.
+ */
+public class GeoIndexerTest {
+
+ private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints();
+
+ private AccumuloRdfConfiguration conf;
+ GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
+
+ @Before
+ public void before() throws Exception {
+ conf = new AccumuloRdfConfiguration();
+ conf.setTablePrefix("triplestore_");
+ String tableName = GeoMesaGeoIndexer.getTableName(conf);
+ conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
+ conf.set(ConfigUtils.CLOUDBASE_USER, "USERNAME");
+ conf.set(ConfigUtils.CLOUDBASE_PASSWORD, "PASS");
+ conf.set(ConfigUtils.CLOUDBASE_AUTHS, "U");
+
+ TableOperations tops = ConfigUtils.getConnector(conf).tableOperations();
+ // get all of the table names with the prefix
+ Set<String> toDel = Sets.newHashSet();
+ for (String t : tops.list()){
+ if (t.startsWith(tableName)){
+ toDel.add(t);
+ }
+ }
+ for (String t : toDel) {
+ tops.delete(t);
+ }
+ }
+
+ @Test
+ public void testRestrictPredicatesSearch() throws Exception {
+ conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2");
+ try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
+ f.setConf(conf);
+
+ ValueFactory vf = new ValueFactoryImpl();
+
+ Point point = gf.createPoint(new Coordinate(10, 10));
+ Value pointValue = vf.createLiteral("Point(10 10)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ URI invalidPredicate = GeoConstants.GEO_AS_WKT;
+
+ // These should not be stored because they are not in the predicate list
+ f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj1"), invalidPredicate, pointValue)));
+ f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), invalidPredicate, pointValue)));
+
+ URI pred1 = vf.createURI("pred:1");
+ URI pred2 = vf.createURI("pred:2");
+
+ // These should be stored because they are in the predicate list
+ Statement s3 = new StatementImpl(vf.createURI("foo:subj3"), pred1, pointValue);
+ Statement s4 = new StatementImpl(vf.createURI("foo:subj4"), pred2, pointValue);
+ f.storeStatement(convertStatement(s3));
+ f.storeStatement(convertStatement(s4));
+
+ // This should not be stored because the object is not valid wkt
+ f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj5"), pred1, vf.createLiteral("soint(10 10)"))));
+
+ // This should not be stored because the object is not a literal
+ f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj6"), pred1, vf.createURI("p:Point(10 10)"))));
+
+ f.flush();
+
+ Set<Statement> actual = getSet(f.queryEquals(point, EMPTY_CONSTRAINTS));
+ Assert.assertEquals(2, actual.size());
+ Assert.assertTrue(actual.contains(s3));
+ Assert.assertTrue(actual.contains(s4));
+ }
+ }
+
+ private static <X> Set<X> getSet(CloseableIteration<X, ?> iter) throws Exception {
+ Set<X> set = new HashSet<X>();
+ while (iter.hasNext()) {
+ set.add(iter.next());
+ }
+ return set;
+ }
+
+ @Test
+ public void testPrimeMeridianSearch() throws Exception {
+ try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
+ f.setConf(conf);
+
+ ValueFactory vf = new ValueFactoryImpl();
+ Resource subject = vf.createURI("foo:subj");
+ URI predicate = GeoConstants.GEO_AS_WKT;
+ Value object = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ Resource context = vf.createURI("foo:context");
+
+ Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ double[] ONE = { 1, 1, -1, 1, -1, -1, 1, -1, 1, 1 };
+ double[] TWO = { 2, 2, -2, 2, -2, -2, 2, -2, 2, 2 };
+ double[] THREE = { 3, 3, -3, 3, -3, -3, 3, -3, 3, 3 };
+
+ LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
+ LinearRing r2 = gf.createLinearRing(new PackedCoordinateSequence.Double(TWO, 2));
+ LinearRing r3 = gf.createLinearRing(new PackedCoordinateSequence.Double(THREE, 2));
+
+ Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+ Polygon p2 = gf.createPolygon(r2, new LinearRing[] {});
+ Polygon p3 = gf.createPolygon(r3, new LinearRing[] {});
+
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS)));
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS)));
+
+ // Test a ring with a hole in it
+ Polygon p3m2 = gf.createPolygon(r3, new LinearRing[] { r2 });
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS)));
+
+ // test a ring outside the point
+ double[] OUT = { 3, 3, 1, 3, 1, 1, 3, 1, 3, 3 };
+ LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
+ Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
+ }
+ }
+
+ @Test
+ public void testDcSearch() throws Exception {
+ // test a ring around dc
+ try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
+ f.setConf(conf);
+
+ ValueFactory vf = new ValueFactoryImpl();
+ Resource subject = vf.createURI("foo:subj");
+ URI predicate = GeoConstants.GEO_AS_WKT;
+ Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ Resource context = vf.createURI("foo:context");
+
+ Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
+ Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+
+ // test a ring outside the point
+ double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
+ LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
+ Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
+ }
+ }
+
+ @Test
+ public void testDeleteSearch() throws Exception {
+ // test a ring around dc
+ try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
+ f.setConf(conf);
+
+ ValueFactory vf = new ValueFactoryImpl();
+ Resource subject = vf.createURI("foo:subj");
+ URI predicate = GeoConstants.GEO_AS_WKT;
+ Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ Resource context = vf.createURI("foo:context");
+
+ Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ f.deleteStatement(convertStatement(statement));
+
+ // test a ring that the point would be inside of if not deleted
+ double[] in = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(in, 2));
+ Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+
+ // test a ring that the point would be outside of if not deleted
+ double[] out = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
+ LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(out, 2));
+ Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
+
+ // test a ring for the whole world and make sure the point is gone
+ // Geomesa is a little sensitive around lon 180, so we only go to 179
+ double[] world = { -180, 90, 179, 90, 179, -90, -180, -90, -180, 90 };
+ LinearRing rWorld = gf.createLinearRing(new PackedCoordinateSequence.Double(world, 2));
+ Polygon pWorld = gf.createPolygon(rWorld, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS)));
+ }
+ }
+
+ @Test
+ public void testDcSearchWithContext() throws Exception {
+ // test a ring around dc
+ try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
+ f.setConf(conf);
+
+ ValueFactory vf = new ValueFactoryImpl();
+ Resource subject = vf.createURI("foo:subj");
+ URI predicate = GeoConstants.GEO_AS_WKT;
+ Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ Resource context = vf.createURI("foo:context");
+
+ Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
+ Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+
+ // query with correct context
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));
+
+ // query with wrong context
+ Assert.assertEquals(Sets.newHashSet(),
+ getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
+ }
+ }
+
+ @Test
+ public void testDcSearchWithSubject() throws Exception {
+ // test a ring around dc
+ try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
+ f.setConf(conf);
+
+ ValueFactory vf = new ValueFactoryImpl();
+ Resource subject = vf.createURI("foo:subj");
+ URI predicate = GeoConstants.GEO_AS_WKT;
+ Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ Resource context = vf.createURI("foo:context");
+
+ Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
+ Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+
+ // query with correct subject
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject))));
+
+ // query with wrong subject
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
+ }
+ }
+
+ @Test
+ public void testDcSearchWithSubjectAndContext() throws Exception {
+ // test a ring around dc
+ try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
+ f.setConf(conf);
+
+ ValueFactory vf = new ValueFactoryImpl();
+ Resource subject = vf.createURI("foo:subj");
+ URI predicate = GeoConstants.GEO_AS_WKT;
+ Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ Resource context = vf.createURI("foo:context");
+
+ Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
+ Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+
+ // query with correct context subject
+ Assert.assertEquals(Sets.newHashSet(statement),
+ getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject))));
+
+ // query with wrong context
+ Assert.assertEquals(Sets.newHashSet(),
+ getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
+
+ // query with wrong subject
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
+ }
+ }
+
+ @Test
+ public void testDcSearchWithPredicate() throws Exception {
+ // test a ring around dc
+ try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
+ f.setConf(conf);
+
+ ValueFactory vf = new ValueFactoryImpl();
+ Resource subject = vf.createURI("foo:subj");
+ URI predicate = GeoConstants.GEO_AS_WKT;
+ Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ Resource context = vf.createURI("foo:context");
+
+ Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
+ Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+
+ // query with correct Predicate
+ Assert.assertEquals(Sets.newHashSet(statement),
+ getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate)))));
+
+ // query with wrong predicate
+ Assert.assertEquals(Sets.newHashSet(),
+ getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createURI("other:pred"))))));
+ }
+ }
+
+ // @Test
+ public void testAntiMeridianSearch() throws Exception {
+ // verify that a search works if the bounding box crosses the anti meridian
+ try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
+ f.setConf(conf);
+
+ ValueFactory vf = new ValueFactoryImpl();
+ Resource context = vf.createURI("foo:context");
+
+ Resource subjectEast = vf.createURI("foo:subj:east");
+ URI predicateEast = GeoConstants.GEO_AS_WKT;
+ Value objectEast = vf.createLiteral("Point(179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ Statement statementEast = new ContextStatementImpl(subjectEast, predicateEast, objectEast, context);
+ f.storeStatement(convertStatement(statementEast));
+
+ Resource subjectWest = vf.createURI("foo:subj:west");
+ URI predicateWest = GeoConstants.GEO_AS_WKT;
+ Value objectWest = vf.createLiteral("Point(-179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ Statement statementWest = new ContextStatementImpl(subjectWest, predicateWest, objectWest, context);
+ f.storeStatement(convertStatement(statementWest));
+
+ f.flush();
+
+ double[] ONE = { 178.1, 1, -178, 1, -178, -1, 178.1, -1, 178.1, 1 };
+
+ LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
+
+ Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+
+ Assert.assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerSfTest.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerSfTest.java b/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerSfTest.java
new file mode 100644
index 0000000..01c6ab7
--- /dev/null
+++ b/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerSfTest.java
@@ -0,0 +1,304 @@
+package mvm.rya.indexing.mongo;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.impl.StatementImpl;
+import org.openrdf.model.impl.ValueFactoryImpl;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.mongodb.MongoClient;
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.LineString;
+import com.vividsolutions.jts.geom.LinearRing;
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.geom.Polygon;
+import com.vividsolutions.jts.geom.PrecisionModel;
+import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;
+
+import de.flapdoodle.embed.mongo.distribution.Version;
+import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
+import info.aduna.iteration.CloseableIteration;
+import mvm.rya.api.domain.RyaStatement;
+import mvm.rya.api.resolver.RdfToRyaConversions;
+import mvm.rya.api.resolver.RyaToRdfConversions;
+import mvm.rya.indexing.GeoConstants;
+import mvm.rya.indexing.OptionalConfigUtils;
+import mvm.rya.indexing.StatementConstraints;
+import mvm.rya.indexing.accumulo.ConfigUtils;
+import mvm.rya.indexing.mongodb.geo.MongoGeoIndexer;
+import mvm.rya.mongodb.MongoDBRdfConfiguration;
+
+/**
+ * Tests all of the "simple functions" of the geoindexer.
+ */
+public class MongoGeoIndexerSfTest {
+ private MongoDBRdfConfiguration conf;
+ private static GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
+ private static MongoGeoIndexer g;
+
+ private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints();
+
+ // Here is the landscape:
+ /**
+ * <pre>
+ * +---+---+---+---+---+---+---+
+ * | F | |
+ * + A + + C +
+ * | | |
+ * +---+---+ E +---+---+
+ * | | / |
+ * + B + /+---+---+
+ * | | / | |
+ * +---+---+/--+---+---+
+ * / | D |
+ * / +---+---+
+ * </pre>
+ **/
+
+ private static final Polygon A = poly(bbox(0, 1, 4, 5));
+ private static final Polygon B = poly(bbox(0, 1, 2, 3));
+ private static final Polygon C = poly(bbox(4, 3, 6, 5));
+ private static final Polygon D = poly(bbox(3, 0, 5, 2));
+
+ private static final Point F = point(2, 4);
+
+ private static final LineString E = line(2, 0, 3, 3);
+
+ private static final Map<Geometry, String> names = Maps.newHashMap();
+ static {
+ names.put(A, "A");
+ names.put(B, "B");
+ names.put(C, "C");
+ names.put(D, "D");
+ names.put(E, "E");
+ names.put(F, "F");
+ }
+
+ @Before
+ public void before() throws Exception {
+ System.out.println(UUID.randomUUID().toString());
+ conf = new MongoDBRdfConfiguration();
+ conf.set(ConfigUtils.USE_MONGO, "true");
+ conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true");
+ conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
+ conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
+ conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
+ conf.set(OptionalConfigUtils.USE_GEO, "true");
+ conf.setTablePrefix("rya_");
+
+ final MongodForTestsFactory testsFactory = MongodForTestsFactory.with(Version.Main.PRODUCTION);
+ final MongoClient mongoClient = testsFactory.newMongo();
+ g = new MongoGeoIndexer();
+ g.initIndexer(conf, mongoClient);
+ g.storeStatement(statement(A));
+ g.storeStatement(statement(B));
+ g.storeStatement(statement(C));
+ g.storeStatement(statement(D));
+ g.storeStatement(statement(F));
+ g.storeStatement(statement(E));
+ }
+
+ private static RyaStatement statement(final Geometry geo) {
+ final ValueFactory vf = new ValueFactoryImpl();
+ final Resource subject = vf.createURI("uri:" + names.get(geo));
+ final URI predicate = GeoConstants.GEO_AS_WKT;
+ final Value object = vf.createLiteral(geo.toString(), GeoConstants.XMLSCHEMA_OGC_WKT);
+ return RdfToRyaConversions.convertStatement(new StatementImpl(subject, predicate, object));
+
+ }
+
+ private static Point point(final double x, final double y) {
+ return gf.createPoint(new Coordinate(x, y));
+ }
+
+ private static LineString line(final double x1, final double y1, final double x2, final double y2) {
+ return new LineString(new PackedCoordinateSequence.Double(new double[] { x1, y1, x2, y2 }, 2), gf);
+ }
+
+ private static Polygon poly(final double[] arr) {
+ final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(arr, 2));
+ final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+ return p1;
+ }
+
+ private static double[] bbox(final double x1, final double y1, final double x2, final double y2) {
+ return new double[] { x1, y1, x1, y2, x2, y2, x2, y1, x1, y1 };
+ }
+
+ public void compare(final CloseableIteration<Statement, ?> actual, final Geometry... expected) throws Exception {
+ final Set<Statement> expectedSet = Sets.newHashSet();
+ for (final Geometry geo : expected) {
+ expectedSet.add(RyaToRdfConversions.convertStatement(statement(geo)));
+ }
+
+ Assert.assertEquals(expectedSet, getSet(actual));
+ }
+
+ private static <X> Set<X> getSet(final CloseableIteration<X, ?> iter) throws Exception {
+ final Set<X> set = new HashSet<X>();
+ while (iter.hasNext()) {
+ set.add(iter.next());
+ }
+ return set;
+ }
+
+ private static Geometry[] EMPTY_RESULTS = {};
+
+ @Test
+ public void testEquals() throws Exception {
+ // point
+ compare(g.queryEquals(F, EMPTY_CONSTRAINTS), F);
+ compare(g.queryEquals(point(2, 2), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+
+ // line
+ compare(g.queryEquals(E, EMPTY_CONSTRAINTS), E);
+ compare(g.queryEquals(line(2, 2, 3, 3), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+
+ // poly
+ compare(g.queryEquals(A, EMPTY_CONSTRAINTS), A);
+ compare(g.queryEquals(poly(bbox(1, 1, 4, 5)), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+
+ }
+
+// @Test
+// public void testDisjoint() throws Exception {
+// // point
+// compare(g.queryDisjoint(F, EMPTY_CONSTRAINTS), B, C, D, E);
+//
+// // line
+// compare(g.queryDisjoint(E, EMPTY_CONSTRAINTS), B, C, D, F);
+//
+// // poly
+// compare(g.queryDisjoint(A, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+// compare(g.queryDisjoint(B, EMPTY_CONSTRAINTS), C, D, F, E);
+// }
+
+ @Test
+ public void testIntersectsPoint() throws Exception {
+ // This seems like a bug
+ // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), A, F);
+ // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ }
+
+ @Test
+ public void testIntersectsLine() throws Exception {
+ // This seems like a bug
+ // compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), A, E);
+ // compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ }
+
+// @Test
+// public void testIntersectsPoly() throws Exception {
+// compare(g.queryIntersects(A, EMPTY_CONSTRAINTS), A, B, C, D, F, E);
+// }
+
+// @Test
+// public void testTouchesPoint() throws Exception {
+// compare(g.queryTouches(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+// }
+//
+// @Test
+// public void testTouchesLine() throws Exception {
+// compare(g.queryTouches(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+// }
+
+// @Test
+// public void testTouchesPoly() throws Exception {
+// compare(g.queryTouches(A, EMPTY_CONSTRAINTS), C);
+// }
+
+// @Test
+// public void testCrossesPoint() throws Exception {
+// compare(g.queryCrosses(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+// }
+
+ @Test
+ public void testCrossesLine() throws Exception {
+ // compare(g.queryCrosses(E, EMPTY_CONSTRAINTS), A);
+ }
+
+// @Test
+// public void testCrossesPoly() throws Exception {
+// compare(g.queryCrosses(A, EMPTY_CONSTRAINTS), E);
+// }
+
+// @Test
+// public void testWithin() throws Exception {
+// // point
+// // compare(g.queryWithin(F, EMPTY_CONSTRAINTS), F);
+//
+// // line
+//// compare(g.queryWithin(E, EMPTY_CONSTRAINTS), E);
+//
+// // poly
+// compare(g.queryWithin(A, EMPTY_CONSTRAINTS), A, B, F);
+// }
+
+// @Test
+// public void testContainsPoint() throws Exception {
+// compare(g.queryContains(F, EMPTY_CONSTRAINTS), A, F);
+// }
+
+ @Test
+ public void testContainsLine() throws Exception {
+ // compare(g.queryContains(E, EMPTY_CONSTRAINTS), E);
+ }
+
+// @Test
+// public void testContainsPoly() throws Exception {
+// compare(g.queryContains(A, EMPTY_CONSTRAINTS), A);
+// compare(g.queryContains(B, EMPTY_CONSTRAINTS), A, B);
+// }
+
+ @Test
+ public void testOverlapsPoint() throws Exception {
+ // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), F);
+ // You cannot have overlapping points
+ // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ }
+
+ @Test
+ public void testOverlapsLine() throws Exception {
+ // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), A, E);
+ // You cannot have overlapping lines
+ // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ }
+
+// @Test
+// public void testOverlapsPoly() throws Exception {
+// compare(g.queryOverlaps(A, EMPTY_CONSTRAINTS), D);
+// }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerTest.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerTest.java b/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerTest.java
new file mode 100644
index 0000000..9b6c8cb
--- /dev/null
+++ b/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerTest.java
@@ -0,0 +1,396 @@
+package mvm.rya.indexing.mongo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+
+import static mvm.rya.api.resolver.RdfToRyaConversions.convertStatement;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.impl.ContextStatementImpl;
+import org.openrdf.model.impl.StatementImpl;
+import org.openrdf.model.impl.ValueFactoryImpl;
+
+import com.google.common.collect.Sets;
+import com.mongodb.MongoClient;
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.LinearRing;
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.geom.Polygon;
+import com.vividsolutions.jts.geom.PrecisionModel;
+import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;
+
+import de.flapdoodle.embed.mongo.distribution.Version;
+import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
+import info.aduna.iteration.CloseableIteration;
+import mvm.rya.indexing.GeoConstants;
+import mvm.rya.indexing.OptionalConfigUtils;
+import mvm.rya.indexing.StatementConstraints;
+import mvm.rya.indexing.accumulo.ConfigUtils;
+import mvm.rya.indexing.mongodb.geo.MongoGeoIndexer;
+import mvm.rya.mongodb.MongoDBRdfConfiguration;
+
+public class MongoGeoIndexerTest {
+
+ private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints();
+
+ MongoDBRdfConfiguration conf;
+ MongoClient mongoClient;
+ GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
+
+ @Before
+ public void before() throws Exception {
+ conf = new MongoDBRdfConfiguration();
+ conf.set(ConfigUtils.USE_MONGO, "true");
+ conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true");
+ conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
+ conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
+ conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
+ conf.set(OptionalConfigUtils.USE_GEO, "true");
+ conf.setTablePrefix("rya_");
+
+ final MongodForTestsFactory testsFactory = MongodForTestsFactory.with(Version.Main.PRODUCTION);
+ mongoClient = testsFactory.newMongo();
+ }
+
+ @Test
+ public void testRestrictPredicatesSearch() throws Exception {
+ conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2");
+ try (MongoGeoIndexer f = new MongoGeoIndexer()) {
+ f.initIndexer(conf, mongoClient);
+
+ final ValueFactory vf = new ValueFactoryImpl();
+
+ final Point point = gf.createPoint(new Coordinate(10, 10));
+ final Value pointValue = vf.createLiteral("Point(10 10)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ final URI invalidPredicate = GeoConstants.GEO_AS_WKT;
+
+ // These should not be stored because they are not in the predicate list
+ f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj1"), invalidPredicate, pointValue)));
+ f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), invalidPredicate, pointValue)));
+
+ final URI pred1 = vf.createURI("pred:1");
+ final URI pred2 = vf.createURI("pred:2");
+
+ // These should be stored because they are in the predicate list
+ final Statement s3 = new StatementImpl(vf.createURI("foo:subj3"), pred1, pointValue);
+ final Statement s4 = new StatementImpl(vf.createURI("foo:subj4"), pred2, pointValue);
+ f.storeStatement(convertStatement(s3));
+ f.storeStatement(convertStatement(s4));
+
+ // This should not be stored because the object is not valid wkt
+ f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj5"), pred1, vf.createLiteral("soint(10 10)"))));
+
+ // This should not be stored because the object is not a literal
+ f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj6"), pred1, vf.createURI("p:Point(10 10)"))));
+
+ f.flush();
+
+ final Set<Statement> actual = getSet(f.queryEquals(point, EMPTY_CONSTRAINTS));
+ Assert.assertEquals(2, actual.size());
+ Assert.assertTrue(actual.contains(s3));
+ Assert.assertTrue(actual.contains(s4));
+ }
+ }
+
+ private static <X> Set<X> getSet(final CloseableIteration<X, ?> iter) throws Exception {
+ final Set<X> set = new HashSet<X>();
+ while (iter.hasNext()) {
+ set.add(iter.next());
+ }
+ return set;
+ }
+
+ @Test
+ public void testPrimeMeridianSearch() throws Exception {
+ try (MongoGeoIndexer f = new MongoGeoIndexer()) {
+ f.initIndexer(conf, mongoClient);
+
+ final ValueFactory vf = new ValueFactoryImpl();
+ final Resource subject = vf.createURI("foo:subj");
+ final URI predicate = GeoConstants.GEO_AS_WKT;
+ final Value object = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ final Resource context = vf.createURI("foo:context");
+
+ final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ final double[] ONE = { 1, 1, -1, 1, -1, -1, 1, -1, 1, 1 };
+ final double[] TWO = { 2, 2, -2, 2, -2, -2, 2, -2, 2, 2 };
+ final double[] THREE = { 3, 3, -3, 3, -3, -3, 3, -3, 3, 3 };
+
+ final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
+ final LinearRing r2 = gf.createLinearRing(new PackedCoordinateSequence.Double(TWO, 2));
+ final LinearRing r3 = gf.createLinearRing(new PackedCoordinateSequence.Double(THREE, 2));
+
+ final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+ final Polygon p2 = gf.createPolygon(r2, new LinearRing[] {});
+ final Polygon p3 = gf.createPolygon(r3, new LinearRing[] {});
+
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS)));
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS)));
+
+ // Test a ring with a hole in it
+ final Polygon p3m2 = gf.createPolygon(r3, new LinearRing[] { r2 });
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS)));
+
+ // test a ring outside the point
+ final double[] OUT = { 3, 3, 1, 3, 1, 1, 3, 1, 3, 3 };
+ final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
+ final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
+ }
+ }
+
+ @Test
+ public void testDcSearch() throws Exception {
+ // test a ring around dc
+ try (MongoGeoIndexer f = new MongoGeoIndexer()) {
+ f.initIndexer(conf, mongoClient);
+
+ final ValueFactory vf = new ValueFactoryImpl();
+ final Resource subject = vf.createURI("foo:subj");
+ final URI predicate = GeoConstants.GEO_AS_WKT;
+ final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ final Resource context = vf.createURI("foo:context");
+
+ final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
+ final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+
+ // test a ring outside the point
+ final double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
+ final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
+ final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
+ }
+ }
+
+ @Test
+ public void testDeleteSearch() throws Exception {
+ // test a ring around dc
+ try (MongoGeoIndexer f = new MongoGeoIndexer()) {
+ f.initIndexer(conf, mongoClient);
+
+ final ValueFactory vf = new ValueFactoryImpl();
+ final Resource subject = vf.createURI("foo:subj");
+ final URI predicate = GeoConstants.GEO_AS_WKT;
+ final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ final Resource context = vf.createURI("foo:context");
+
+ final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ f.deleteStatement(convertStatement(statement));
+
+ // test a ring that the point would be inside of if not deleted
+ final double[] in = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(in, 2));
+ final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+
+ // test a ring that the point would be outside of if not deleted
+ final double[] out = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
+ final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(out, 2));
+ final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
+
+ // test a ring for the whole world and make sure the point is gone
+ // Geomesa is a little sensitive around lon 180, so we only go to 179
+ final double[] world = { -180, 90, 179, 90, 179, -90, -180, -90, -180, 90 };
+ final LinearRing rWorld = gf.createLinearRing(new PackedCoordinateSequence.Double(world, 2));
+ final Polygon pWorld = gf.createPolygon(rWorld, new LinearRing[] {});
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS)));
+ }
+ }
+
+ @Test
+ public void testDcSearchWithContext() throws Exception {
+ // test a ring around dc
+ try (MongoGeoIndexer f = new MongoGeoIndexer()) {
+ f.initIndexer(conf, mongoClient);
+
+ final ValueFactory vf = new ValueFactoryImpl();
+ final Resource subject = vf.createURI("foo:subj");
+ final URI predicate = GeoConstants.GEO_AS_WKT;
+ final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ final Resource context = vf.createURI("foo:context");
+
+ final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
+ final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+
+ // query with correct context
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));
+
+ // query with wrong context
+ Assert.assertEquals(Sets.newHashSet(),
+ getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
+ }
+ }
+
+ @Test
+ public void testDcSearchWithSubject() throws Exception {
+ // test a ring around dc
+ try (MongoGeoIndexer f = new MongoGeoIndexer()) {
+ f.initIndexer(conf, mongoClient);
+
+ final ValueFactory vf = new ValueFactoryImpl();
+ final Resource subject = vf.createURI("foo:subj");
+ final URI predicate = GeoConstants.GEO_AS_WKT;
+ final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ final Resource context = vf.createURI("foo:context");
+
+ final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
+ final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+
+ // query with correct subject
+ Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject))));
+
+ // query with wrong subject
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
+ }
+ }
+
+ @Test
+ public void testDcSearchWithSubjectAndContext() throws Exception {
+ // test a ring around dc
+ try (MongoGeoIndexer f = new MongoGeoIndexer()) {
+ f.initIndexer(conf, mongoClient);
+
+ final ValueFactory vf = new ValueFactoryImpl();
+ final Resource subject = vf.createURI("foo:subj");
+ final URI predicate = GeoConstants.GEO_AS_WKT;
+ final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ final Resource context = vf.createURI("foo:context");
+
+ final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
+ final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+
+ // query with correct context subject
+ Assert.assertEquals(Sets.newHashSet(statement),
+ getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject))));
+
+ // query with wrong context
+ Assert.assertEquals(Sets.newHashSet(),
+ getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
+
+ // query with wrong subject
+ Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
+ }
+ }
+
+ @Test
+ public void testDcSearchWithPredicate() throws Exception {
+ // test a ring around dc
+ try (MongoGeoIndexer f = new MongoGeoIndexer()) {
+ f.initIndexer(conf, mongoClient);
+
+ final ValueFactory vf = new ValueFactoryImpl();
+ final Resource subject = vf.createURI("foo:subj");
+ final URI predicate = GeoConstants.GEO_AS_WKT;
+ final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ final Resource context = vf.createURI("foo:context");
+
+ final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
+ f.storeStatement(convertStatement(statement));
+ f.flush();
+
+ final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
+ final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
+ final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+
+ // query with correct Predicate
+ Assert.assertEquals(Sets.newHashSet(statement),
+ getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate)))));
+
+ // query with wrong predicate
+ Assert.assertEquals(Sets.newHashSet(),
+ getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createURI("other:pred"))))));
+ }
+ }
+
+ // @Test
+ public void testAntiMeridianSearch() throws Exception {
+ // verify that a search works if the bounding box crosses the anti meridian
+ try (MongoGeoIndexer f = new MongoGeoIndexer()) {
+ f.initIndexer(conf, mongoClient);
+
+ final ValueFactory vf = new ValueFactoryImpl();
+ final Resource context = vf.createURI("foo:context");
+
+ final Resource subjectEast = vf.createURI("foo:subj:east");
+ final URI predicateEast = GeoConstants.GEO_AS_WKT;
+ final Value objectEast = vf.createLiteral("Point(179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ final Statement statementEast = new ContextStatementImpl(subjectEast, predicateEast, objectEast, context);
+ f.storeStatement(convertStatement(statementEast));
+
+ final Resource subjectWest = vf.createURI("foo:subj:west");
+ final URI predicateWest = GeoConstants.GEO_AS_WKT;
+ final Value objectWest = vf.createLiteral("Point(-179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
+ final Statement statementWest = new ContextStatementImpl(subjectWest, predicateWest, objectWest, context);
+ f.storeStatement(convertStatement(statementWest));
+
+ f.flush();
+
+ final double[] ONE = { 178.1, 1, -178, 1, -178, -1, 178.1, -1, 178.1, 1 };
+
+ final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
+
+ final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+
+ Assert.assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.prospector/pom.xml
----------------------------------------------------------------------
diff --git a/extras/rya.prospector/pom.xml b/extras/rya.prospector/pom.xml
index bf9321e..2ce45b9 100644
--- a/extras/rya.prospector/pom.xml
+++ b/extras/rya.prospector/pom.xml
@@ -71,6 +71,7 @@ under the License.
<excludes>
<!-- Services Files -->
<exclude>**/resources/META-INF/services/**</exclude>
+ <exclude>**/META-INF/**</exclude>
</excludes>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/mapreduce/src/main/java/mvm/rya/accumulo/mr/AbstractAccumuloMRTool.java
----------------------------------------------------------------------
diff --git a/mapreduce/src/main/java/mvm/rya/accumulo/mr/AbstractAccumuloMRTool.java b/mapreduce/src/main/java/mvm/rya/accumulo/mr/AbstractAccumuloMRTool.java
index 88f9030..3869c96 100644
--- a/mapreduce/src/main/java/mvm/rya/accumulo/mr/AbstractAccumuloMRTool.java
+++ b/mapreduce/src/main/java/mvm/rya/accumulo/mr/AbstractAccumuloMRTool.java
@@ -269,7 +269,6 @@ public abstract class AbstractAccumuloMRTool implements Tool {
RyaOutputFormat.setTablePrefix(job, tablePrefix);
// Determine which indexers to use based on the config
RyaOutputFormat.setFreeTextEnabled(job, ConfigUtils.getUseFreeText(conf));
- RyaOutputFormat.setGeoEnabled(job, ConfigUtils.getUseGeo(conf));
RyaOutputFormat.setTemporalEnabled(job, ConfigUtils.getUseTemporal(conf));
RyaOutputFormat.setEntityEnabled(job, ConfigUtils.getUseEntity(conf));
// Configure the Accumulo connection
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/mapreduce/src/main/java/mvm/rya/accumulo/mr/RyaOutputFormat.java
----------------------------------------------------------------------
diff --git a/mapreduce/src/main/java/mvm/rya/accumulo/mr/RyaOutputFormat.java b/mapreduce/src/main/java/mvm/rya/accumulo/mr/RyaOutputFormat.java
index c9f7ffe..331c721 100644
--- a/mapreduce/src/main/java/mvm/rya/accumulo/mr/RyaOutputFormat.java
+++ b/mapreduce/src/main/java/mvm/rya/accumulo/mr/RyaOutputFormat.java
@@ -59,12 +59,10 @@ import mvm.rya.api.persist.RyaDAOException;
import mvm.rya.api.resolver.RdfToRyaConversions;
import mvm.rya.api.resolver.RyaTripleContext;
import mvm.rya.indexing.FreeTextIndexer;
-import mvm.rya.indexing.GeoIndexer;
import mvm.rya.indexing.TemporalIndexer;
import mvm.rya.indexing.accumulo.ConfigUtils;
import mvm.rya.indexing.accumulo.entity.EntityCentricIndex;
import mvm.rya.indexing.accumulo.freetext.AccumuloFreeTextIndexer;
-import mvm.rya.indexing.accumulo.geo.GeoMesaGeoIndexer;
import mvm.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer;
/**
@@ -83,7 +81,6 @@ public class RyaOutputFormat extends OutputFormat<Writable, RyaStatementWritable
private static final String PREFIX = RyaOutputFormat.class.getSimpleName();
private static final String MAX_MUTATION_BUFFER_SIZE = PREFIX + ".maxmemory";
private static final String ENABLE_FREETEXT = PREFIX + ".freetext.enable";
- private static final String ENABLE_GEO = PREFIX + ".geo.enable";
private static final String ENABLE_TEMPORAL = PREFIX + ".temporal.enable";
private static final String ENABLE_ENTITY = PREFIX + ".entity.enable";
private static final String ENABLE_CORE = PREFIX + ".coretables.enable";
@@ -135,16 +132,7 @@ public class RyaOutputFormat extends OutputFormat<Writable, RyaStatementWritable
job.getConfiguration().setBoolean(ENABLE_FREETEXT, enable);
}
- /**
- * Set whether the geo index is enabled. Defaults to true.
- * @param job Job to apply the setting to.
- * @param enable Whether this job should add its output statements to the geo index.
- */
- public static void setGeoEnabled(Job job, boolean enable) {
- job.getConfiguration().setBoolean(ENABLE_GEO, enable);
- }
-
- /**
+ /**
* Set whether the temporal index is enabled. Defaults to true.
* @param job Job to apply the setting to.
* @param enable Whether this job should add its output statements to the temporal index.
@@ -191,7 +179,6 @@ public class RyaOutputFormat extends OutputFormat<Writable, RyaStatementWritable
public void checkOutputSpecs(JobContext jobContext) throws IOException {
Configuration conf = jobContext.getConfiguration();
// make sure that all of the indexers can connect
- getGeoIndexer(conf);
getFreeTextIndexer(conf);
getTemporalIndexer(conf);
getRyaIndexer(conf);
@@ -219,14 +206,6 @@ public class RyaOutputFormat extends OutputFormat<Writable, RyaStatementWritable
return new RyaRecordWriter(context);
}
- private static GeoIndexer getGeoIndexer(Configuration conf) {
- if (!conf.getBoolean(ENABLE_GEO, true)) {
- return null;
- }
- GeoMesaGeoIndexer geo = new GeoMesaGeoIndexer();
- geo.setConf(conf);
- return geo;
- }
private static FreeTextIndexer getFreeTextIndexer(Configuration conf) {
if (!conf.getBoolean(ENABLE_FREETEXT, true)) {
@@ -295,7 +274,6 @@ public class RyaOutputFormat extends OutputFormat<Writable, RyaStatementWritable
private static final Logger logger = Logger.getLogger(RyaRecordWriter.class);
private FreeTextIndexer freeTextIndexer;
- private GeoIndexer geoIndexer;
private TemporalIndexer temporalIndexer;
private EntityCentricIndex entityIndexer;
private AccumuloRyaDAO ryaIndexer;
@@ -347,7 +325,6 @@ public class RyaOutputFormat extends OutputFormat<Writable, RyaStatementWritable
// set up the indexers
freeTextIndexer = getFreeTextIndexer(conf);
- geoIndexer = getGeoIndexer(conf);
temporalIndexer = getTemporalIndexer(conf);
entityIndexer = getEntityIndexer(conf);
ryaIndexer = getRyaIndexer(conf);
@@ -407,12 +384,6 @@ public class RyaOutputFormat extends OutputFormat<Writable, RyaStatementWritable
logger.error("Error flushing the buffer on RyaOutputFormat Close", e);
}
try {
- if (geoIndexer != null)
- geoIndexer.close();
- } catch (IOException e) {
- logger.error("Error closing the geoIndexer on RyaOutputFormat Close", e);
- }
- try {
if (freeTextIndexer != null)
freeTextIndexer.close();
} catch (IOException e) {
@@ -531,12 +502,6 @@ public class RyaOutputFormat extends OutputFormat<Writable, RyaStatementWritable
logger.info(String.format("(C-%d) (Reading) Duration, Current Rate, Total Rate: %.2f %.2f %.2f ", commitCount, readingDuration,
currentReadRate, totalReadRate));
- // write to geo
- if (geoIndexer != null) {
- geoIndexer.storeStatements(buffer);
- geoIndexer.flush();
- }
-
// write to free text
if (freeTextIndexer != null) {
freeTextIndexer.storeStatements(buffer);
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/mapreduce/src/test/java/mvm/rya/accumulo/mr/RyaOutputFormatTest.java
----------------------------------------------------------------------
diff --git a/mapreduce/src/test/java/mvm/rya/accumulo/mr/RyaOutputFormatTest.java b/mapreduce/src/test/java/mvm/rya/accumulo/mr/RyaOutputFormatTest.java
index cfd65d7..60bcc49 100644
--- a/mapreduce/src/test/java/mvm/rya/accumulo/mr/RyaOutputFormatTest.java
+++ b/mapreduce/src/test/java/mvm/rya/accumulo/mr/RyaOutputFormatTest.java
@@ -25,11 +25,6 @@ import org.openrdf.model.ValueFactory;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.openrdf.model.vocabulary.XMLSchema;
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.Point;
-import com.vividsolutions.jts.geom.PrecisionModel;
-
import info.aduna.iteration.CloseableIteration;
import mvm.rya.accumulo.AccumuloRdfConfiguration;
import mvm.rya.accumulo.AccumuloRyaDAO;
@@ -47,8 +42,6 @@ import mvm.rya.indexing.accumulo.entity.EntityCentricIndex;
import mvm.rya.indexing.accumulo.freetext.AccumuloFreeTextIndexer;
import mvm.rya.indexing.accumulo.freetext.SimpleTokenizer;
import mvm.rya.indexing.accumulo.freetext.Tokenizer;
-import mvm.rya.indexing.accumulo.geo.GeoConstants;
-import mvm.rya.indexing.accumulo.geo.GeoMesaGeoIndexer;
import mvm.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer;
/*
@@ -133,7 +126,6 @@ public class RyaOutputFormatTest {
RyaOutputFormat.setCoreTablesEnabled(job, true);
RyaOutputFormat.setFreeTextEnabled(job, false);
RyaOutputFormat.setTemporalEnabled(job, false);
- RyaOutputFormat.setGeoEnabled(job, false);
RyaOutputFormat.setEntityEnabled(job, false);
write(input);
TestUtils.verify(connector, conf, input);
@@ -159,7 +151,6 @@ public class RyaOutputFormatTest {
RyaOutputFormat.setCoreTablesEnabled(job, true);
RyaOutputFormat.setFreeTextEnabled(job, false);
RyaOutputFormat.setTemporalEnabled(job, false);
- RyaOutputFormat.setGeoEnabled(job, false);
RyaOutputFormat.setEntityEnabled(job, false);
RyaOutputFormat.setDefaultVisibility(job, CV);
write(input);
@@ -186,7 +177,6 @@ public class RyaOutputFormatTest {
RyaOutputFormat.setCoreTablesEnabled(job, true);
RyaOutputFormat.setFreeTextEnabled(job, false);
RyaOutputFormat.setTemporalEnabled(job, false);
- RyaOutputFormat.setGeoEnabled(job, false);
RyaOutputFormat.setEntityEnabled(job, false);
RyaOutputFormat.setDefaultContext(job, GRAPH);
write(input);
@@ -205,7 +195,6 @@ public class RyaOutputFormatTest {
RyaOutputFormat.setCoreTablesEnabled(job, false);
RyaOutputFormat.setFreeTextEnabled(job, true);
RyaOutputFormat.setTemporalEnabled(job, false);
- RyaOutputFormat.setGeoEnabled(job, false);
RyaOutputFormat.setEntityEnabled(job, false);
write(input);
final Set<Statement> empty = new HashSet<>();
@@ -232,7 +221,6 @@ public class RyaOutputFormatTest {
RyaOutputFormat.setCoreTablesEnabled(job, false);
RyaOutputFormat.setFreeTextEnabled(job, false);
RyaOutputFormat.setTemporalEnabled(job, true);
- RyaOutputFormat.setGeoEnabled(job, false);
RyaOutputFormat.setEntityEnabled(job, false);
final ValueFactory vf = new ValueFactoryImpl();
for (int i = 0; i < instants.length; i++) {
@@ -260,30 +248,6 @@ public class RyaOutputFormatTest {
temporal.close();
}
- @Test
- public void testGeoIndexing() throws Exception {
- final GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
- final Point p1 = gf.createPoint(new Coordinate(1, 1));
- final Point p2 = gf.createPoint(new Coordinate(2, 2));
- final GeoMesaGeoIndexer geo = new GeoMesaGeoIndexer();
- geo.setConf(conf);
- final RyaStatement input = RyaStatement.builder()
- .setSubject(new RyaURI(GRAPH + ":s"))
- .setPredicate(new RyaURI(GRAPH + ":p"))
- .setObject(new RyaType(GeoConstants.XMLSCHEMA_OGC_WKT, "Point(2 2)"))
- .build();
- RyaOutputFormat.setCoreTablesEnabled(job, false);
- RyaOutputFormat.setFreeTextEnabled(job, false);
- RyaOutputFormat.setTemporalEnabled(job, false);
- RyaOutputFormat.setGeoEnabled(job, true);
- RyaOutputFormat.setEntityEnabled(job, false);
- write(input);
- final Set<Statement> expected = new HashSet<>();
- Assert.assertEquals(expected, getSet(geo.queryContains(p1, new StatementConstraints())));
- expected.add(RyaToRdfConversions.convertStatement(input));
- Assert.assertEquals(expected, getSet(geo.queryEquals(p2, new StatementConstraints())));
- geo.close();
- }
@Test
public void testEntityIndexing() throws Exception {
@@ -297,7 +261,6 @@ public class RyaOutputFormatTest {
RyaOutputFormat.setCoreTablesEnabled(job, false);
RyaOutputFormat.setFreeTextEnabled(job, false);
RyaOutputFormat.setTemporalEnabled(job, false);
- RyaOutputFormat.setGeoEnabled(job, false);
RyaOutputFormat.setEntityEnabled(job, true);
write(input);
entity.close();
[3/6] incubator-rya git commit: RYA-177 adding optional geoindexing
profile
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
----------------------------------------------------------------------
diff --git a/extras/indexingExample/src/main/java/MongoRyaDirectExample.java b/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
index 8a2bac5..b741e6a 100644
--- a/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
+++ b/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
@@ -44,8 +44,8 @@ import org.openrdf.repository.sail.SailRepositoryConnection;
import org.openrdf.sail.Sail;
import mvm.rya.api.RdfCloudTripleStoreConfiguration;
+import mvm.rya.indexing.GeoConstants;
import mvm.rya.indexing.accumulo.ConfigUtils;
-import mvm.rya.indexing.accumulo.geo.GeoConstants;
import mvm.rya.mongodb.MongoDBRdfConfiguration;
import mvm.rya.rdftriplestore.RdfCloudTripleStore;
import mvm.rya.rdftriplestore.inference.InferenceEngineException;
@@ -83,7 +83,7 @@ public class MongoRyaDirectExample {
testAddAndDelete(conn);
testAddAndDeleteNoContext(conn);
testAddNamespaces(conn);
- testAddPointAndWithinSearch(conn);
+// testAddPointAndWithinSearch(conn);
testAddAndFreeTextSearchWithPCJ(conn);
// to test out inference, set inference to true in the conf
if (USE_INFER){
@@ -100,60 +100,60 @@ public class MongoRyaDirectExample {
}
}
- private static void testAddPointAndWithinSearch(SailRepositoryConnection conn) throws Exception {
-
- String update = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "INSERT DATA { " //
- + " <urn:feature> a geo:Feature ; " //
- + " geo:hasGeometry [ " //
- + " a geo:Point ; " //
- + " geo:asWKT \"Point(-77.03524 38.889468)\"^^geo:wktLiteral "//
- + " ] . " //
- + "}";
-
- Update u = conn.prepareUpdate(QueryLanguage.SPARQL, update);
- u.execute();
-
- String queryString;
- TupleQuery tupleQuery;
- CountingResultHandler tupleHandler;
-
- // ring containing point
- queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?feature ?point ?wkt " //
- + "{" //
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " //
- + "}";//
- tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
-
- tupleHandler = new CountingResultHandler();
- tupleQuery.evaluate(tupleHandler);
- log.info("Result count : " + tupleHandler.getCount());
- Validate.isTrue(tupleHandler.getCount() >= 1); // may see points from during previous runs
-
- // ring outside point
- queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?feature ?point ?wkt " //
- + "{" //
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-77 39, -76 39, -76 38, -77 38, -77 39))\"^^geo:wktLiteral)) " //
- + "}";//
- tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
-
- tupleHandler = new CountingResultHandler();
- tupleQuery.evaluate(tupleHandler);
- log.info("Result count : " + tupleHandler.getCount());
- Validate.isTrue(tupleHandler.getCount() == 0);
- }
+// private static void testAddPointAndWithinSearch(SailRepositoryConnection conn) throws Exception {
+//
+// String update = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "INSERT DATA { " //
+// + " <urn:feature> a geo:Feature ; " //
+// + " geo:hasGeometry [ " //
+// + " a geo:Point ; " //
+// + " geo:asWKT \"Point(-77.03524 38.889468)\"^^geo:wktLiteral "//
+// + " ] . " //
+// + "}";
+//
+// Update u = conn.prepareUpdate(QueryLanguage.SPARQL, update);
+// u.execute();
+//
+// String queryString;
+// TupleQuery tupleQuery;
+// CountingResultHandler tupleHandler;
+//
+// // ring containing point
+// queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
+// + "SELECT ?feature ?point ?wkt " //
+// + "{" //
+// + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " //
+// + "}";//
+// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
+//
+// tupleHandler = new CountingResultHandler();
+// tupleQuery.evaluate(tupleHandler);
+// log.info("Result count : " + tupleHandler.getCount());
+// Validate.isTrue(tupleHandler.getCount() >= 1); // may see points from during previous runs
+//
+// // ring outside point
+// queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
+// + "SELECT ?feature ?point ?wkt " //
+// + "{" //
+// + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-77 39, -76 39, -76 38, -77 38, -77 39))\"^^geo:wktLiteral)) " //
+// + "}";//
+// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
+//
+// tupleHandler = new CountingResultHandler();
+// tupleQuery.evaluate(tupleHandler);
+// log.info("Result count : " + tupleHandler.getCount());
+// Validate.isTrue(tupleHandler.getCount() == 0);
+// }
private static void closeQuietly(SailRepository repository) {
if (repository != null) {
@@ -272,7 +272,7 @@ public class MongoRyaDirectExample {
conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, MONGO_DB);
conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, MONGO_COLL_PREFIX);
conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
- conf.set(ConfigUtils.USE_GEO, "true");
+// conf.set(ConfigUtils.USE_GEO, "true");
conf.set(ConfigUtils.USE_FREETEXT, "true");
conf.setTablePrefix(MONGO_COLL_PREFIX);
conf.set(ConfigUtils.GEO_PREDICATES_LIST, GeoConstants.GEO_AS_WKT.stringValue());
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexingExample/src/main/java/RyaDirectExample.java
----------------------------------------------------------------------
diff --git a/extras/indexingExample/src/main/java/RyaDirectExample.java b/extras/indexingExample/src/main/java/RyaDirectExample.java
index 03d23f9..8c609b4 100644
--- a/extras/indexingExample/src/main/java/RyaDirectExample.java
+++ b/extras/indexingExample/src/main/java/RyaDirectExample.java
@@ -17,10 +17,7 @@
* under the License.
*/
-import java.io.File;
-import java.io.FileInputStream;
import java.net.UnknownHostException;
-import java.util.Collection;
import java.util.List;
import org.apache.accumulo.core.client.AccumuloException;
@@ -36,7 +33,6 @@ import org.apache.log4j.Logger;
import org.apache.rya.indexing.pcj.storage.PcjException;
import org.apache.rya.indexing.pcj.storage.accumulo.PcjTables;
import org.apache.rya.indexing.pcj.storage.accumulo.PcjVarOrderFactory;
-import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.model.ValueFactory;
import org.openrdf.model.impl.LiteralImpl;
@@ -56,10 +52,6 @@ import org.openrdf.query.UpdateExecutionException;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.repository.sail.SailRepositoryConnection;
-import org.openrdf.rio.RDFFormat;
-import org.openrdf.rio.RDFParser;
-import org.openrdf.rio.Rio;
-import org.openrdf.rio.helpers.StatementCollector;
import org.openrdf.sail.Sail;
import org.openrdf.sail.SailException;
@@ -68,8 +60,8 @@ import com.google.common.base.Optional;
import mvm.rya.accumulo.AccumuloRdfConfiguration;
import mvm.rya.api.RdfCloudTripleStoreConfiguration;
import mvm.rya.api.persist.RyaDAOException;
+import mvm.rya.indexing.GeoConstants;
import mvm.rya.indexing.accumulo.ConfigUtils;
-import mvm.rya.indexing.accumulo.geo.GeoConstants;
import mvm.rya.indexing.external.PrecomputedJoinIndexerConfig;
import mvm.rya.indexing.external.PrecomputedJoinIndexerConfig.PrecomputedJoinStorageType;
import mvm.rya.rdftriplestore.inference.InferenceEngineException;
@@ -114,18 +106,18 @@ public class RyaDirectExample {
testAddAndTemporalSearchWithPCJ(conn);
log.info("Running SAIL/SPARQL Example: Add and Free Text Search with PCJ");
testAddAndFreeTextSearchWithPCJ(conn);
- log.info("Running SPARQL Example: Add Point and Geo Search with PCJ");
- testAddPointAndWithinSearchWithPCJ(conn);
- log.info("Running SPARQL Example: Temporal, Freetext, and Geo Search");
- testTemporalFreeGeoSearch(conn);
- log.info("Running SPARQL Example: Geo, Freetext, and PCJ Search");
- testGeoFreetextWithPCJSearch(conn);
+// log.info("Running SPARQL Example: Add Point and Geo Search with PCJ");
+//// testAddPointAndWithinSearchWithPCJ(conn);
+// log.info("Running SPARQL Example: Temporal, Freetext, and Geo Search");
+// testTemporalFreeGeoSearch(conn);
+// log.info("Running SPARQL Example: Geo, Freetext, and PCJ Search");
+// testGeoFreetextWithPCJSearch(conn);
log.info("Running SPARQL Example: Delete Temporal Data");
testDeleteTemporalData(conn);
log.info("Running SPARQL Example: Delete Free Text Data");
testDeleteFreeTextData(conn);
- log.info("Running SPARQL Example: Delete Geo Data");
- testDeleteGeoData(conn);
+// log.info("Running SPARQL Example: Delete Geo Data");
+// testDeleteGeoData(conn);
log.info("TIME: " + (System.currentTimeMillis() - start) / 1000.);
} finally {
@@ -161,7 +153,6 @@ public class RyaDirectExample {
conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, USE_MOCK_INSTANCE);
conf.set(ConfigUtils.USE_PCJ, "true");
- conf.set(ConfigUtils.USE_GEO, "true");
conf.set(ConfigUtils.USE_FREETEXT, "true");
conf.set(ConfigUtils.USE_TEMPORAL, "true");
conf.set(PrecomputedJoinIndexerConfig.PCJ_STORAGE_TYPE, PrecomputedJoinStorageType.ACCUMULO.name());
@@ -428,197 +419,197 @@ public class RyaDirectExample {
Validate.isTrue(tupleHandler.getCount() == 1);
}
- private static void testAddPointAndWithinSearchWithPCJ(
- final SailRepositoryConnection conn) throws Exception {
-
- final String update = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "INSERT DATA { " //
- + " <urn:feature> a geo:Feature ; " //
- + " geo:hasGeometry [ " //
- + " a geo:Point ; " //
- + " geo:asWKT \"Point(-77.03524 38.889468)\"^^geo:wktLiteral "//
- + " ] . " //
- + "}";
-
- final Update u = conn.prepareUpdate(QueryLanguage.SPARQL, update);
- u.execute();
-
- String queryString;
- TupleQuery tupleQuery;
- CountingResultHandler tupleHandler;
-
- // point outside search ring
- queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?feature ?point ?wkt " //
- + "{" //
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-77 39, -76 39, -76 38, -77 38, -77 39))\"^^geo:wktLiteral)) " //
- + "}";//
- tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
- tupleHandler = new CountingResultHandler();
- tupleQuery.evaluate(tupleHandler);
- log.info("Result count : " + tupleHandler.getCount());
- Validate.isTrue(tupleHandler.getCount() == 0);
-
- // point inside search ring
- queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?feature ?point ?wkt ?e ?l ?o" //
- + "{" //
- + " ?feature a ?e . "//
- + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
- + " ?e <uri:talksTo> ?o . "//
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " //
- + "}";//
-
- tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
- tupleHandler = new CountingResultHandler();
- tupleQuery.evaluate(tupleHandler);
- log.info("Result count : " + tupleHandler.getCount());
- Validate.isTrue(tupleHandler.getCount() == 1);
-
- // point inside search ring with Pre-Computed Join
- queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?feature ?point ?wkt ?e ?l ?o" //
- + "{" //
- + " ?feature a ?e . "//
- + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
- + " ?e <uri:talksTo> ?o . "//
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " //
- + "}";//
-
- tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
- tupleHandler = new CountingResultHandler();
- tupleQuery.evaluate(tupleHandler);
- log.info("Result count : " + tupleHandler.getCount());
- Validate.isTrue(tupleHandler.getCount() >= 1); // may see points from
- // during previous runs
-
- // point outside search ring with PCJ
- queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?feature ?point ?wkt ?e ?l ?o " //
- + "{" //
- + " ?feature a ?e . "//
- + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
- + " ?e <uri:talksTo> ?o . "//
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-77 39, -76 39, -76 38, -77 38, -77 39))\"^^geo:wktLiteral)) " //
- + "}";//
- tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
- tupleHandler = new CountingResultHandler();
- tupleQuery.evaluate(tupleHandler);
- log.info("Result count : " + tupleHandler.getCount());
- Validate.isTrue(tupleHandler.getCount() == 0);
-
- // point inside search ring with different Pre-Computed Join
- queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?feature ?point ?wkt ?e ?c ?l ?o " //
- + "{" //
- + " ?e a ?c . "//
- + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
- + " ?e <uri:talksTo> ?o . "//
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " //
- + "}";//
- tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
- tupleHandler = new CountingResultHandler();
- tupleQuery.evaluate(tupleHandler);
- log.info("Result count : " + tupleHandler.getCount());
- Validate.isTrue(tupleHandler.getCount() == 1);
- }
-
- private static void testTemporalFreeGeoSearch(
- final SailRepositoryConnection conn)
- throws MalformedQueryException, RepositoryException,
- UpdateExecutionException, TupleQueryResultHandlerException,
- QueryEvaluationException {
-
- String queryString;
- TupleQuery tupleQuery;
- CountingResultHandler tupleHandler;
-
- // ring containing point
- queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "PREFIX time: <http://www.w3.org/2006/time#> "//
- + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> "//
- + "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?feature ?point ?wkt ?event ?time ?person ?match" //
- + "{" //
- + " ?event a time:Instant . \n"//
- + " ?event time:inXSDDateTime ?time . \n"//
- + " FILTER(tempo:after(?time, '2001-01-01T01:01:03-08:00') ) \n"// after
- // 3
- // seconds
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)). " //
- + " ?person a <http://example.org/ontology/Person> . "//
- + " ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . "//
- + " FILTER(fts:text(?match, \"pal*\")) " //
- + "}";//
-
- tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
-
- tupleHandler = new CountingResultHandler();
- tupleQuery.evaluate(tupleHandler);
- log.info("Result count : " + tupleHandler.getCount());
- Validate.isTrue(tupleHandler.getCount() == 5);
-
- }
-
- private static void testGeoFreetextWithPCJSearch(
- final SailRepositoryConnection conn)
- throws MalformedQueryException, RepositoryException,
- TupleQueryResultHandlerException, QueryEvaluationException {
- // ring outside point
- final String queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?feature ?point ?wkt ?e ?c ?l ?o ?person ?match " //
- + "{" //
- + " ?person a <http://example.org/ontology/Person> . "//
- + " ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . "//
- + " FILTER(fts:text(?match, \"!alice & hose\")) " //
- + " ?e a ?c . "//
- + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
- + " ?e <uri:talksTo> ?o . "//
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " //
- + "}";//
- final TupleQuery tupleQuery = conn.prepareTupleQuery(
- QueryLanguage.SPARQL, queryString);
- final CountingResultHandler tupleHandler = new CountingResultHandler();
- tupleQuery.evaluate(tupleHandler);
- log.info("Result count : " + tupleHandler.getCount());
- Validate.isTrue(tupleHandler.getCount() == 1);
- }
+// private static void testAddPointAndWithinSearchWithPCJ(
+// final SailRepositoryConnection conn) throws Exception {
+//
+// final String update = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "INSERT DATA { " //
+// + " <urn:feature> a geo:Feature ; " //
+// + " geo:hasGeometry [ " //
+// + " a geo:Point ; " //
+// + " geo:asWKT \"Point(-77.03524 38.889468)\"^^geo:wktLiteral "//
+// + " ] . " //
+// + "}";
+//
+// final Update u = conn.prepareUpdate(QueryLanguage.SPARQL, update);
+// u.execute();
+//
+// String queryString;
+// TupleQuery tupleQuery;
+// CountingResultHandler tupleHandler;
+//
+// // point outside search ring
+// queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
+// + "SELECT ?feature ?point ?wkt " //
+// + "{" //
+// + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-77 39, -76 39, -76 38, -77 38, -77 39))\"^^geo:wktLiteral)) " //
+// + "}";//
+// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
+// tupleHandler = new CountingResultHandler();
+// tupleQuery.evaluate(tupleHandler);
+// log.info("Result count : " + tupleHandler.getCount());
+// Validate.isTrue(tupleHandler.getCount() == 0);
+//
+// // point inside search ring
+// queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
+// + "SELECT ?feature ?point ?wkt ?e ?l ?o" //
+// + "{" //
+// + " ?feature a ?e . "//
+// + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
+// + " ?e <uri:talksTo> ?o . "//
+// + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " //
+// + "}";//
+//
+// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
+// tupleHandler = new CountingResultHandler();
+// tupleQuery.evaluate(tupleHandler);
+// log.info("Result count : " + tupleHandler.getCount());
+// Validate.isTrue(tupleHandler.getCount() == 1);
+//
+// // point inside search ring with Pre-Computed Join
+// queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
+// + "SELECT ?feature ?point ?wkt ?e ?l ?o" //
+// + "{" //
+// + " ?feature a ?e . "//
+// + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
+// + " ?e <uri:talksTo> ?o . "//
+// + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " //
+// + "}";//
+//
+// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
+// tupleHandler = new CountingResultHandler();
+// tupleQuery.evaluate(tupleHandler);
+// log.info("Result count : " + tupleHandler.getCount());
+// Validate.isTrue(tupleHandler.getCount() >= 1); // may see points from
+// // during previous runs
+//
+// // point outside search ring with PCJ
+// queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
+// + "SELECT ?feature ?point ?wkt ?e ?l ?o " //
+// + "{" //
+// + " ?feature a ?e . "//
+// + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
+// + " ?e <uri:talksTo> ?o . "//
+// + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-77 39, -76 39, -76 38, -77 38, -77 39))\"^^geo:wktLiteral)) " //
+// + "}";//
+// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
+// tupleHandler = new CountingResultHandler();
+// tupleQuery.evaluate(tupleHandler);
+// log.info("Result count : " + tupleHandler.getCount());
+// Validate.isTrue(tupleHandler.getCount() == 0);
+//
+// // point inside search ring with different Pre-Computed Join
+// queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
+// + "SELECT ?feature ?point ?wkt ?e ?c ?l ?o " //
+// + "{" //
+// + " ?e a ?c . "//
+// + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
+// + " ?e <uri:talksTo> ?o . "//
+// + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " //
+// + "}";//
+// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
+// tupleHandler = new CountingResultHandler();
+// tupleQuery.evaluate(tupleHandler);
+// log.info("Result count : " + tupleHandler.getCount());
+// Validate.isTrue(tupleHandler.getCount() == 1);
+// }
+//
+// private static void testTemporalFreeGeoSearch(
+// final SailRepositoryConnection conn)
+// throws MalformedQueryException, RepositoryException,
+// UpdateExecutionException, TupleQueryResultHandlerException,
+// QueryEvaluationException {
+//
+// String queryString;
+// TupleQuery tupleQuery;
+// CountingResultHandler tupleHandler;
+//
+// // ring containing point
+// queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
+// + "PREFIX time: <http://www.w3.org/2006/time#> "//
+// + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> "//
+// + "PREFIX fts: <http://rdf.useekm.com/fts#> "//
+// + "SELECT ?feature ?point ?wkt ?event ?time ?person ?match" //
+// + "{" //
+// + " ?event a time:Instant . \n"//
+// + " ?event time:inXSDDateTime ?time . \n"//
+// + " FILTER(tempo:after(?time, '2001-01-01T01:01:03-08:00') ) \n"// after
+// // 3
+// // seconds
+// + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)). " //
+// + " ?person a <http://example.org/ontology/Person> . "//
+// + " ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . "//
+// + " FILTER(fts:text(?match, \"pal*\")) " //
+// + "}";//
+//
+// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
+//
+// tupleHandler = new CountingResultHandler();
+// tupleQuery.evaluate(tupleHandler);
+// log.info("Result count : " + tupleHandler.getCount());
+// Validate.isTrue(tupleHandler.getCount() == 5);
+//
+// }
+//
+// private static void testGeoFreetextWithPCJSearch(
+// final SailRepositoryConnection conn)
+// throws MalformedQueryException, RepositoryException,
+// TupleQueryResultHandlerException, QueryEvaluationException {
+// // ring outside point
+// final String queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "PREFIX fts: <http://rdf.useekm.com/fts#> "//
+// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
+// + "SELECT ?feature ?point ?wkt ?e ?c ?l ?o ?person ?match " //
+// + "{" //
+// + " ?person a <http://example.org/ontology/Person> . "//
+// + " ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . "//
+// + " FILTER(fts:text(?match, \"!alice & hose\")) " //
+// + " ?e a ?c . "//
+// + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
+// + " ?e <uri:talksTo> ?o . "//
+// + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " //
+// + "}";//
+// final TupleQuery tupleQuery = conn.prepareTupleQuery(
+// QueryLanguage.SPARQL, queryString);
+// final CountingResultHandler tupleHandler = new CountingResultHandler();
+// tupleQuery.evaluate(tupleHandler);
+// log.info("Result count : " + tupleHandler.getCount());
+// Validate.isTrue(tupleHandler.getCount() == 1);
+// }
private static void testDeleteTemporalData(
final SailRepositoryConnection conn) throws Exception {
@@ -693,46 +684,46 @@ public class RyaDirectExample {
Validate.isTrue(tupleHandler.getCount() == 0);
}
- private static void testDeleteGeoData(final SailRepositoryConnection conn)
- throws Exception {
- // Delete all stored points
- final String sparqlDelete = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "DELETE {\n" //
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + "}\n" + "WHERE { \n" + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + "}";//
-
- final Update deleteUpdate = conn.prepareUpdate(QueryLanguage.SPARQL,
- sparqlDelete);
- deleteUpdate.execute();
-
- String queryString;
- TupleQuery tupleQuery;
- CountingResultHandler tupleHandler;
-
- // Find all stored points
- queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?feature ?point ?wkt " //
- + "{" //
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + "}";//
- tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
- tupleHandler = new CountingResultHandler();
- tupleQuery.evaluate(tupleHandler);
- log.info("Result count : " + tupleHandler.getCount());
- Validate.isTrue(tupleHandler.getCount() == 0);
- }
+// private static void testDeleteGeoData(final SailRepositoryConnection conn)
+// throws Exception {
+// // Delete all stored points
+// final String sparqlDelete = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
+// + "DELETE {\n" //
+// + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + "}\n" + "WHERE { \n" + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + "}";//
+//
+// final Update deleteUpdate = conn.prepareUpdate(QueryLanguage.SPARQL,
+// sparqlDelete);
+// deleteUpdate.execute();
+//
+// String queryString;
+// TupleQuery tupleQuery;
+// CountingResultHandler tupleHandler;
+//
+// // Find all stored points
+// queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
+// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
+// + "SELECT ?feature ?point ?wkt " //
+// + "{" //
+// + " ?feature a geo:Feature . "//
+// + " ?feature geo:hasGeometry ?point . "//
+// + " ?point a geo:Point . "//
+// + " ?point geo:asWKT ?wkt . "//
+// + "}";//
+// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
+// tupleHandler = new CountingResultHandler();
+// tupleQuery.evaluate(tupleHandler);
+// log.info("Result count : " + tupleHandler.getCount());
+// Validate.isTrue(tupleHandler.getCount() == 0);
+// }
private static void createPCJ(final Configuration conf)
throws RepositoryException, AccumuloException,
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/pom.xml
----------------------------------------------------------------------
diff --git a/extras/pom.xml b/extras/pom.xml
index 0ffeb7a..8131627 100644
--- a/extras/pom.xml
+++ b/extras/pom.xml
@@ -44,4 +44,13 @@ under the License.
<module>rya.merger</module>
<module>rya.benchmark</module>
</modules>
+
+ <profiles>
+ <profile>
+ <id>geoindexing</id>
+ <modules>
+ <module>rya.geoindexing</module>
+ </modules>
+ </profile>
+ </profiles>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/pom.xml
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/pom.xml b/extras/rya.geoindexing/pom.xml
new file mode 100644
index 0000000..a1721c8
--- /dev/null
+++ b/extras/rya.geoindexing/pom.xml
@@ -0,0 +1,224 @@
+<?xml version='1.0'?>
+
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ you under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.rya</groupId>
+ <artifactId>rya.extras</artifactId>
+ <version>3.2.10-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>rya.geoindexing</artifactId>
+ <name>Apache Rya Secondary Indexing</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <geotools.version>14.3</geotools.version>
+ </properties>
+ <repositories>
+ <repository>
+ <id>osgeo</id>
+ <name>Open Source Geospatial Foundation Repository</name>
+ <url>http://download.osgeo.org/webdav/geotools/</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.accumulo</groupId>
+ <artifactId>accumulo-minicluster</artifactId>
+ <version>${accumulo.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.rya</groupId>
+ <artifactId>rya.sail</artifactId>
+ <exclusions>
+ <exclusion>
+ <artifactId>hsqldb</artifactId>
+ <groupId>hsqldb</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rya</groupId>
+ <artifactId>rya.indexing</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rya</groupId>
+ <artifactId>accumulo.rya</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rya</groupId>
+ <artifactId>mongodb.rya</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rya</groupId>
+ <artifactId>rya.prospector</artifactId>
+ </dependency>
+
+ <!-- Free Text Indexing -->
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-analyzers</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </dependency>
+
+ <!-- Geo Indexing -->
+ <dependency>
+ <groupId>org.locationtech.geomesa</groupId>
+ <artifactId>geomesa-accumulo-datastore</artifactId>
+ </dependency>
+
+ <!-- PCJ Indexing -->
+ <dependency>
+ <groupId>org.apache.rya</groupId>
+ <artifactId>rya.indexing.pcj</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rya</groupId>
+ <artifactId>rya.pcj.fluo.api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.fluo</groupId>
+ <artifactId>fluo-mini</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rya</groupId>
+ <artifactId>accumulo.rya</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.geotools.xsd</groupId>
+ <artifactId>gt-xsd-gml3</artifactId>
+ <version>${geotools.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.geotools</groupId>
+ <artifactId>gt-api</artifactId>
+ <version>${geotools.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.vividsolutions</groupId>
+ <artifactId>jts</artifactId>
+ <version>1.13</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <!-- RDF data Files -->
+ <exclude>**/*.ttl</exclude>
+
+ <!-- Services Files -->
+ <exclude>**/resources/META-INF/services/**</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <configuration>
+ <shadedArtifactAttached>true</shadedArtifactAttached>
+ <shadedClassifierName>map-reduce</shadedClassifierName>
+ <transformers>
+ <transformer
+ implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
+ </transformers>
+ <filters>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>META-INF/*.SF</exclude>
+ <exclude>META-INF/*.DSA</exclude>
+ <exclude>META-INF/*.RSA</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ </configuration>
+ </execution>
+ <execution>
+ <id>accumulo-server</id>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <shadedArtifactAttached>true</shadedArtifactAttached>
+ <shadedClassifierName>accumulo-server</shadedClassifierName>
+ <artifactSet>
+ <excludes>
+ <exclude>org.locationtech.geomesa:*</exclude>
+ <exclude>scala:*</exclude>
+ <exclude>org.apache.accumulo:*</exclude>
+ <exclude>org.apache.thrift:*</exclude>
+ <exclude>org.apache.hadoop:*</exclude>
+ <exclude>org.apache.zookeeper:*</exclude>
+ </excludes>
+ </artifactSet>
+ <transformers>
+ <transformer
+ implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
+ </transformers>
+ <filters>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>META-INF/*.SF</exclude>
+ <exclude>META-INF/*.DSA</exclude>
+ <exclude>META-INF/*.RSA</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoEnabledFilterFunctionOptimizer.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoEnabledFilterFunctionOptimizer.java b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoEnabledFilterFunctionOptimizer.java
new file mode 100644
index 0000000..45d1f1a
--- /dev/null
+++ b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoEnabledFilterFunctionOptimizer.java
@@ -0,0 +1,353 @@
+package mvm.rya.indexing;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.TableExistsException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.commons.lang.Validate;
+import org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.log4j.Logger;
+import org.geotools.feature.SchemaException;
+import org.openrdf.model.Resource;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.impl.URIImpl;
+import org.openrdf.model.impl.ValueFactoryImpl;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.Dataset;
+import org.openrdf.query.algebra.And;
+import org.openrdf.query.algebra.Filter;
+import org.openrdf.query.algebra.FunctionCall;
+import org.openrdf.query.algebra.Join;
+import org.openrdf.query.algebra.LeftJoin;
+import org.openrdf.query.algebra.QueryModelNode;
+import org.openrdf.query.algebra.StatementPattern;
+import org.openrdf.query.algebra.TupleExpr;
+import org.openrdf.query.algebra.ValueConstant;
+import org.openrdf.query.algebra.ValueExpr;
+import org.openrdf.query.algebra.Var;
+import org.openrdf.query.algebra.evaluation.QueryOptimizer;
+import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
+
+import com.google.common.collect.Lists;
+
+import mvm.rya.accumulo.AccumuloRdfConfiguration;
+import mvm.rya.indexing.IndexingFunctionRegistry.FUNCTION_TYPE;
+import mvm.rya.indexing.accumulo.ConfigUtils;
+import mvm.rya.indexing.accumulo.freetext.AccumuloFreeTextIndexer;
+import mvm.rya.indexing.accumulo.freetext.FreeTextTupleSet;
+import mvm.rya.indexing.accumulo.geo.GeoMesaGeoIndexer;
+import mvm.rya.indexing.accumulo.geo.GeoTupleSet;
+import mvm.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer;
+import mvm.rya.indexing.mongodb.freetext.MongoFreeTextIndexer;
+import mvm.rya.indexing.mongodb.geo.MongoGeoIndexer;
+import mvm.rya.indexing.mongodb.temporal.MongoTemporalIndexer;
+
+public class GeoEnabledFilterFunctionOptimizer implements QueryOptimizer, Configurable {
+ private static final Logger LOG = Logger.getLogger(GeoEnabledFilterFunctionOptimizer.class);
+ private final ValueFactory valueFactory = new ValueFactoryImpl();
+
+ private Configuration conf;
+ private GeoIndexer geoIndexer;
+ private FreeTextIndexer freeTextIndexer;
+ private TemporalIndexer temporalIndexer;
+ private boolean init = false;
+
+ public GeoEnabledFilterFunctionOptimizer() {
+ }
+
+ public GeoEnabledFilterFunctionOptimizer(final AccumuloRdfConfiguration conf) throws AccumuloException, AccumuloSecurityException,
+ TableNotFoundException, IOException, SchemaException, TableExistsException, NumberFormatException, UnknownHostException {
+ this.conf = conf;
+ init();
+ }
+
+ //setConf initializes FilterFunctionOptimizer so reflection can be used
+ //to create optimizer in RdfCloudTripleStoreConnection
+ @Override
+ public void setConf(final Configuration conf) {
+ this.conf = conf;
+ //reset the init.
+ init = false;
+ init();
+ }
+
+ private synchronized void init() {
+ if (!init) {
+ if (ConfigUtils.getUseMongo(conf)) {
+ geoIndexer = new MongoGeoIndexer();
+ geoIndexer.setConf(conf);
+ freeTextIndexer = new MongoFreeTextIndexer();
+ freeTextIndexer.setConf(conf);
+ temporalIndexer = new MongoTemporalIndexer();
+ temporalIndexer.setConf(conf);
+ } else {
+ geoIndexer = new GeoMesaGeoIndexer();
+ geoIndexer.setConf(conf);
+ freeTextIndexer = new AccumuloFreeTextIndexer();
+ freeTextIndexer.setConf(conf);
+ temporalIndexer = new AccumuloTemporalIndexer();
+ temporalIndexer.setConf(conf);
+ }
+ init = true;
+ }
+ }
+
+ @Override
+ public void optimize(final TupleExpr tupleExpr, final Dataset dataset, final BindingSet bindings) {
+ // find variables used in property and resource based searches:
+ final SearchVarVisitor searchVars = new SearchVarVisitor();
+ tupleExpr.visit(searchVars);
+ // rewrites for property searches:
+ processPropertySearches(tupleExpr, searchVars.searchProperties);
+
+ }
+
+
+
+ private void processPropertySearches(final TupleExpr tupleExpr, final Collection<Var> searchProperties) {
+ final MatchStatementVisitor matchStatements = new MatchStatementVisitor(searchProperties);
+ tupleExpr.visit(matchStatements);
+ for (final StatementPattern matchStatement: matchStatements.matchStatements) {
+ final Var subject = matchStatement.getSubjectVar();
+ if (subject.hasValue() && !(subject.getValue() instanceof Resource)) {
+ throw new IllegalArgumentException("Query error: Found " + subject.getValue() + ", expected an URI or BNode");
+ }
+ Validate.isTrue(subject.hasValue() || subject.getName() != null);
+ Validate.isTrue(!matchStatement.getObjectVar().hasValue() && matchStatement.getObjectVar().getName() != null);
+ buildQuery(tupleExpr, matchStatement);
+ }
+ }
+
+ private void buildQuery(final TupleExpr tupleExpr, final StatementPattern matchStatement) {
+ //If our IndexerExpr (to be) is the rhs-child of LeftJoin, we can safely make that a Join:
+ // the IndexerExpr will (currently) not return results that can deliver unbound variables.
+ //This optimization should probably be generalized into a LeftJoin -> Join optimizer under certain conditions. Until that
+ // has been done, this code path at least takes care of queries generated by OpenSahara SparqTool that filter on OPTIONAL
+ // projections. E.g. summary~'full text search' (summary is optional). See #379
+ if (matchStatement.getParentNode() instanceof LeftJoin) {
+ final LeftJoin leftJoin = (LeftJoin)matchStatement.getParentNode();
+ if (leftJoin.getRightArg() == matchStatement && leftJoin.getCondition() == null) {
+ matchStatement.getParentNode().replaceWith(new Join(leftJoin.getLeftArg(), leftJoin.getRightArg()));
+ }
+ }
+ final FilterFunction fVisitor = new FilterFunction(matchStatement.getObjectVar().getName());
+ tupleExpr.visit(fVisitor);
+ final List<IndexingExpr> results = Lists.newArrayList();
+ for(int i = 0; i < fVisitor.func.size(); i++){
+ results.add(new IndexingExpr(fVisitor.func.get(i), matchStatement, fVisitor.args.get(i)));
+ }
+ removeMatchedPattern(tupleExpr, matchStatement, new IndexerExprReplacer(results));
+ }
+
+ //find vars contained in filters
+ private static class SearchVarVisitor extends QueryModelVisitorBase<RuntimeException> {
+ private final Collection<Var> searchProperties = new ArrayList<Var>();
+
+ @Override
+ public void meet(final FunctionCall fn) {
+ final URI fun = new URIImpl(fn.getURI());
+ final Var result = IndexingFunctionRegistry.getResultVarFromFunctionCall(fun, fn.getArgs());
+ if (result != null && !searchProperties.contains(result)) {
+ searchProperties.add(result);
+ }
+ }
+ }
+
+ //find StatementPatterns containing filter variables
+ private static class MatchStatementVisitor extends QueryModelVisitorBase<RuntimeException> {
+ private final Collection<Var> propertyVars;
+ private final Collection<Var> usedVars = new ArrayList<Var>();
+ private final List<StatementPattern> matchStatements = new ArrayList<StatementPattern>();
+
+ public MatchStatementVisitor(final Collection<Var> propertyVars) {
+ this.propertyVars = propertyVars;
+ }
+
+ @Override public void meet(final StatementPattern statement) {
+ final Var object = statement.getObjectVar();
+ if (propertyVars.contains(object)) {
+ if (usedVars.contains(object)) {
+ throw new IllegalArgumentException("Illegal search, variable is used multiple times as object: " + object.getName());
+ } else {
+ usedVars.add(object);
+ matchStatements.add(statement);
+ }
+ }
+ }
+ }
+
+ private abstract class AbstractEnhanceVisitor extends QueryModelVisitorBase<RuntimeException> {
+ final String matchVar;
+ List<URI> func = Lists.newArrayList();
+ List<Value[]> args = Lists.newArrayList();
+
+ public AbstractEnhanceVisitor(final String matchVar) {
+ this.matchVar = matchVar;
+ }
+
+ protected void addFilter(final URI uri, final Value[] values) {
+ func.add(uri);
+ args.add(values);
+ }
+ }
+
+ //create indexing expression for each filter matching var in filter StatementPattern
+ //replace old filter condition with true condition
+ private class FilterFunction extends AbstractEnhanceVisitor {
+ public FilterFunction(final String matchVar) {
+ super(matchVar);
+ }
+
+ @Override
+ public void meet(final FunctionCall call) {
+ final URI fnUri = valueFactory.createURI(call.getURI());
+ final Var resultVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(fnUri, call.getArgs());
+ if (resultVar != null && resultVar.getName().equals(matchVar)) {
+ addFilter(valueFactory.createURI(call.getURI()), extractArguments(matchVar, call));
+ if (call.getParentNode() instanceof Filter || call.getParentNode() instanceof And || call.getParentNode() instanceof LeftJoin) {
+ call.replaceWith(new ValueConstant(valueFactory.createLiteral(true)));
+ } else {
+ throw new IllegalArgumentException("Query error: Found " + call + " as part of an expression that is too complex");
+ }
+ }
+ }
+
+ private Value[] extractArguments(final String matchName, final FunctionCall call) {
+ final Value args[] = new Value[call.getArgs().size() - 1];
+ int argI = 0;
+ for (int i = 0; i != call.getArgs().size(); ++i) {
+ final ValueExpr arg = call.getArgs().get(i);
+ if (argI == i && arg instanceof Var && matchName.equals(((Var)arg).getName())) {
+ continue;
+ }
+ if (arg instanceof ValueConstant) {
+ args[argI] = ((ValueConstant)arg).getValue();
+ } else if (arg instanceof Var && ((Var)arg).hasValue()) {
+ args[argI] = ((Var)arg).getValue();
+ } else {
+ throw new IllegalArgumentException("Query error: Found " + arg + ", expected a Literal, BNode or URI");
+ }
+ ++argI;
+ }
+ return args;
+ }
+
+ @Override
+ public void meet(final Filter filter) {
+ //First visit children, then condition (reverse of default):
+ filter.getArg().visit(this);
+ filter.getCondition().visit(this);
+ }
+ }
+
+ private void removeMatchedPattern(final TupleExpr tupleExpr, final StatementPattern pattern, final TupleExprReplacer replacer) {
+ final List<TupleExpr> indexTuples = replacer.createReplacement(pattern);
+ if (indexTuples.size() > 1) {
+ final VarExchangeVisitor vev = new VarExchangeVisitor(pattern);
+ tupleExpr.visit(vev);
+ Join join = new Join(indexTuples.remove(0), indexTuples.remove(0));
+ for (final TupleExpr geo : indexTuples) {
+ join = new Join(join, geo);
+ }
+ pattern.replaceWith(join);
+ } else if (indexTuples.size() == 1) {
+ pattern.replaceWith(indexTuples.get(0));
+ pattern.setParentNode(null);
+ } else {
+ throw new IllegalStateException("Must have at least one replacement for matched StatementPattern.");
+ }
+ }
+
+ private interface TupleExprReplacer {
+ List<TupleExpr> createReplacement(TupleExpr org);
+ }
+
+ //replace each filter pertinent StatementPattern with corresponding index expr
+ private class IndexerExprReplacer implements TupleExprReplacer {
+ private final List<IndexingExpr> indxExpr;
+ private final FUNCTION_TYPE type;
+
+ public IndexerExprReplacer(final List<IndexingExpr> indxExpr) {
+ this.indxExpr = indxExpr;
+ final URI func = indxExpr.get(0).getFunction();
+ type = IndexingFunctionRegistry.getFunctionType(func);
+ }
+
+ @Override
+ public List<TupleExpr> createReplacement(final TupleExpr org) {
+ final List<TupleExpr> indexTuples = Lists.newArrayList();
+ switch (type) {
+ case GEO:
+ for (final IndexingExpr indx : indxExpr) {
+ indexTuples.add(new GeoTupleSet(indx, geoIndexer));
+ }
+ break;
+ case FREETEXT:
+ for (final IndexingExpr indx : indxExpr) {
+ indexTuples.add(new FreeTextTupleSet(indx, freeTextIndexer));
+ }
+ break;
+ case TEMPORAL:
+ for (final IndexingExpr indx : indxExpr) {
+ indexTuples.add(new TemporalTupleSet(indx, temporalIndexer));
+ }
+ break;
+ default:
+ throw new IllegalArgumentException("Incorrect type!");
+ }
+ return indexTuples;
+ }
+ }
+
+ private static class VarExchangeVisitor extends QueryModelVisitorBase<RuntimeException> {
+ private final StatementPattern exchangeVar;
+ public VarExchangeVisitor(final StatementPattern sp) {
+ exchangeVar = sp;
+ }
+
+ @Override
+ public void meet(final Join node) {
+ final QueryModelNode lNode = node.getLeftArg();
+ if (lNode instanceof StatementPattern) {
+ exchangeVar.replaceWith(lNode);
+ node.setLeftArg(exchangeVar);
+ } else {
+ super.meet(node);
+ }
+ }
+ }
+
+ @Override
+ public Configuration getConf() {
+ return conf;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoIndexer.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoIndexer.java b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoIndexer.java
new file mode 100644
index 0000000..40dfeec
--- /dev/null
+++ b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoIndexer.java
@@ -0,0 +1,185 @@
+package mvm.rya.indexing;
+
+import org.openrdf.model.Statement;
+import org.openrdf.query.QueryEvaluationException;
+
+import com.vividsolutions.jts.geom.Geometry;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+
+import info.aduna.iteration.CloseableIteration;
+import mvm.rya.api.persist.index.RyaSecondaryIndexer;
+
+/**
+ * A repository to store, index, and retrieve {@link Statement}s based on geospatial features.
+ */
+public interface GeoIndexer extends RyaSecondaryIndexer {
+ /**
+ * Returns statements that contain a geometry that is equal to the queried {@link Geometry} and meet the {@link StatementConstraints}.
+ *
+ * <p>
+ * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
+ * <ul>
+ * <li>
+ * "Two geometries are topologically equal if their interiors intersect and no part of the interior or boundary of one geometry intersects the exterior of the other"
+ * <li>"A is equal to B if A is within B and A contains B"
+ * </ul>
+ *
+ * @param query
+ * the queried geometry
+ * @param contraints
+ * the {@link StatementConstraints}
+ * @return
+ */
+ public abstract CloseableIteration<Statement, QueryEvaluationException> queryEquals(Geometry query, StatementConstraints contraints);
+
+ /**
+ * Returns statements that contain a geometry that is disjoint to the queried {@link Geometry} and meet the {@link StatementConstraints}.
+ *
+ * <p>
+ * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
+ * <ul>
+ * <li>"A and B are disjoint if they have no point in common. They form a set of disconnected geometries."
+ * <li>"A and B are disjoint if A does not intersect B"
+ * </ul>
+ *
+ * @param query
+ * the queried geometry
+ * @param contraints
+ * the {@link StatementConstraints}
+ * @return
+ */
+ public abstract CloseableIteration<Statement, QueryEvaluationException> queryDisjoint(Geometry query, StatementConstraints contraints);
+
+ /**
+ * Returns statements that contain a geometry that Intersects the queried {@link Geometry} and meet the {@link StatementConstraints}.
+ *
+ * <p>
+ * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
+ * <ul>
+ * <li>"a intersects b: geometries a and b have at least one point in common."
+ * <li>"not Disjoint"
+ * </ul>
+ *
+ *
+ * @param query
+ * the queried geometry
+ * @param contraints
+ * the {@link StatementConstraints}
+ * @return
+ */
+ public abstract CloseableIteration<Statement, QueryEvaluationException> queryIntersects(Geometry query, StatementConstraints contraints);
+
+ /**
+ * Returns statements that contain a geometry that Touches the queried {@link Geometry} and meet the {@link StatementConstraints}.
+ *
+ * <p>
+ * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
+ * <ul>
+ * <li>"a touches b, they have at least one boundary point in common, but no interior points."
+ * </ul>
+ *
+ *
+ * @param query
+ * the queried geometry
+ * @param contraints
+ * the {@link StatementConstraints}
+ * @return
+ */
+ public abstract CloseableIteration<Statement, QueryEvaluationException> queryTouches(Geometry query, StatementConstraints contraints);
+
+ /**
+ * Returns statements that contain a geometry that crosses the queried {@link Geometry} and meet the {@link StatementConstraints}.
+ *
+ * <p>
+ * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
+ * <ul>
+ * <li>
+ * "a crosses b, they have some but not all interior points in common (and the dimension of the intersection is less than that of at least one of them)."
+ * </ul>
+ *
+ * @param query
+ * the queried geometry
+ * @param contraints
+ * the {@link StatementConstraints}
+ * @return
+ */
+ public abstract CloseableIteration<Statement, QueryEvaluationException> queryCrosses(Geometry query, StatementConstraints contraints);
+
+ /**
+ * Returns statements that contain a geometry that is Within the queried {@link Geometry} and meet the {@link StatementConstraints}.
+ *
+ * <p>
+ * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
+ * <ul>
+ * <li>"a is within b, a lies in the interior of b"
+ * <li>Same as: "Contains(b,a)"
+ * </ul>
+ *
+ *
+ * @param query
+ * the queried geometry
+ * @param contraints
+ * the {@link StatementConstraints}
+ * @return
+ */
+ public abstract CloseableIteration<Statement, QueryEvaluationException> queryWithin(Geometry query, StatementConstraints contraints);
+
+ /**
+ * Returns statements that contain a geometry that Contains the queried {@link Geometry} and meet the {@link StatementConstraints}.
+ *
+ * <p>
+ * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
+ * <ul>
+ * <li>b is within a. Geometry b lies in the interior of a. Another definition:
+ * "a 'contains' b iff no points of b lie in the exterior of a, and at least one point of the interior of b lies in the interior of a"
+ * <li>Same: Within(b,a)
+ * </ul>
+ *
+ *
+ * @param query
+ * the queried geometry
+ * @param contraints
+ * the {@link StatementConstraints}
+ * @return
+ */
+ public abstract CloseableIteration<Statement, QueryEvaluationException> queryContains(Geometry query, StatementConstraints contraints);
+
+ /**
+ * Returns statements that contain a geometry that Overlaps the queried {@link Geometry} and meet the {@link StatementConstraints}.
+ *
+ * <p>
+ * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
+ * <ul>
+ * <li>a crosses b, they have some but not all interior points in common (and the dimension of the intersection is less than that of at
+ * least one of them).
+ * </ul>
+ *
+ *
+ * @param query
+ * the queried geometry
+ * @param contraints
+ * the {@link StatementConstraints}
+ * @return
+ */
+ public abstract CloseableIteration<Statement, QueryEvaluationException> queryOverlaps(Geometry query, StatementConstraints contraints);
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoRyaSailFactory.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoRyaSailFactory.java b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoRyaSailFactory.java
new file mode 100644
index 0000000..368d3c9
--- /dev/null
+++ b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/GeoRyaSailFactory.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package mvm.rya.indexing;
+
+import static java.util.Objects.requireNonNull;
+
+import java.net.UnknownHostException;
+import java.util.Objects;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.hadoop.conf.Configuration;
+import org.openrdf.sail.Sail;
+import org.openrdf.sail.SailException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.mongodb.MongoClient;
+
+import mvm.rya.accumulo.AccumuloRdfConfiguration;
+import mvm.rya.accumulo.AccumuloRyaDAO;
+import mvm.rya.api.RdfCloudTripleStoreConfiguration;
+import mvm.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException;
+import mvm.rya.api.instance.RyaDetailsToConfiguration;
+import mvm.rya.api.layout.TablePrefixLayoutStrategy;
+import mvm.rya.api.persist.RyaDAO;
+import mvm.rya.api.persist.RyaDAOException;
+import mvm.rya.indexing.accumulo.ConfigUtils;
+import mvm.rya.mongodb.MongoConnectorFactory;
+import mvm.rya.mongodb.MongoDBRdfConfiguration;
+import mvm.rya.mongodb.MongoDBRyaDAO;
+import mvm.rya.mongodb.instance.MongoRyaInstanceDetailsRepository;
+import mvm.rya.rdftriplestore.RdfCloudTripleStore;
+import mvm.rya.rdftriplestore.inference.InferenceEngine;
+import mvm.rya.rdftriplestore.inference.InferenceEngineException;
+import mvm.rya.sail.config.RyaSailFactory;
+
+public class GeoRyaSailFactory {
+ private static final Logger LOG = LoggerFactory.getLogger(GeoRyaSailFactory.class);
+
+ /**
+ * Creates an instance of {@link Sail} that is attached to a Rya instance.
+ *
+ * @param conf - Configures how the Sail object will be constructed. (not null)
+ * @return A {@link Sail} object that is backed by a Rya datastore.
+ * @throws SailException The object could not be created.
+ */
+ public static Sail getInstance(final Configuration conf) throws AccumuloException,
+ AccumuloSecurityException, RyaDAOException, InferenceEngineException, SailException {
+ requireNonNull(conf);
+ return getRyaSail(conf);
+ }
+
+ private static Sail getRyaSail(final Configuration config) throws InferenceEngineException, RyaDAOException, AccumuloException, AccumuloSecurityException, SailException {
+ final RdfCloudTripleStore store = new RdfCloudTripleStore();
+ final RyaDAO<?> dao;
+ final RdfCloudTripleStoreConfiguration rdfConfig;
+
+ final String user;
+ final String pswd;
+ // XXX Should(?) be MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX inside the if below. RYA-135
+ final String ryaInstance = config.get(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
+ Objects.requireNonNull(ryaInstance, "RyaInstance or table prefix is missing from configuration."+RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
+
+ if(ConfigUtils.getUseMongo(config)) {
+ final MongoDBRdfConfiguration mongoConfig = new MongoDBRdfConfiguration(config);
+ rdfConfig = mongoConfig;
+ final MongoClient client = MongoConnectorFactory.getMongoClient(config);
+ try {
+ final MongoRyaInstanceDetailsRepository ryaDetailsRepo = new MongoRyaInstanceDetailsRepository(client, mongoConfig.getCollectionName());
+ RyaDetailsToConfiguration.addRyaDetailsToConfiguration(ryaDetailsRepo.getRyaInstanceDetails(), mongoConfig);
+ } catch (final RyaDetailsRepositoryException e) {
+ LOG.info("Instance does not have a rya details collection, skipping.");
+ } dao = getMongoDAO((MongoDBRdfConfiguration)rdfConfig, client);
+ } else {
+ rdfConfig = new AccumuloRdfConfiguration(config);
+ user = rdfConfig.get(ConfigUtils.CLOUDBASE_USER);
+ pswd = rdfConfig.get(ConfigUtils.CLOUDBASE_PASSWORD);
+ Objects.requireNonNull(user, "Accumulo user name is missing from configuration."+ConfigUtils.CLOUDBASE_USER);
+ Objects.requireNonNull(pswd, "Accumulo user password is missing from configuration."+ConfigUtils.CLOUDBASE_PASSWORD);
+ rdfConfig.setTableLayoutStrategy( new TablePrefixLayoutStrategy(ryaInstance) );
+ RyaSailFactory.updateAccumuloConfig((AccumuloRdfConfiguration) rdfConfig, user, pswd, ryaInstance);
+ dao = getAccumuloDAO((AccumuloRdfConfiguration)rdfConfig);
+ }
+ store.setRyaDAO(dao);
+ rdfConfig.setTablePrefix(ryaInstance);
+
+ if (rdfConfig.isInfer()){
+ final InferenceEngine inferenceEngine = new InferenceEngine();
+ inferenceEngine.setConf(rdfConfig);
+ inferenceEngine.setRyaDAO(dao);
+ inferenceEngine.init();
+ store.setInferenceEngine(inferenceEngine);
+ }
+
+ store.initialize();
+
+ return store;
+ }
+
+ private static MongoDBRyaDAO getMongoDAO(final MongoDBRdfConfiguration config, final MongoClient client) throws RyaDAOException {
+ MongoDBRyaDAO dao = null;
+ OptionalConfigUtils.setIndexers(config);
+ if(client != null) {
+ dao = new MongoDBRyaDAO(config, client);
+ } else {
+ try {
+ dao = new MongoDBRyaDAO(config);
+ } catch (NumberFormatException | UnknownHostException e) {
+ throw new RyaDAOException("Unable to connect to mongo at the configured location.", e);
+ }
+ }
+ dao.init();
+ return dao;
+ }
+
+ private static AccumuloRyaDAO getAccumuloDAO(final AccumuloRdfConfiguration config) throws AccumuloException, AccumuloSecurityException, RyaDAOException {
+ final Connector connector = ConfigUtils.getConnector(config);
+ final AccumuloRyaDAO dao = new AccumuloRyaDAO();
+ dao.setConnector(connector);
+
+ OptionalConfigUtils.setIndexers(config);
+ config.setDisplayQueryPlan(true);
+
+ dao.setConf(config);
+ dao.init();
+ return dao;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/OptionalConfigUtils.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/OptionalConfigUtils.java b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/OptionalConfigUtils.java
new file mode 100644
index 0000000..089610b
--- /dev/null
+++ b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/OptionalConfigUtils.java
@@ -0,0 +1,141 @@
+package mvm.rya.indexing;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static java.util.Objects.requireNonNull;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.BatchScanner;
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.MultiTableBatchWriter;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableExistsException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.ZooKeeperInstance;
+import org.apache.accumulo.core.client.admin.TableOperations;
+import org.apache.accumulo.core.client.mock.MockInstance;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.JobContext;
+import org.apache.hadoop.util.ReflectionUtils;
+import org.apache.log4j.Logger;
+import org.openrdf.model.URI;
+import org.openrdf.model.impl.URIImpl;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+
+import mvm.rya.accumulo.AccumuloRdfConfiguration;
+import mvm.rya.api.RdfCloudTripleStoreConfiguration;
+import mvm.rya.api.instance.RyaDetails;
+import mvm.rya.indexing.GeoEnabledFilterFunctionOptimizer;
+import mvm.rya.indexing.accumulo.ConfigUtils;
+import mvm.rya.indexing.accumulo.entity.EntityCentricIndex;
+import mvm.rya.indexing.accumulo.entity.EntityOptimizer;
+import mvm.rya.indexing.accumulo.freetext.AccumuloFreeTextIndexer;
+import mvm.rya.indexing.accumulo.freetext.LuceneTokenizer;
+import mvm.rya.indexing.accumulo.freetext.Tokenizer;
+import mvm.rya.indexing.accumulo.geo.GeoMesaGeoIndexer;
+import mvm.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer;
+import mvm.rya.indexing.external.PrecomputedJoinIndexer;
+import mvm.rya.indexing.mongodb.freetext.MongoFreeTextIndexer;
+import mvm.rya.indexing.mongodb.geo.MongoGeoIndexer;
+import mvm.rya.indexing.pcj.matching.PCJOptimizer;
+
+/**
+ * A set of configuration utils to read a Hadoop {@link Configuration} object and create Cloudbase/Accumulo objects.
+ * Soon will deprecate this class. Use installer for the set methods, use {@link RyaDetails} for the get methods.
+ * New code must separate parameters that are set at Rya install time from that which is specific to the client.
+ * Also Accumulo index tables are pushed down to the implementation and not configured in conf.
+ */
+public class OptionalConfigUtils extends ConfigUtils {
+ private static final Logger logger = Logger.getLogger(OptionalConfigUtils.class);
+
+
+ public static final String GEO_NUM_PARTITIONS = "sc.geo.numPartitions";
+
+ public static final String USE_GEO = "sc.use_geo";
+ public static final String USE_FREETEXT = "sc.use_freetext";
+ public static final String USE_TEMPORAL = "sc.use_temporal";
+ public static final String USE_ENTITY = "sc.use_entity";
+ public static final String USE_PCJ = "sc.use_pcj";
+ public static final String USE_OPTIMAL_PCJ = "sc.use.optimal.pcj";
+ public static final String USE_PCJ_UPDATER_INDEX = "sc.use.updater";
+ public static final String GEO_PREDICATES_LIST = "sc.geo.predicates";
+
+ public static Set<URI> getGeoPredicates(final Configuration conf) {
+ return getPredicates(conf, GEO_PREDICATES_LIST);
+ }
+
+ public static int getGeoNumPartitions(final Configuration conf) {
+ return conf.getInt(GEO_NUM_PARTITIONS, getNumPartitions(conf));
+ }
+
+ public static boolean getUseGeo(final Configuration conf) {
+ return conf.getBoolean(USE_GEO, false);
+ }
+
+
+ public static void setIndexers(final RdfCloudTripleStoreConfiguration conf) {
+
+ final List<String> indexList = Lists.newArrayList();
+ final List<String> optimizers = Lists.newArrayList();
+
+ boolean useFilterIndex = false;
+ ConfigUtils.setIndexers(conf);
+ for (String index : conf.getStrings(AccumuloRdfConfiguration.CONF_ADDITIONAL_INDEXERS)){
+ indexList.add(index);
+ }
+ for (String optimizer : conf.getStrings(RdfCloudTripleStoreConfiguration.CONF_OPTIMIZERS)){
+ optimizers.add(optimizer);
+ }
+
+ if (ConfigUtils.getUseMongo(conf)) {
+ if (getUseGeo(conf)) {
+ indexList.add(MongoGeoIndexer.class.getName());
+ useFilterIndex = true;
+ }
+ } else {
+ if (getUseGeo(conf)) {
+ indexList.add(GeoMesaGeoIndexer.class.getName());
+ useFilterIndex = true;
+ }
+ }
+
+ if (useFilterIndex) {
+ optimizers.remove(FilterFunctionOptimizer.class.getName());
+ optimizers.add(GeoEnabledFilterFunctionOptimizer.class.getName());
+ }
+
+ conf.setStrings(AccumuloRdfConfiguration.CONF_ADDITIONAL_INDEXERS, indexList.toArray(new String[]{}));
+ conf.setStrings(RdfCloudTripleStoreConfiguration.CONF_OPTIMIZERS, optimizers.toArray(new String[]{}));
+
+ }
+
+
+
+}
[2/6] incubator-rya git commit: RYA-177 adding optional geoindexing
profile
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java
new file mode 100644
index 0000000..fe173af
--- /dev/null
+++ b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java
@@ -0,0 +1,518 @@
+package mvm.rya.indexing.accumulo.geo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.mock.MockInstance;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.log4j.Logger;
+import org.geotools.data.DataStore;
+import org.geotools.data.DataStoreFinder;
+import org.geotools.data.DataUtilities;
+import org.geotools.data.FeatureSource;
+import org.geotools.data.FeatureStore;
+import org.geotools.data.Query;
+import org.geotools.factory.CommonFactoryFinder;
+import org.geotools.factory.Hints;
+import org.geotools.feature.DefaultFeatureCollection;
+import org.geotools.feature.FeatureIterator;
+import org.geotools.feature.SchemaException;
+import org.geotools.feature.simple.SimpleFeatureBuilder;
+import org.geotools.filter.text.cql2.CQLException;
+import org.geotools.filter.text.ecql.ECQL;
+import org.locationtech.geomesa.accumulo.data.AccumuloDataStore;
+import org.locationtech.geomesa.accumulo.index.Constants;
+import org.locationtech.geomesa.utils.geotools.SimpleFeatureTypes;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.filter.Filter;
+import org.opengis.filter.FilterFactory;
+import org.opengis.filter.identity.Identifier;
+import org.openrdf.model.Literal;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.query.QueryEvaluationException;
+
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKTReader;
+
+import info.aduna.iteration.CloseableIteration;
+import mvm.rya.accumulo.experimental.AbstractAccumuloIndexer;
+import mvm.rya.api.RdfCloudTripleStoreConfiguration;
+import mvm.rya.api.domain.RyaStatement;
+import mvm.rya.api.resolver.RyaToRdfConversions;
+import mvm.rya.indexing.GeoIndexer;
+import mvm.rya.indexing.Md5Hash;
+import mvm.rya.indexing.OptionalConfigUtils;
+import mvm.rya.indexing.StatementConstraints;
+import mvm.rya.indexing.StatementSerializer;
+import mvm.rya.indexing.accumulo.ConfigUtils;
+
+/**
+ * A {@link GeoIndexer} wrapper around a GeoMesa {@link AccumuloDataStore}. This class configures and connects to the Datastore, creates the
+ * RDF Feature Type, and interacts with the Datastore.
+ * <p>
+ * Specifically, this class creates a RDF Feature type and stores each RDF Statement as a RDF Feature in the datastore. Each feature
+ * contains the standard set of GeoMesa attributes (Geometry, Start Date, and End Date). The GeoMesaGeoIndexer populates the Geometry
+ * attribute by parsing the Well-Known Text contained in the RDF Statement\u2019s object literal value.
+ * <p>
+ * The RDF Feature contains four additional attributes for each component of the RDF Statement. These attributes are:
+ * <p>
+ * <table border="1">
+ * <tr>
+ * <th>Name</th>
+ * <th>Symbol</th>
+ * <th>Type</th>
+ * </tr>
+ * <tr>
+ * <td>Subject Attribute</td>
+ * <td>S</td>
+ * <td>String</td>
+ * </tr>
+ * </tr>
+ * <tr>
+ * <td>Predicate Attribute</td>
+ * <td>P</td>
+ * <td>String</td>
+ * </tr>
+ * </tr>
+ * <tr>
+ * <td>Object Attribute</td>
+ * <td>O</td>
+ * <td>String</td>
+ * </tr>
+ * </tr>
+ * <tr>
+ * <td>Context Attribute</td>
+ * <td>C</td>
+ * <td>String</td>
+ * </tr>
+ * </table>
+ */
+public class GeoMesaGeoIndexer extends AbstractAccumuloIndexer implements GeoIndexer {
+
+ private static final String TABLE_SUFFIX = "geo";
+
+ private static final Logger logger = Logger.getLogger(GeoMesaGeoIndexer.class);
+
+ private static final String FEATURE_NAME = "RDF";
+
+ private static final String SUBJECT_ATTRIBUTE = "S";
+ private static final String PREDICATE_ATTRIBUTE = "P";
+ private static final String OBJECT_ATTRIBUTE = "O";
+ private static final String CONTEXT_ATTRIBUTE = "C";
+
+ private Set<URI> validPredicates;
+ private Configuration conf;
+ private FeatureStore<SimpleFeatureType, SimpleFeature> featureStore;
+ private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource;
+ private SimpleFeatureType featureType;
+ private boolean isInit = false;
+
+ //initialization occurs in setConf because index is created using reflection
+ @Override
+ public void setConf(final Configuration conf) {
+ this.conf = conf;
+ if (!isInit) {
+ try {
+ initInternal();
+ isInit = true;
+ } catch (final IOException e) {
+ logger.warn("Unable to initialize index. Throwing Runtime Exception. ", e);
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ @Override
+ public Configuration getConf() {
+ return conf;
+ }
+
+
+ private void initInternal() throws IOException {
+ validPredicates = ConfigUtils.getGeoPredicates(conf);
+
+ final DataStore dataStore = createDataStore(conf);
+
+ try {
+ featureType = getStatementFeatureType(dataStore);
+ } catch (final IOException e) {
+ throw new IOException(e);
+ } catch (final SchemaException e) {
+ throw new IOException(e);
+ }
+
+ featureSource = dataStore.getFeatureSource(featureType.getName());
+ if (!(featureSource instanceof FeatureStore)) {
+ throw new IllegalStateException("Could not retrieve feature store");
+ }
+ featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) featureSource;
+ }
+
+ private static DataStore createDataStore(final Configuration conf) throws IOException {
+ // get the configuration parameters
+ final Instance instance = ConfigUtils.getInstance(conf);
+ final boolean useMock = instance instanceof MockInstance;
+ final String instanceId = instance.getInstanceName();
+ final String zookeepers = instance.getZooKeepers();
+ final String user = ConfigUtils.getUsername(conf);
+ final String password = ConfigUtils.getPassword(conf);
+ final String auths = ConfigUtils.getAuthorizations(conf).toString();
+ final String tableName = getTableName(conf);
+ final int numParitions = OptionalConfigUtils.getGeoNumPartitions(conf);
+
+ final String featureSchemaFormat = "%~#s%" + numParitions + "#r%" + FEATURE_NAME
+ + "#cstr%0,3#gh%yyyyMMdd#d::%~#s%3,2#gh::%~#s%#id";
+ // build the map of parameters
+ final Map<String, Serializable> params = new HashMap<String, Serializable>();
+ params.put("instanceId", instanceId);
+ params.put("zookeepers", zookeepers);
+ params.put("user", user);
+ params.put("password", password);
+ params.put("auths", auths);
+ params.put("tableName", tableName);
+ params.put("indexSchemaFormat", featureSchemaFormat);
+ params.put("useMock", Boolean.toString(useMock));
+
+ // fetch the data store from the finder
+ return DataStoreFinder.getDataStore(params);
+ }
+
+ private static SimpleFeatureType getStatementFeatureType(final DataStore dataStore) throws IOException, SchemaException {
+ SimpleFeatureType featureType;
+
+ final String[] datastoreFeatures = dataStore.getTypeNames();
+ if (Arrays.asList(datastoreFeatures).contains(FEATURE_NAME)) {
+ featureType = dataStore.getSchema(FEATURE_NAME);
+ } else {
+ final String featureSchema = SUBJECT_ATTRIBUTE + ":String," //
+ + PREDICATE_ATTRIBUTE + ":String," //
+ + OBJECT_ATTRIBUTE + ":String," //
+ + CONTEXT_ATTRIBUTE + ":String," //
+ + Constants.SF_PROPERTY_GEOMETRY + ":Geometry:srid=4326";
+ featureType = SimpleFeatureTypes.createType(FEATURE_NAME, featureSchema);
+ dataStore.createSchema(featureType);
+ }
+ return featureType;
+ }
+
+ @Override
+ public void storeStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
+ // create a feature collection
+ final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
+ for (final RyaStatement ryaStatement : ryaStatements) {
+ final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
+ // if the predicate list is empty, accept all predicates.
+ // Otherwise, make sure the predicate is on the "valid" list
+ final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
+
+ if (isValidPredicate && (statement.getObject() instanceof Literal)) {
+ try {
+ final SimpleFeature feature = createFeature(featureType, statement);
+ featureCollection.add(feature);
+ } catch (final ParseException e) {
+ logger.warn("Error getting geo from statement: " + statement.toString(), e);
+ }
+ }
+ }
+
+ // write this feature collection to the store
+ if (!featureCollection.isEmpty()) {
+ featureStore.addFeatures(featureCollection);
+ }
+ }
+
+
+ @Override
+ public void storeStatement(final RyaStatement statement) throws IOException {
+ storeStatements(Collections.singleton(statement));
+ }
+
+ private static SimpleFeature createFeature(final SimpleFeatureType featureType, final Statement statement) throws ParseException {
+ final String subject = StatementSerializer.writeSubject(statement);
+ final String predicate = StatementSerializer.writePredicate(statement);
+ final String object = StatementSerializer.writeObject(statement);
+ final String context = StatementSerializer.writeContext(statement);
+
+ // create the feature
+ final Object[] noValues = {};
+
+ // create the hash
+ final String statementId = Md5Hash.md5Base64(StatementSerializer.writeStatement(statement));
+ final SimpleFeature newFeature = SimpleFeatureBuilder.build(featureType, noValues, statementId);
+
+ // write the statement data to the fields
+ final Geometry geom = GeoParseUtils.getGeometry(statement);
+ if(geom == null || geom.isEmpty() || !geom.isValid()) {
+ throw new ParseException("Could not create geometry for statement " + statement);
+ }
+ newFeature.setDefaultGeometry(geom);
+
+ newFeature.setAttribute(SUBJECT_ATTRIBUTE, subject);
+ newFeature.setAttribute(PREDICATE_ATTRIBUTE, predicate);
+ newFeature.setAttribute(OBJECT_ATTRIBUTE, object);
+ newFeature.setAttribute(CONTEXT_ATTRIBUTE, context);
+
+ // preserve the ID that we created for this feature
+ // (set the hint to FALSE to have GeoTools generate IDs)
+ newFeature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);
+
+ return newFeature;
+ }
+
+ private CloseableIteration<Statement, QueryEvaluationException> performQuery(final String type, final Geometry geometry,
+ final StatementConstraints contraints) {
+ final List<String> filterParms = new ArrayList<String>();
+
+ filterParms.add(type + "(" + Constants.SF_PROPERTY_GEOMETRY + ", " + geometry + " )");
+
+ if (contraints.hasSubject()) {
+ filterParms.add("( " + SUBJECT_ATTRIBUTE + "= '" + contraints.getSubject() + "') ");
+ }
+ if (contraints.hasContext()) {
+ filterParms.add("( " + CONTEXT_ATTRIBUTE + "= '" + contraints.getContext() + "') ");
+ }
+ if (contraints.hasPredicates()) {
+ final List<String> predicates = new ArrayList<String>();
+ for (final URI u : contraints.getPredicates()) {
+ predicates.add("( " + PREDICATE_ATTRIBUTE + "= '" + u.stringValue() + "') ");
+ }
+ filterParms.add("(" + StringUtils.join(predicates, " OR ") + ")");
+ }
+
+ final String filterString = StringUtils.join(filterParms, " AND ");
+ logger.info("Performing geomesa query : " + filterString);
+
+ return getIteratorWrapper(filterString);
+ }
+
+ private CloseableIteration<Statement, QueryEvaluationException> getIteratorWrapper(final String filterString) {
+
+ return new CloseableIteration<Statement, QueryEvaluationException>() {
+
+ private FeatureIterator<SimpleFeature> featureIterator = null;
+
+ FeatureIterator<SimpleFeature> getIterator() throws QueryEvaluationException {
+ if (featureIterator == null) {
+ Filter cqlFilter;
+ try {
+ cqlFilter = ECQL.toFilter(filterString);
+ } catch (final CQLException e) {
+ logger.error("Error parsing query: " + filterString, e);
+ throw new QueryEvaluationException(e);
+ }
+
+ final Query query = new Query(featureType.getTypeName(), cqlFilter);
+ try {
+ featureIterator = featureSource.getFeatures(query).features();
+ } catch (final IOException e) {
+ logger.error("Error performing query: " + filterString, e);
+ throw new QueryEvaluationException(e);
+ }
+
+ }
+ return featureIterator;
+ }
+
+ @Override
+ public boolean hasNext() throws QueryEvaluationException {
+ return getIterator().hasNext();
+ }
+
+ @Override
+ public Statement next() throws QueryEvaluationException {
+ final SimpleFeature feature = getIterator().next();
+ final String subjectString = feature.getAttribute(SUBJECT_ATTRIBUTE).toString();
+ final String predicateString = feature.getAttribute(PREDICATE_ATTRIBUTE).toString();
+ final String objectString = feature.getAttribute(OBJECT_ATTRIBUTE).toString();
+ final String contextString = feature.getAttribute(CONTEXT_ATTRIBUTE).toString();
+ final Statement statement = StatementSerializer.readStatement(subjectString, predicateString, objectString, contextString);
+ return statement;
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("Remove not implemented");
+ }
+
+ @Override
+ public void close() throws QueryEvaluationException {
+ getIterator().close();
+ }
+ };
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryEquals(final Geometry query, final StatementConstraints contraints) {
+ return performQuery("EQUALS", query, contraints);
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryDisjoint(final Geometry query, final StatementConstraints contraints) {
+ return performQuery("DISJOINT", query, contraints);
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryIntersects(final Geometry query, final StatementConstraints contraints) {
+ return performQuery("INTERSECTS", query, contraints);
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryTouches(final Geometry query, final StatementConstraints contraints) {
+ return performQuery("TOUCHES", query, contraints);
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryCrosses(final Geometry query, final StatementConstraints contraints) {
+ return performQuery("CROSSES", query, contraints);
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryWithin(final Geometry query, final StatementConstraints contraints) {
+ return performQuery("WITHIN", query, contraints);
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryContains(final Geometry query, final StatementConstraints contraints) {
+ return performQuery("CONTAINS", query, contraints);
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryOverlaps(final Geometry query, final StatementConstraints contraints) {
+ return performQuery("OVERLAPS", query, contraints);
+ }
+
+ @Override
+ public Set<URI> getIndexablePredicates() {
+ return validPredicates;
+ }
+
+ @Override
+ public void flush() throws IOException {
+ // TODO cache and flush features instead of writing them one at a time
+ }
+
+ @Override
+ public void close() throws IOException {
+ flush();
+ }
+
+
+ @Override
+ public String getTableName() {
+ return getTableName(conf);
+ }
+
+ /**
+ * Get the Accumulo table that will be used by this index.
+ * @param conf
+ * @return table name guaranteed to be used by instances of this index
+ */
+ public static String getTableName(Configuration conf) {
+ return ConfigUtils.getTablePrefix(conf) + TABLE_SUFFIX;
+ }
+
+ private void deleteStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
+ // create a feature collection
+ final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
+
+ for (final RyaStatement ryaStatement : ryaStatements) {
+ final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
+ // if the predicate list is empty, accept all predicates.
+ // Otherwise, make sure the predicate is on the "valid" list
+ final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
+
+ if (isValidPredicate && (statement.getObject() instanceof Literal)) {
+ try {
+ final SimpleFeature feature = createFeature(featureType, statement);
+ featureCollection.add(feature);
+ } catch (final ParseException e) {
+ logger.warn("Error getting geo from statement: " + statement.toString(), e);
+ }
+ }
+ }
+
+ // remove this feature collection from the store
+ if (!featureCollection.isEmpty()) {
+ final Set<Identifier> featureIds = new HashSet<Identifier>();
+ final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
+ final Set<String> stringIds = DataUtilities.fidSet(featureCollection);
+ for (final String id : stringIds) {
+ featureIds.add(filterFactory.featureId(id));
+ }
+ final Filter filter = filterFactory.id(featureIds);
+ featureStore.removeFeatures(filter);
+ }
+ }
+
+
+ @Override
+ public void deleteStatement(final RyaStatement statement) throws IOException {
+ deleteStatements(Collections.singleton(statement));
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setConnector(final Connector connector) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void destroy() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void purge(final RdfCloudTripleStoreConfiguration configuration) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dropAndDestroy() {
+ // TODO Auto-generated method stub
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoParseUtils.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoParseUtils.java b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoParseUtils.java
new file mode 100644
index 0000000..fa3699a
--- /dev/null
+++ b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoParseUtils.java
@@ -0,0 +1,119 @@
+package mvm.rya.indexing.accumulo.geo;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import org.apache.log4j.Logger;
+import org.geotools.gml3.GMLConfiguration;
+import org.geotools.xml.Parser;
+import org.openrdf.model.Literal;
+import org.openrdf.model.Statement;
+import org.xml.sax.SAXException;
+
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKTReader;
+
+import mvm.rya.indexing.GeoConstants;
+
+public class GeoParseUtils {
+ static final Logger logger = Logger.getLogger(GeoParseUtils.class);
+ /**
+ * @deprecated Not needed since geo literals may be WKT or GML.
+ *
+ * This method warns on a condition that must already be tested. Replaced by
+ * {@link #getLiteral(Statement)} and {@link #getGeometry(Statement}
+ * and getLiteral(statement).toString()
+ * and getLiteral(statement).getDatatype()
+ */
+ @Deprecated
+ public static String getWellKnownText(Statement statement) throws ParseException {
+ Literal lit = getLiteral(statement);
+ if (!GeoConstants.XMLSCHEMA_OGC_WKT.equals(lit.getDatatype())) {
+ logger.warn("Literal is not of type " + GeoConstants.XMLSCHEMA_OGC_WKT + ": " + statement.toString());
+ }
+ return lit.getLabel().toString();
+ }
+
+ public static Literal getLiteral(Statement statement) throws ParseException {
+ org.openrdf.model.Value v = statement.getObject();
+ if (!(v instanceof Literal)) {
+ throw new ParseException("Statement does not contain Literal: " + statement.toString());
+ }
+ Literal lit = (Literal) v;
+ return lit;
+ }
+
+ /**
+ * Parse GML/wkt literal to Geometry
+ *
+ * @param statement
+ * @return
+ * @throws ParseException
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ */
+ public static Geometry getGeometry(Statement statement) throws ParseException {
+ // handle GML or WKT
+ Literal lit = getLiteral(statement);
+ if (GeoConstants.XMLSCHEMA_OGC_WKT.equals(lit.getDatatype())) {
+ final String wkt = lit.getLabel().toString();
+ return (new WKTReader()).read(wkt);
+ } else if (GeoConstants.XMLSCHEMA_OGC_GML.equals(lit.getDatatype())) {
+ String gml = lit.getLabel().toString();
+ try {
+ return getGeometryGml(gml);
+ } catch (IOException | SAXException | ParserConfigurationException e) {
+ throw new ParseException(e);
+ }
+ } else {
+ throw new ParseException("Literal is unknown geo type, expecting WKT or GML: " + statement.toString());
+ }
+ }
+ /**
+ * Convert GML/XML string into a geometry that can be indexed.
+ * @param gmlString
+ * @return
+ * @throws IOException
+ * @throws SAXException
+ * @throws ParserConfigurationException
+ */
+ public static Geometry getGeometryGml(String gmlString) throws IOException, SAXException, ParserConfigurationException {
+ Reader reader = new StringReader(gmlString);
+ GMLConfiguration gmlConfiguration = new GMLConfiguration();
+ Parser gmlParser = new Parser(gmlConfiguration);
+ // gmlParser.setStrict(false); // attempt at allowing deprecated elements, but no.
+ // gmlParser.setValidating(false);
+ final Geometry geometry = (Geometry) gmlParser.parse(reader);
+ // This sometimes gets populated with the SRS/CRS: geometry.getUserData()
+ // Always returns 0 : geometry.getSRID()
+ //TODO geometry.setUserData(some default CRS); OR geometry.setSRID(some default CRS)
+
+ return geometry;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoTupleSet.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoTupleSet.java b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoTupleSet.java
new file mode 100644
index 0000000..a3a0630
--- /dev/null
+++ b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoTupleSet.java
@@ -0,0 +1,363 @@
+package mvm.rya.indexing.accumulo.geo;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.QueryEvaluationException;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Maps;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKTReader;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import info.aduna.iteration.CloseableIteration;
+import mvm.rya.indexing.GeoConstants;
+import mvm.rya.indexing.GeoIndexer;
+import mvm.rya.indexing.IndexingExpr;
+import mvm.rya.indexing.IteratorFactory;
+import mvm.rya.indexing.SearchFunction;
+import mvm.rya.indexing.StatementConstraints;
+import mvm.rya.indexing.external.tupleSet.ExternalTupleSet;
+
+//Indexing Node for geo expressions to be inserted into execution plan
+//to delegate geo portion of query to geo index
+public class GeoTupleSet extends ExternalTupleSet {
+
+ private final Configuration conf;
+ private final GeoIndexer geoIndexer;
+ private final IndexingExpr filterInfo;
+
+
+ public GeoTupleSet(final IndexingExpr filterInfo, final GeoIndexer geoIndexer) {
+ this.filterInfo = filterInfo;
+ this.geoIndexer = geoIndexer;
+ conf = geoIndexer.getConf();
+ }
+
+ @Override
+ public Set<String> getBindingNames() {
+ return filterInfo.getBindingNames();
+ }
+
+ @Override
+ public GeoTupleSet clone() {
+ return new GeoTupleSet(filterInfo, geoIndexer);
+ }
+
+ @Override
+ public double cardinality() {
+ return 0.0; // No idea how the estimate cardinality here.
+ }
+
+
+ @Override
+ public String getSignature() {
+ return "(GeoTuple Projection) " + "variables: " + Joiner.on(", ").join(getBindingNames()).replaceAll("\\s+", " ");
+ }
+
+
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof GeoTupleSet)) {
+ return false;
+ }
+ final GeoTupleSet arg = (GeoTupleSet) other;
+ return filterInfo.equals(arg.filterInfo);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 31*result + filterInfo.hashCode();
+
+ return result;
+ }
+
+
+
+ /**
+ * Returns an iterator over the result set of the contained IndexingExpr.
+ * <p>
+ * Should be thread-safe (concurrent invocation {@link OfflineIterable} this
+ * method can be expected with some query evaluators.
+ */
+ @Override
+ public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings)
+ throws QueryEvaluationException {
+
+
+ final URI funcURI = filterInfo.getFunction();
+ final SearchFunction searchFunction = new GeoSearchFunctionFactory(conf).getSearchFunction(funcURI);
+ if(filterInfo.getArguments().length > 1) {
+ throw new IllegalArgumentException("Index functions do not support more than two arguments.");
+ }
+
+ final String queryText = filterInfo.getArguments()[0].stringValue();
+
+ return IteratorFactory.getIterator(filterInfo.getSpConstraint(), bindings, queryText, searchFunction);
+ }
+
+
+
+ //returns appropriate search function for a given URI
+ //search functions used in GeoMesaGeoIndexer to access index
+ public class GeoSearchFunctionFactory {
+
+ Configuration conf;
+
+ private final Map<URI, SearchFunction> SEARCH_FUNCTION_MAP = Maps.newHashMap();
+
+ public GeoSearchFunctionFactory(final Configuration conf) {
+ this.conf = conf;
+ }
+
+
+ /**
+ * Get a {@link GeoSearchFunction} for a given URI.
+ *
+ * @param searchFunction
+ * @return
+ */
+ public SearchFunction getSearchFunction(final URI searchFunction) {
+
+ SearchFunction geoFunc = null;
+
+ try {
+ geoFunc = getSearchFunctionInternal(searchFunction);
+ } catch (final QueryEvaluationException e) {
+ e.printStackTrace();
+ }
+
+ return geoFunc;
+ }
+
+ private SearchFunction getSearchFunctionInternal(final URI searchFunction) throws QueryEvaluationException {
+ final SearchFunction sf = SEARCH_FUNCTION_MAP.get(searchFunction);
+
+ if (sf != null) {
+ return sf;
+ } else {
+ throw new QueryEvaluationException("Unknown Search Function: " + searchFunction.stringValue());
+ }
+ }
+
+ private final SearchFunction GEO_EQUALS = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
+ final StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ final WKTReader reader = new WKTReader();
+ final Geometry geometry = reader.read(queryText);
+ final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (final ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_EQUALS";
+ };
+ };
+
+ private final SearchFunction GEO_DISJOINT = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
+ final StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ final WKTReader reader = new WKTReader();
+ final Geometry geometry = reader.read(queryText);
+ final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (final ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_DISJOINT";
+ };
+ };
+
+ private final SearchFunction GEO_INTERSECTS = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
+ final StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ final WKTReader reader = new WKTReader();
+ final Geometry geometry = reader.read(queryText);
+ final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (final ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_INTERSECTS";
+ };
+ };
+
+ private final SearchFunction GEO_TOUCHES = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
+ final StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ final WKTReader reader = new WKTReader();
+ final Geometry geometry = reader.read(queryText);
+ final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (final ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_TOUCHES";
+ };
+ };
+
+ private final SearchFunction GEO_CONTAINS = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
+ final StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ final WKTReader reader = new WKTReader();
+ final Geometry geometry = reader.read(queryText);
+ final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (final ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_CONTAINS";
+ };
+ };
+
+ private final SearchFunction GEO_OVERLAPS = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
+ final StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ final WKTReader reader = new WKTReader();
+ final Geometry geometry = reader.read(queryText);
+ final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (final ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_OVERLAPS";
+ };
+ };
+
+ private final SearchFunction GEO_CROSSES = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
+ final StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ final WKTReader reader = new WKTReader();
+ final Geometry geometry = reader.read(queryText);
+ final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (final ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_CROSSES";
+ };
+ };
+
+ private final SearchFunction GEO_WITHIN = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
+ final StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ final WKTReader reader = new WKTReader();
+ final Geometry geometry = reader.read(queryText);
+ final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (final ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_WITHIN";
+ };
+ };
+
+ {
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_EQUALS, GEO_EQUALS);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_DISJOINT, GEO_DISJOINT);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_INTERSECTS, GEO_INTERSECTS);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_TOUCHES, GEO_TOUCHES);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_CONTAINS, GEO_CONTAINS);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_OVERLAPS, GEO_OVERLAPS);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_CROSSES, GEO_CROSSES);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_WITHIN, GEO_WITHIN);
+ }
+
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/GeoMongoDBStorageStrategy.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/GeoMongoDBStorageStrategy.java b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/GeoMongoDBStorageStrategy.java
new file mode 100644
index 0000000..9411330
--- /dev/null
+++ b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/GeoMongoDBStorageStrategy.java
@@ -0,0 +1,143 @@
+package mvm.rya.indexing.mongodb.geo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.openrdf.model.Statement;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKTReader;
+
+import mvm.rya.api.domain.RyaStatement;
+import mvm.rya.api.resolver.RyaToRdfConversions;
+import mvm.rya.indexing.accumulo.geo.GeoParseUtils;
+import mvm.rya.indexing.mongodb.IndexingMongoDBStorageStrategy;
+
+public class GeoMongoDBStorageStrategy extends IndexingMongoDBStorageStrategy {
+ private static final Logger LOG = Logger.getLogger(GeoMongoDBStorageStrategy.class);
+
+ private static final String GEO = "location";
+ public enum GeoQueryType {
+ INTERSECTS {
+ @Override
+ public String getKeyword() {
+ return "$geoIntersects";
+ }
+ }, WITHIN {
+ @Override
+ public String getKeyword() {
+ return "$geoWithin";
+ }
+ },
+ EQUALS {
+ @Override
+ public String getKeyword() {
+ return "$near";
+ }
+ };
+
+ public abstract String getKeyword();
+ }
+
+ static class GeoQuery {
+ private final GeoQueryType queryType;
+ private final Geometry geo;
+
+ public GeoQuery(final GeoQueryType queryType, final Geometry geo) {
+ this.queryType = queryType;
+ this.geo = geo;
+ }
+
+ public GeoQueryType getQueryType() {
+ return queryType;
+ }
+ public Geometry getGeo() {
+ return geo;
+ }
+ }
+
+ private final double maxDistance;
+
+ public GeoMongoDBStorageStrategy(final double maxDistance) {
+ this.maxDistance = maxDistance;
+ }
+
+ @Override
+ public void createIndices(final DBCollection coll){
+ coll.createIndex("{" + GEO + " : \"2dsphere\"" );
+ }
+
+ public DBObject getQuery(final GeoQuery queryObj) {
+ final Geometry geo = queryObj.getGeo();
+ final GeoQueryType queryType = queryObj.getQueryType();
+
+ BasicDBObject query;
+ if (queryType.equals(GeoQueryType.EQUALS)){
+ final List<double[]> points = getCorrespondingPoints(geo);
+ if (points.size() == 1){
+ final List circle = new ArrayList();
+ circle.add(points.get(0));
+ circle.add(maxDistance);
+ final BasicDBObject polygon = new BasicDBObject("$centerSphere", circle);
+ query = new BasicDBObject(GEO, new BasicDBObject(GeoQueryType.WITHIN.getKeyword(), polygon));
+ } else {
+ query = new BasicDBObject(GEO, points);
+ }
+ } else {
+ query = new BasicDBObject(GEO, new BasicDBObject(queryType.getKeyword(), new BasicDBObject("$polygon", getCorrespondingPoints(geo))));
+ }
+
+ return query;
+ }
+
+ @Override
+ public DBObject serialize(final RyaStatement ryaStatement) {
+ // if the object is wkt, then try to index it
+ // write the statement data to the fields
+ try {
+ final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
+ final Geometry geo = (new WKTReader()).read(GeoParseUtils.getWellKnownText(statement));
+ final BasicDBObject base = (BasicDBObject) super.serialize(ryaStatement);
+ base.append(GEO, getCorrespondingPoints(geo));
+ return base;
+ } catch(final ParseException e) {
+ LOG.error("Could not create geometry for statement " + ryaStatement, e);
+ return null;
+ }
+ }
+
+ private List<double[]> getCorrespondingPoints(final Geometry geo){
+ final List<double[]> points = new ArrayList<double[]>();
+ for (final Coordinate coord : geo.getCoordinates()){
+ points.add(new double[] {
+ coord.x, coord.y
+ });
+ }
+ return points;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoIndexer.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoIndexer.java b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoIndexer.java
new file mode 100644
index 0000000..7589f03
--- /dev/null
+++ b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoIndexer.java
@@ -0,0 +1,112 @@
+package mvm.rya.indexing.mongodb.geo;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static mvm.rya.indexing.mongodb.geo.GeoMongoDBStorageStrategy.GeoQueryType.EQUALS;
+import static mvm.rya.indexing.mongodb.geo.GeoMongoDBStorageStrategy.GeoQueryType.INTERSECTS;
+import static mvm.rya.indexing.mongodb.geo.GeoMongoDBStorageStrategy.GeoQueryType.WITHIN;
+
+import org.apache.log4j.Logger;
+import org.openrdf.model.Statement;
+import org.openrdf.query.QueryEvaluationException;
+
+import com.mongodb.DBObject;
+import com.vividsolutions.jts.geom.Geometry;
+
+import info.aduna.iteration.CloseableIteration;
+import mvm.rya.indexing.GeoIndexer;
+import mvm.rya.indexing.StatementConstraints;
+import mvm.rya.indexing.accumulo.ConfigUtils;
+import mvm.rya.indexing.mongodb.AbstractMongoIndexer;
+import mvm.rya.indexing.mongodb.geo.GeoMongoDBStorageStrategy.GeoQuery;
+import mvm.rya.mongodb.MongoDBRdfConfiguration;
+
+public class MongoGeoIndexer extends AbstractMongoIndexer<GeoMongoDBStorageStrategy> implements GeoIndexer {
+ private static final String COLLECTION_SUFFIX = "geo";
+ private static final Logger logger = Logger.getLogger(MongoGeoIndexer.class);
+
+ @Override
+ public void init() {
+ initCore();
+ predicates = ConfigUtils.getGeoPredicates(conf);
+ storageStrategy = new GeoMongoDBStorageStrategy(Double.valueOf(conf.get(MongoDBRdfConfiguration.MONGO_GEO_MAXDISTANCE, "1e-10")));
+ storageStrategy.createIndices(collection);
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryEquals(
+ final Geometry query, final StatementConstraints constraints) {
+ final DBObject queryObj = storageStrategy.getQuery(new GeoQuery(EQUALS, query));
+ return withConstraints(constraints, queryObj);
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryDisjoint(
+ final Geometry query, final StatementConstraints constraints) {
+ throw new UnsupportedOperationException(
+ "Disjoint queries are not supported in Mongo DB.");
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryIntersects(
+ final Geometry query, final StatementConstraints constraints) {
+ final DBObject queryObj = storageStrategy.getQuery(new GeoQuery(INTERSECTS, query));
+ return withConstraints(constraints, queryObj);
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryTouches(
+ final Geometry query, final StatementConstraints constraints) {
+ throw new UnsupportedOperationException(
+ "Touches queries are not supported in Mongo DB.");
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryCrosses(
+ final Geometry query, final StatementConstraints constraints) {
+ throw new UnsupportedOperationException(
+ "Crosses queries are not supported in Mongo DB.");
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryWithin(
+ final Geometry query, final StatementConstraints constraints) {
+ final DBObject queryObj = storageStrategy.getQuery(new GeoQuery(WITHIN, query));
+ return withConstraints(constraints, queryObj);
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryContains(
+ final Geometry query, final StatementConstraints constraints) {
+ throw new UnsupportedOperationException(
+ "Contains queries are not supported in Mongo DB.");
+ }
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> queryOverlaps(
+ final Geometry query, final StatementConstraints constraints) {
+ throw new UnsupportedOperationException(
+ "Overlaps queries are not supported in Mongo DB.");
+ }
+
+ @Override
+ public String getCollectionName() {
+ return ConfigUtils.getTablePrefix(conf) + COLLECTION_SUFFIX;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoTupleSet.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoTupleSet.java b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoTupleSet.java
new file mode 100644
index 0000000..35e679e
--- /dev/null
+++ b/extras/rya.geoindexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoTupleSet.java
@@ -0,0 +1,360 @@
+package mvm.rya.indexing.mongodb.geo;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.QueryEvaluationException;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Maps;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKTReader;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import info.aduna.iteration.CloseableIteration;
+import mvm.rya.indexing.GeoConstants;
+import mvm.rya.indexing.GeoIndexer;
+import mvm.rya.indexing.IndexingExpr;
+import mvm.rya.indexing.IteratorFactory;
+import mvm.rya.indexing.SearchFunction;
+import mvm.rya.indexing.StatementConstraints;
+import mvm.rya.indexing.accumulo.geo.GeoTupleSet;
+import mvm.rya.indexing.external.tupleSet.ExternalTupleSet;
+
+public class MongoGeoTupleSet extends ExternalTupleSet {
+
+ private Configuration conf;
+ private GeoIndexer geoIndexer;
+ private IndexingExpr filterInfo;
+
+
+ public MongoGeoTupleSet(IndexingExpr filterInfo, GeoIndexer geoIndexer) {
+ this.filterInfo = filterInfo;
+ this.geoIndexer = geoIndexer;
+ this.conf = geoIndexer.getConf();
+ }
+
+ @Override
+ public Set<String> getBindingNames() {
+ return filterInfo.getBindingNames();
+ }
+
+ public GeoTupleSet clone() {
+ return new GeoTupleSet(filterInfo, geoIndexer);
+ }
+
+ @Override
+ public double cardinality() {
+ return 0.0; // No idea how the estimate cardinality here.
+ }
+
+
+ @Override
+ public String getSignature() {
+ return "(GeoTuple Projection) " + "variables: " + Joiner.on(", ").join(this.getBindingNames()).replaceAll("\\s+", " ");
+ }
+
+
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof MongoGeoTupleSet)) {
+ return false;
+ }
+ MongoGeoTupleSet arg = (MongoGeoTupleSet) other;
+ return this.filterInfo.equals(arg.filterInfo);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 31*result + filterInfo.hashCode();
+
+ return result;
+ }
+
+
+
+ /**
+ * Returns an iterator over the result set of the contained IndexingExpr.
+ * <p>
+ * Should be thread-safe (concurrent invocation {@link OfflineIterable} this
+ * method can be expected with some query evaluators.
+ */
+ @Override
+ public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSet bindings)
+ throws QueryEvaluationException {
+
+
+ URI funcURI = filterInfo.getFunction();
+ SearchFunction searchFunction = (new MongoGeoSearchFunctionFactory(conf)).getSearchFunction(funcURI);
+ if(filterInfo.getArguments().length > 1) {
+ throw new IllegalArgumentException("Index functions do not support more than two arguments.");
+ }
+
+ String queryText = filterInfo.getArguments()[0].stringValue();
+
+ return IteratorFactory.getIterator(filterInfo.getSpConstraint(), bindings, queryText, searchFunction);
+ }
+
+
+
+ //returns appropriate search function for a given URI
+ //search functions used in GeoMesaGeoIndexer to access index
+ public class MongoGeoSearchFunctionFactory {
+
+ Configuration conf;
+
+ private final Map<URI, SearchFunction> SEARCH_FUNCTION_MAP = Maps.newHashMap();
+
+ public MongoGeoSearchFunctionFactory(Configuration conf) {
+ this.conf = conf;
+ }
+
+
+ /**
+ * Get a {@link GeoSearchFunction} for a given URI.
+ *
+ * @param searchFunction
+ * @return
+ */
+ public SearchFunction getSearchFunction(final URI searchFunction) {
+
+ SearchFunction geoFunc = null;
+
+ try {
+ geoFunc = getSearchFunctionInternal(searchFunction);
+ } catch (QueryEvaluationException e) {
+ e.printStackTrace();
+ }
+
+ return geoFunc;
+ }
+
+ private SearchFunction getSearchFunctionInternal(final URI searchFunction) throws QueryEvaluationException {
+ SearchFunction sf = SEARCH_FUNCTION_MAP.get(searchFunction);
+
+ if (sf != null) {
+ return sf;
+ } else {
+ throw new QueryEvaluationException("Unknown Search Function: " + searchFunction.stringValue());
+ }
+ }
+
+ private final SearchFunction GEO_EQUALS = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
+ StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ WKTReader reader = new WKTReader();
+ Geometry geometry = reader.read(queryText);
+ CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_EQUALS";
+ };
+ };
+
+ private final SearchFunction GEO_DISJOINT = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
+ StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ WKTReader reader = new WKTReader();
+ Geometry geometry = reader.read(queryText);
+ CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_DISJOINT";
+ };
+ };
+
+ private final SearchFunction GEO_INTERSECTS = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
+ StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ WKTReader reader = new WKTReader();
+ Geometry geometry = reader.read(queryText);
+ CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_INTERSECTS";
+ };
+ };
+
+ private final SearchFunction GEO_TOUCHES = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
+ StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ WKTReader reader = new WKTReader();
+ Geometry geometry = reader.read(queryText);
+ CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_TOUCHES";
+ };
+ };
+
+ private final SearchFunction GEO_CONTAINS = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
+ StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ WKTReader reader = new WKTReader();
+ Geometry geometry = reader.read(queryText);
+ CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_CONTAINS";
+ };
+ };
+
+ private final SearchFunction GEO_OVERLAPS = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
+ StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ WKTReader reader = new WKTReader();
+ Geometry geometry = reader.read(queryText);
+ CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_OVERLAPS";
+ };
+ };
+
+ private final SearchFunction GEO_CROSSES = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
+ StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ WKTReader reader = new WKTReader();
+ Geometry geometry = reader.read(queryText);
+ CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_CROSSES";
+ };
+ };
+
+ private final SearchFunction GEO_WITHIN = new SearchFunction() {
+
+ @Override
+ public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
+ StatementConstraints contraints) throws QueryEvaluationException {
+ try {
+ WKTReader reader = new WKTReader();
+ Geometry geometry = reader.read(queryText);
+ CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
+ geometry, contraints);
+ return statements;
+ } catch (ParseException e) {
+ throw new QueryEvaluationException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GEO_WITHIN";
+ };
+ };
+
+ {
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_EQUALS, GEO_EQUALS);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_DISJOINT, GEO_DISJOINT);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_INTERSECTS, GEO_INTERSECTS);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_TOUCHES, GEO_TOUCHES);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_CONTAINS, GEO_CONTAINS);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_OVERLAPS, GEO_OVERLAPS);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_CROSSES, GEO_CROSSES);
+ SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_WITHIN, GEO_WITHIN);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerSfTest.java
----------------------------------------------------------------------
diff --git a/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerSfTest.java b/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerSfTest.java
new file mode 100644
index 0000000..69c3ce2
--- /dev/null
+++ b/extras/rya.geoindexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerSfTest.java
@@ -0,0 +1,514 @@
+package mvm.rya.indexing.accumulo.geo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.admin.TableOperations;
+import org.geotools.geometry.jts.Geometries;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.impl.StatementImpl;
+import org.openrdf.model.impl.URIImpl;
+import org.openrdf.model.impl.ValueFactoryImpl;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.LineString;
+import com.vividsolutions.jts.geom.LinearRing;
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.geom.Polygon;
+import com.vividsolutions.jts.geom.PrecisionModel;
+import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.gml2.GMLWriter;
+
+import info.aduna.iteration.CloseableIteration;
+import mvm.rya.accumulo.AccumuloRdfConfiguration;
+import mvm.rya.api.domain.RyaStatement;
+import mvm.rya.api.resolver.RdfToRyaConversions;
+import mvm.rya.api.resolver.RyaToRdfConversions;
+import mvm.rya.indexing.GeoConstants;
+import mvm.rya.indexing.StatementConstraints;
+import mvm.rya.indexing.accumulo.ConfigUtils;
+
+/**
+ * Tests all of the "simple functions" of the geoindexer specific to GML.
+ * Parameterized so that each test is run for WKT and for GML.
+ */
+@RunWith(value = Parameterized.class)
+public class GeoIndexerSfTest {
+ private static AccumuloRdfConfiguration conf;
+ private static GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
+ private static GeoMesaGeoIndexer g;
+
+ private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints();
+
+ // Here is the landscape:
+ /**
+ * <pre>
+ * 2---+---+---+---+---+---+
+ * | F |G |
+ * 1 A o(-1,1) o C |
+ * | | |
+ * 0---+---+ +---+---+(3,0)
+ * | | E |
+ * -1 B + .---+---+
+ * | | /| | |
+ * -2---+---+-/-+---+ +
+ * ^ / | D |
+ * -3 -2 -1 0---1---2 3 4
+ * </pre>
+ **/
+ private static final Polygon A = poly(bbox(-3, -2, 1, 2));
+ private static final Polygon B = poly(bbox(-3, -2, -1, 0));
+ private static final Polygon C = poly(bbox(1, 0, 3, 2));
+ private static final Polygon D = poly(bbox(0, -3, 2, -1));
+
+ private static final Point F = point(-1, 1);
+ private static final Point G = point(1, 1);
+
+ private static final LineString E = line(-1, -3, 0, -1);
+
+ private static final Map<Geometry, String> names = Maps.newHashMap();
+ static {
+ names.put(A, "A");
+ names.put(B, "B");
+ names.put(C, "C");
+ names.put(D, "D");
+ names.put(E, "E");
+ names.put(F, "F");
+ names.put(G, "G");
+ }
+
+ /**
+ * JUnit 4 parameterized iterates thru this list and calls the constructor with each.
+ * For each test, Call the constructor three times, for WKT and for GML encoding 1, and GML encoding 2
+ * @return
+ */
+ final static URI useJtsLibEncoding = new URIImpl("uri:useLib") ;
+ final static URI useRoughEncoding = new URIImpl("uri:useRough") ;
+
+ @Parameters
+ public static Collection<URI[]> constructorData() {
+ URI[][] data = new URI[][] { { GeoConstants.XMLSCHEMA_OGC_WKT,useJtsLibEncoding }, { GeoConstants.XMLSCHEMA_OGC_GML,useJtsLibEncoding } , { GeoConstants.XMLSCHEMA_OGC_GML,useRoughEncoding } };
+ return Arrays.asList(data);
+ }
+
+ private URI schemaToTest;
+ private URI encodeMethod;
+ /**
+ * Constructor required by JUnit parameterized runner. See data() for constructor values.
+ */
+ public GeoIndexerSfTest(URI schemaToTest, URI encodeMethod) {
+ this.schemaToTest=schemaToTest;
+ this.encodeMethod = encodeMethod;
+ }
+ /**
+ * Run before each test method.
+ * @throws Exception
+ */
+ @Before
+ public void before() throws Exception {
+ conf = new AccumuloRdfConfiguration();
+ conf.setTablePrefix("triplestore_");
+ String tableName = GeoMesaGeoIndexer.getTableName(conf);
+ conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
+ conf.set(ConfigUtils.CLOUDBASE_USER, "USERNAME");
+ conf.set(ConfigUtils.CLOUDBASE_PASSWORD, "PASS");
+ conf.set(ConfigUtils.CLOUDBASE_AUTHS, "U");
+
+ TableOperations tops = ConfigUtils.getConnector(conf).tableOperations();
+ // get all of the table names with the prefix
+ Set<String> toDel = Sets.newHashSet();
+ for (String t : tops.list()) {
+ if (t.startsWith(tableName)) {
+ toDel.add(t);
+ }
+ }
+ for (String t : toDel) {
+ tops.delete(t);
+ }
+
+ g = new GeoMesaGeoIndexer();
+ g.setConf(conf);
+ // Convert the statements as schema WKT or GML, then GML has two methods to encode.
+ g.storeStatement(RyaStatement(A,schemaToTest, encodeMethod));
+ g.storeStatement(RyaStatement(B,schemaToTest, encodeMethod));
+ g.storeStatement(RyaStatement(C,schemaToTest, encodeMethod));
+ g.storeStatement(RyaStatement(D,schemaToTest, encodeMethod));
+ g.storeStatement(RyaStatement(F,schemaToTest, encodeMethod));
+ g.storeStatement(RyaStatement(E,schemaToTest, encodeMethod));
+ g.storeStatement(RyaStatement(G,schemaToTest, encodeMethod));
+ }
+
+ private static RyaStatement RyaStatement(Geometry geo, URI schema, URI encodingMethod) {
+ return RdfToRyaConversions.convertStatement(genericStatement(geo,schema,encodingMethod));
+ }
+ private static Statement genericStatement(Geometry geo, URI schema, URI encodingMethod) {
+ if (schema.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) {
+ return genericStatementWkt(geo);
+ } else if (schema.equals(GeoConstants.XMLSCHEMA_OGC_GML)) {
+ return genericStatementGml(geo, encodingMethod);
+ }
+ throw new Error("schema unsupported: "+schema);
+ }
+ private static Statement genericStatementWkt(Geometry geo) {
+ ValueFactory vf = new ValueFactoryImpl();
+ Resource subject = vf.createURI("uri:" + names.get(geo));
+ URI predicate = GeoConstants.GEO_AS_WKT;
+ Value object = vf.createLiteral(geo.toString(), GeoConstants.XMLSCHEMA_OGC_WKT);
+ return new StatementImpl(subject, predicate, object);
+ }
+
+ private static Statement genericStatementGml(Geometry geo, URI encodingMethod) {
+ ValueFactory vf = new ValueFactoryImpl();
+ Resource subject = vf.createURI("uri:" + names.get(geo));
+ URI predicate = GeoConstants.GEO_AS_GML;
+
+ final String gml ;
+ if (encodingMethod==useJtsLibEncoding)
+ gml = geoToGmlUseJtsLib(geo);
+ else if (encodingMethod==useRoughEncoding)
+ gml = geoToGmlRough(geo);
+ else
+ throw new Error("invalid encoding method: "+encodingMethod);
+ // System.out.println("===created GML====");
+ // System.out.println(gml);
+ // System.out.println("========== GML====");
+
+ Value object = vf.createLiteral(gml, GeoConstants.XMLSCHEMA_OGC_GML);
+ return new StatementImpl(subject, predicate, object);
+ }
+
+ /**
+ * JTS library conversion from geometry to GML.
+ * @param geo base Geometry gets delegated
+ * @return String gml encoding of the geomoetry
+ */
+ private static String geoToGmlUseJtsLib(Geometry geo) {
+ int srid = geo.getSRID();
+ GMLWriter gmlWriter = new GMLWriter();
+ gmlWriter.setNamespace(false);
+ gmlWriter.setPrefix(null);
+
+ if (srid != -1 || srid != 0) {
+ gmlWriter.setSrsName("EPSG:" + geo.getSRID());
+ }
+ String gml = gmlWriter.write(geo);
+ // Hack to replace a gml 2.0 deprecated element in the Polygon.
+ // It should tolerate this as it does other depreciated elements like <gml:coordinates>.
+ return gml.replace("outerBoundaryIs", "exterior");
+ }
+
+ /**
+ * Rough conversion from geometry to GML using a template.
+ * @param geo base Geometry gets delegated
+ * @return String gml encoding of the gemoetry
+ */
+ private static String geoToGmlRough(Geometry geo) {
+ final Geometries theType = org.geotools.geometry.jts.Geometries.get(geo);
+ switch (theType) {
+ case POINT:
+ return geoToGml((Point)geo);
+ case LINESTRING:
+ return geoToGml((LineString)geo);
+ case POLYGON:
+ return geoToGml((Polygon)geo);
+ case MULTIPOINT:
+ case MULTILINESTRING:
+ case MULTIPOLYGON:
+ default:
+ throw new Error("No code to convert to GML for this type: "+theType);
+ }
+ }
+
+ private static Point point(double x, double y) {
+ return gf.createPoint(new Coordinate(x, y));
+ }
+
+ private static String geoToGml(Point point) {
+ //CRS:84 long X,lat Y
+ //ESPG:4326 lat Y,long X
+ return "<Point"//
+ + " srsName='CRS:84'"// TODO: point.getSRID()
+ + "><pos>"+point.getX()+" "+point.getY()+"</pos> "// assumes Y=lat X=long
+ + " </Point>";
+ }
+
+ private static LineString line(double x1, double y1, double x2, double y2) {
+ return new LineString(new PackedCoordinateSequence.Double(new double[] { x1, y1, x2, y2 }, 2), gf);
+ }
+ /**
+ * convert a lineString geometry to GML
+ * @param line
+ * @return String that is XML that is a GMLLiteral of line
+ */
+ private static String geoToGml(LineString line) {
+ StringBuilder coordString = new StringBuilder() ;
+ for (Coordinate coor : line.getCoordinates()) {
+ coordString.append(" ").append(coor.x).append(" ").append(coor.y); //ESPG:4326 lat/long
+ }
+ return " <gml:LineString srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\" xmlns:gml='http://www.opengis.net/gml'>\n"
+ + "<gml:posList srsDimension=\"2\">"//
+ + coordString //
+ + "</gml:posList></gml:LineString >";
+ }
+
+ private static Polygon poly(double[] arr) {
+ LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(arr, 2));
+ Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
+ return p1;
+ }
+ /**
+ * convert a Polygon geometry to GML
+ * @param geometry
+ * @return String that is XML that is a GMLLiteral of line
+ */
+ private static String geoToGml(Polygon poly) {
+ StringBuilder coordString = new StringBuilder() ;
+ for (Coordinate coor : poly.getCoordinates()) {
+ coordString.append(" ").append(coor.x).append(" ").append(coor.y); //ESPG:4326 lat/long
+ //with commas: coordString.append(" ").append(coor.x).append(",").append(coor.y);
+ }
+ return "<gml:Polygon srsName=\"EPSG:4326\" xmlns:gml='http://www.opengis.net/gml'>\r\n"//
+ + "<gml:exterior><gml:LinearRing>\r\n"//
+ + "<gml:posList srsDimension='2'>\r\n"
+ + coordString
+ + "</gml:posList>\r\n"//
+ + "</gml:LinearRing></gml:exterior>\r\n</gml:Polygon>\r\n";
+ }
+
+ private static double[] bbox(double x1, double y1, double x2, double y2) {
+ return new double[] { x1, y1, x1, y2, x2, y2, x2, y1, x1, y1 };
+ }
+
+ public void compare(CloseableIteration<Statement, ?> actual, Geometry... expected) throws Exception {
+ Set<Statement> expectedSet = Sets.newHashSet();
+ for (Geometry geo : expected) {
+ expectedSet.add(RyaToRdfConversions.convertStatement(RyaStatement(geo,this.schemaToTest, encodeMethod)));
+ }
+
+ Assert.assertEquals(expectedSet, getSet(actual));
+ }
+
+ private static <X> Set<X> getSet(CloseableIteration<X, ?> iter) throws Exception {
+ Set<X> set = new HashSet<X>();
+ while (iter.hasNext()) {
+ set.add(iter.next());
+ }
+ return set;
+ }
+
+ private static Geometry[] EMPTY_RESULTS = {};
+
+ @Test
+ public void testParsePoly() throws Exception {
+ assertParseable(D);
+ }
+
+ @Test
+ public void testParseLine() throws Exception {
+ assertParseable(E);
+ }
+
+ @Test
+ public void testParsePoint() throws Exception {
+ assertParseable(F);
+ }
+
+ /**
+ * Convert Geometry to Wkt|GML (schemaToTest), parse to Geometry, and compare to original.
+ * @throws ParseException
+ */
+ public void assertParseable(Geometry originalGeom) throws ParseException {
+ Geometry parsedGeom = GeoParseUtils.getGeometry(genericStatement(originalGeom,schemaToTest, encodeMethod));
+ assertTrue("Parsed should equal original: "+originalGeom+" parsed: "+parsedGeom, originalGeom.equalsNorm(parsedGeom));
+ // assertEquals( originalGeom, parsedGeom ); //also passes
+ // assertTrue( originalGeom.equalsExact(parsedGeom) ); //also passes
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ // point
+ compare(g.queryEquals(F, EMPTY_CONSTRAINTS), F);
+ compare(g.queryEquals(point(-1, -1), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+
+ // line
+ compare(g.queryEquals(E, EMPTY_CONSTRAINTS), E);
+ compare(g.queryEquals(line(-1, -1, 0, 0), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+
+ // poly
+ compare(g.queryEquals(A, EMPTY_CONSTRAINTS), A);
+ compare(g.queryEquals(poly(bbox(-2, -2, 1, 2)), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+
+ }
+
+ @Test
+ public void testDisjoint() throws Exception {
+ // point
+ compare(g.queryDisjoint(F, EMPTY_CONSTRAINTS), B, C, D, E, G);
+
+ // line
+ compare(g.queryDisjoint(E, EMPTY_CONSTRAINTS), B, C, F, G);
+
+ // poly
+ compare(g.queryDisjoint(A, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ compare(g.queryDisjoint(B, EMPTY_CONSTRAINTS), C, D, F, E, G);
+ }
+
+ @Test
+ @Ignore
+ public void testIntersectsPoint() throws Exception {
+ // This seems like a bug
+ // scala.MatchError: POINT (2 4) (of class com.vividsolutions.jts.geom.Point)
+ // at org.locationtech.geomesa.filter.FilterHelper$.updateToIDLSafeFilter(FilterHelper.scala:53)
+ // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), A, F);
+ // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ }
+
+ @Ignore
+ @Test
+ public void testIntersectsLine() throws Exception {
+ // This seems like a bug
+ // fails with:
+ // scala.MatchError: LINESTRING (2 0, 3 3) (of class com.vividsolutions.jts.geom.LineString)
+ // at org.locationtech.geomesa.filter.FilterHelper$.updateToIDLSafeFilter(FilterHelper.scala:53)
+ //compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), A, E, D);
+ //compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ }
+
+ @Test
+ public void testIntersectsPoly() throws Exception {
+ compare(g.queryIntersects(A, EMPTY_CONSTRAINTS), A, B, C, D, F, E, G);
+ }
+
+ @Test
+ public void testTouchesPoint() throws Exception {
+ compare(g.queryTouches(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ compare(g.queryTouches(G, EMPTY_CONSTRAINTS), A, C);
+ }
+
+ @Test
+ public void testTouchesLine() throws Exception {
+ compare(g.queryTouches(E, EMPTY_CONSTRAINTS), D);
+ }
+
+ @Test
+ public void testTouchesPoly() throws Exception {
+ compare(g.queryTouches(A, EMPTY_CONSTRAINTS), C,G);
+ }
+
+ @Test
+ public void testCrossesPoint() throws Exception {
+ compare(g.queryCrosses(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ compare(g.queryCrosses(G, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ // bug? java.lang.IllegalStateException: getX called on empty Point
+ // compare(g.queryCrosses(point(2, 0), EMPTY_CONSTRAINTS), E);
+ }
+
+ @Ignore
+ @Test
+ public void testCrossesLine() throws Exception {
+ // fails with:
+ // java.lang.IllegalStateException: getX called on empty Point
+ // at com.vividsolutions.jts.geom.Point.getX(Point.java:124)
+ // at org.locationtech.geomesa.utils.geohash.GeohashUtils$.considerCandidate$1(GeohashUtils.scala:1023)
+
+ // compare(g.queryCrosses(E, EMPTY_CONSTRAINTS), A);
+ }
+
+ @Test
+ public void testCrossesPoly() throws Exception {
+ compare(g.queryCrosses(A, EMPTY_CONSTRAINTS), E);
+ compare(g.queryCrosses(poly(bbox(-0.9, -2.9, -0.1, -1.1)), EMPTY_CONSTRAINTS), E);
+ }
+
+ @Test
+ public void testWithin() throws Exception {
+ // point
+ // geomesa bug? scala.MatchError: POINT (2 4) (of class com.vividsolutions.jts.geom.Point)
+ // compare(g.queryWithin(F, EMPTY_CONSTRAINTS), F);
+
+ // line
+ // geomesa bug? scala.MatchError: LINESTRING (2 0, 3 2) (of class com.vividsolutions.jts.geom.LineString)
+ // compare(g.queryWithin(E, EMPTY_CONSTRAINTS), E);
+
+ // poly
+ compare(g.queryWithin(A, EMPTY_CONSTRAINTS), A, B, F);
+ }
+
+ @Test
+ public void testContainsPoint() throws Exception {
+ compare(g.queryContains(F, EMPTY_CONSTRAINTS), A, F);
+ }
+
+ @Ignore
+ @Test
+ public void testContainsLine() throws Exception {
+ // compare(g.queryContains(E, EMPTY_CONSTRAINTS), E);
+ }
+
+ @Test
+ public void testContainsPoly() throws Exception {
+ compare(g.queryContains(A, EMPTY_CONSTRAINTS), A);
+ compare(g.queryContains(B, EMPTY_CONSTRAINTS), A, B);
+ }
+
+ @Ignore
+ @Test
+ public void testOverlapsPoint() throws Exception {
+ // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), F);
+ // You cannot have overlapping points
+ // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ }
+
+ @Ignore
+ @Test
+ public void testOverlapsLine() throws Exception {
+ // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), A, E);
+ // You cannot have overlapping lines
+ // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
+ }
+
+ @Test
+ public void testOverlapsPoly() throws Exception {
+ compare(g.queryOverlaps(A, EMPTY_CONSTRAINTS), D);
+ }
+
+}
[4/6] incubator-rya git commit: RYA-177 adding optional geoindexing
profile
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoTupleSet.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoTupleSet.java b/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoTupleSet.java
deleted file mode 100644
index 3ab9037..0000000
--- a/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoTupleSet.java
+++ /dev/null
@@ -1,361 +0,0 @@
-package mvm.rya.indexing.mongodb.geo;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import info.aduna.iteration.CloseableIteration;
-
-import java.util.Map;
-import java.util.Set;
-
-import mvm.rya.indexing.GeoIndexer;
-import mvm.rya.indexing.IndexingExpr;
-import mvm.rya.indexing.IteratorFactory;
-import mvm.rya.indexing.SearchFunction;
-import mvm.rya.indexing.StatementConstraints;
-import mvm.rya.indexing.accumulo.geo.GeoConstants;
-import mvm.rya.indexing.accumulo.geo.GeoTupleSet;
-import mvm.rya.indexing.external.tupleSet.ExternalTupleSet;
-
-import org.apache.hadoop.conf.Configuration;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.query.BindingSet;
-import org.openrdf.query.QueryEvaluationException;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.Maps;
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.io.ParseException;
-import com.vividsolutions.jts.io.WKTReader;
-
-public class MongoGeoTupleSet extends ExternalTupleSet {
-
- private Configuration conf;
- private GeoIndexer geoIndexer;
- private IndexingExpr filterInfo;
-
-
- public MongoGeoTupleSet(IndexingExpr filterInfo, GeoIndexer geoIndexer) {
- this.filterInfo = filterInfo;
- this.geoIndexer = geoIndexer;
- this.conf = geoIndexer.getConf();
- }
-
- @Override
- public Set<String> getBindingNames() {
- return filterInfo.getBindingNames();
- }
-
- public GeoTupleSet clone() {
- return new GeoTupleSet(filterInfo, geoIndexer);
- }
-
- @Override
- public double cardinality() {
- return 0.0; // No idea how the estimate cardinality here.
- }
-
-
- @Override
- public String getSignature() {
- return "(GeoTuple Projection) " + "variables: " + Joiner.on(", ").join(this.getBindingNames()).replaceAll("\\s+", " ");
- }
-
-
-
- @Override
- public boolean equals(Object other) {
- if (other == this) {
- return true;
- }
- if (!(other instanceof MongoGeoTupleSet)) {
- return false;
- }
- MongoGeoTupleSet arg = (MongoGeoTupleSet) other;
- return this.filterInfo.equals(arg.filterInfo);
- }
-
- @Override
- public int hashCode() {
- int result = 17;
- result = 31*result + filterInfo.hashCode();
-
- return result;
- }
-
-
-
- /**
- * Returns an iterator over the result set of the contained IndexingExpr.
- * <p>
- * Should be thread-safe (concurrent invocation {@link OfflineIterable} this
- * method can be expected with some query evaluators.
- */
- @Override
- public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSet bindings)
- throws QueryEvaluationException {
-
-
- URI funcURI = filterInfo.getFunction();
- SearchFunction searchFunction = (new MongoGeoSearchFunctionFactory(conf)).getSearchFunction(funcURI);
- if(filterInfo.getArguments().length > 1) {
- throw new IllegalArgumentException("Index functions do not support more than two arguments.");
- }
-
- String queryText = filterInfo.getArguments()[0].stringValue();
-
- return IteratorFactory.getIterator(filterInfo.getSpConstraint(), bindings, queryText, searchFunction);
- }
-
-
-
- //returns appropriate search function for a given URI
- //search functions used in GeoMesaGeoIndexer to access index
- public class MongoGeoSearchFunctionFactory {
-
- Configuration conf;
-
- private final Map<URI, SearchFunction> SEARCH_FUNCTION_MAP = Maps.newHashMap();
-
- public MongoGeoSearchFunctionFactory(Configuration conf) {
- this.conf = conf;
- }
-
-
- /**
- * Get a {@link GeoSearchFunction} for a given URI.
- *
- * @param searchFunction
- * @return
- */
- public SearchFunction getSearchFunction(final URI searchFunction) {
-
- SearchFunction geoFunc = null;
-
- try {
- geoFunc = getSearchFunctionInternal(searchFunction);
- } catch (QueryEvaluationException e) {
- e.printStackTrace();
- }
-
- return geoFunc;
- }
-
- private SearchFunction getSearchFunctionInternal(final URI searchFunction) throws QueryEvaluationException {
- SearchFunction sf = SEARCH_FUNCTION_MAP.get(searchFunction);
-
- if (sf != null) {
- return sf;
- } else {
- throw new QueryEvaluationException("Unknown Search Function: " + searchFunction.stringValue());
- }
- }
-
- private final SearchFunction GEO_EQUALS = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
- StatementConstraints contraints) throws QueryEvaluationException {
- try {
- WKTReader reader = new WKTReader();
- Geometry geometry = reader.read(queryText);
- CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_EQUALS";
- };
- };
-
- private final SearchFunction GEO_DISJOINT = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
- StatementConstraints contraints) throws QueryEvaluationException {
- try {
- WKTReader reader = new WKTReader();
- Geometry geometry = reader.read(queryText);
- CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_DISJOINT";
- };
- };
-
- private final SearchFunction GEO_INTERSECTS = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
- StatementConstraints contraints) throws QueryEvaluationException {
- try {
- WKTReader reader = new WKTReader();
- Geometry geometry = reader.read(queryText);
- CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_INTERSECTS";
- };
- };
-
- private final SearchFunction GEO_TOUCHES = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
- StatementConstraints contraints) throws QueryEvaluationException {
- try {
- WKTReader reader = new WKTReader();
- Geometry geometry = reader.read(queryText);
- CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_TOUCHES";
- };
- };
-
- private final SearchFunction GEO_CONTAINS = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
- StatementConstraints contraints) throws QueryEvaluationException {
- try {
- WKTReader reader = new WKTReader();
- Geometry geometry = reader.read(queryText);
- CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_CONTAINS";
- };
- };
-
- private final SearchFunction GEO_OVERLAPS = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
- StatementConstraints contraints) throws QueryEvaluationException {
- try {
- WKTReader reader = new WKTReader();
- Geometry geometry = reader.read(queryText);
- CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_OVERLAPS";
- };
- };
-
- private final SearchFunction GEO_CROSSES = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
- StatementConstraints contraints) throws QueryEvaluationException {
- try {
- WKTReader reader = new WKTReader();
- Geometry geometry = reader.read(queryText);
- CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_CROSSES";
- };
- };
-
- private final SearchFunction GEO_WITHIN = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText,
- StatementConstraints contraints) throws QueryEvaluationException {
- try {
- WKTReader reader = new WKTReader();
- Geometry geometry = reader.read(queryText);
- CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_WITHIN";
- };
- };
-
- {
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_EQUALS, GEO_EQUALS);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_DISJOINT, GEO_DISJOINT);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_INTERSECTS, GEO_INTERSECTS);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_TOUCHES, GEO_TOUCHES);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_CONTAINS, GEO_CONTAINS);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_OVERLAPS, GEO_OVERLAPS);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_CROSSES, GEO_CROSSES);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_WITHIN, GEO_WITHIN);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/sail/config/RyaSailFactory.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/sail/config/RyaSailFactory.java b/extras/indexing/src/main/java/mvm/rya/sail/config/RyaSailFactory.java
index b0a719b..d3c891c 100644
--- a/extras/indexing/src/main/java/mvm/rya/sail/config/RyaSailFactory.java
+++ b/extras/indexing/src/main/java/mvm/rya/sail/config/RyaSailFactory.java
@@ -146,7 +146,7 @@ public class RyaSailFactory {
return dao;
}
- private static void updateAccumuloConfig(final AccumuloRdfConfiguration config, final String user, final String pswd, final String ryaInstance) throws AccumuloException, AccumuloSecurityException {
+ public static void updateAccumuloConfig(final AccumuloRdfConfiguration config, final String user, final String pswd, final String ryaInstance) throws AccumuloException, AccumuloSecurityException {
try {
final PasswordToken pswdToken = new PasswordToken(pswd);
final Instance accInst = ConfigUtils.getInstance(config);
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerSfTest.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerSfTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerSfTest.java
deleted file mode 100644
index 5395267..0000000
--- a/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerSfTest.java
+++ /dev/null
@@ -1,514 +0,0 @@
-package mvm.rya.indexing.accumulo.geo;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.accumulo.core.client.admin.TableOperations;
-import org.geotools.geometry.jts.Geometries;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-import org.openrdf.model.Resource;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.model.impl.StatementImpl;
-import org.openrdf.model.impl.URIImpl;
-import org.openrdf.model.impl.ValueFactoryImpl;
-
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.LineString;
-import com.vividsolutions.jts.geom.LinearRing;
-import com.vividsolutions.jts.geom.Point;
-import com.vividsolutions.jts.geom.Polygon;
-import com.vividsolutions.jts.geom.PrecisionModel;
-import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;
-import com.vividsolutions.jts.io.ParseException;
-import com.vividsolutions.jts.io.gml2.GMLWriter;
-
-import info.aduna.iteration.CloseableIteration;
-import mvm.rya.accumulo.AccumuloRdfConfiguration;
-import mvm.rya.api.domain.RyaStatement;
-import mvm.rya.api.resolver.RdfToRyaConversions;
-import mvm.rya.api.resolver.RyaToRdfConversions;
-import mvm.rya.indexing.StatementConstraints;
-import mvm.rya.indexing.accumulo.ConfigUtils;
-
-/**
- * Tests all of the "simple functions" of the geoindexer specific to GML.
- * Parameterized so that each test is run for WKT and for GML.
- */
-@RunWith(value = Parameterized.class)
-public class GeoIndexerSfTest {
- private static AccumuloRdfConfiguration conf;
- private static GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
- private static GeoMesaGeoIndexer g;
-
- private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints();
-
- // Here is the landscape:
- /**
- * <pre>
- * 2---+---+---+---+---+---+
- * | F |G |
- * 1 A o(-1,1) o C |
- * | | |
- * 0---+---+ +---+---+(3,0)
- * | | E |
- * -1 B + .---+---+
- * | | /| | |
- * -2---+---+-/-+---+ +
- * ^ / | D |
- * -3 -2 -1 0---1---2 3 4
- * </pre>
- **/
- private static final Polygon A = poly(bbox(-3, -2, 1, 2));
- private static final Polygon B = poly(bbox(-3, -2, -1, 0));
- private static final Polygon C = poly(bbox(1, 0, 3, 2));
- private static final Polygon D = poly(bbox(0, -3, 2, -1));
-
- private static final Point F = point(-1, 1);
- private static final Point G = point(1, 1);
-
- private static final LineString E = line(-1, -3, 0, -1);
-
- private static final Map<Geometry, String> names = Maps.newHashMap();
- static {
- names.put(A, "A");
- names.put(B, "B");
- names.put(C, "C");
- names.put(D, "D");
- names.put(E, "E");
- names.put(F, "F");
- names.put(G, "G");
- }
-
- /**
- * JUnit 4 parameterized iterates thru this list and calls the constructor with each.
- * For each test, Call the constructor three times, for WKT and for GML encoding 1, and GML encoding 2
- * @return
- */
- final static URI useJtsLibEncoding = new URIImpl("uri:useLib") ;
- final static URI useRoughEncoding = new URIImpl("uri:useRough") ;
-
- @Parameters
- public static Collection<URI[]> constructorData() {
- URI[][] data = new URI[][] { { GeoConstants.XMLSCHEMA_OGC_WKT,useJtsLibEncoding }, { GeoConstants.XMLSCHEMA_OGC_GML,useJtsLibEncoding } , { GeoConstants.XMLSCHEMA_OGC_GML,useRoughEncoding } };
- return Arrays.asList(data);
- }
-
- private URI schemaToTest;
- private URI encodeMethod;
- /**
- * Constructor required by JUnit parameterized runner. See data() for constructor values.
- */
- public GeoIndexerSfTest(URI schemaToTest, URI encodeMethod) {
- this.schemaToTest=schemaToTest;
- this.encodeMethod = encodeMethod;
- }
- /**
- * Run before each test method.
- * @throws Exception
- */
- @Before
- public void before() throws Exception {
- conf = new AccumuloRdfConfiguration();
- conf.setTablePrefix("triplestore_");
- String tableName = GeoMesaGeoIndexer.getTableName(conf);
- conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
- conf.set(ConfigUtils.CLOUDBASE_USER, "USERNAME");
- conf.set(ConfigUtils.CLOUDBASE_PASSWORD, "PASS");
- conf.set(ConfigUtils.CLOUDBASE_AUTHS, "U");
-
- TableOperations tops = ConfigUtils.getConnector(conf).tableOperations();
- // get all of the table names with the prefix
- Set<String> toDel = Sets.newHashSet();
- for (String t : tops.list()) {
- if (t.startsWith(tableName)) {
- toDel.add(t);
- }
- }
- for (String t : toDel) {
- tops.delete(t);
- }
-
- g = new GeoMesaGeoIndexer();
- g.setConf(conf);
- // Convert the statements as schema WKT or GML, then GML has two methods to encode.
- g.storeStatement(RyaStatement(A,schemaToTest, encodeMethod));
- g.storeStatement(RyaStatement(B,schemaToTest, encodeMethod));
- g.storeStatement(RyaStatement(C,schemaToTest, encodeMethod));
- g.storeStatement(RyaStatement(D,schemaToTest, encodeMethod));
- g.storeStatement(RyaStatement(F,schemaToTest, encodeMethod));
- g.storeStatement(RyaStatement(E,schemaToTest, encodeMethod));
- g.storeStatement(RyaStatement(G,schemaToTest, encodeMethod));
- }
-
- private static RyaStatement RyaStatement(Geometry geo, URI schema, URI encodingMethod) {
- return RdfToRyaConversions.convertStatement(genericStatement(geo,schema,encodingMethod));
- }
- private static Statement genericStatement(Geometry geo, URI schema, URI encodingMethod) {
- if (schema.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) {
- return genericStatementWkt(geo);
- } else if (schema.equals(GeoConstants.XMLSCHEMA_OGC_GML)) {
- return genericStatementGml(geo, encodingMethod);
- }
- throw new Error("schema unsupported: "+schema);
- }
- private static Statement genericStatementWkt(Geometry geo) {
- ValueFactory vf = new ValueFactoryImpl();
- Resource subject = vf.createURI("uri:" + names.get(geo));
- URI predicate = GeoConstants.GEO_AS_WKT;
- Value object = vf.createLiteral(geo.toString(), GeoConstants.XMLSCHEMA_OGC_WKT);
- return new StatementImpl(subject, predicate, object);
- }
-
- private static Statement genericStatementGml(Geometry geo, URI encodingMethod) {
- ValueFactory vf = new ValueFactoryImpl();
- Resource subject = vf.createURI("uri:" + names.get(geo));
- URI predicate = GeoConstants.GEO_AS_GML;
-
- final String gml ;
- if (encodingMethod==useJtsLibEncoding)
- gml = geoToGmlUseJtsLib(geo);
- else if (encodingMethod==useRoughEncoding)
- gml = geoToGmlRough(geo);
- else
- throw new Error("invalid encoding method: "+encodingMethod);
- // System.out.println("===created GML====");
- // System.out.println(gml);
- // System.out.println("========== GML====");
-
- Value object = vf.createLiteral(gml, GeoConstants.XMLSCHEMA_OGC_GML);
- return new StatementImpl(subject, predicate, object);
- }
-
- /**
- * JTS library conversion from geometry to GML.
- * @param geo base Geometry gets delegated
- * @return String gml encoding of the geomoetry
- */
- private static String geoToGmlUseJtsLib(Geometry geo) {
- int srid = geo.getSRID();
- GMLWriter gmlWriter = new GMLWriter();
- gmlWriter.setNamespace(false);
- gmlWriter.setPrefix(null);
-
- if (srid != -1 || srid != 0) {
- gmlWriter.setSrsName("EPSG:" + geo.getSRID());
- }
- String gml = gmlWriter.write(geo);
- // Hack to replace a gml 2.0 deprecated element in the Polygon.
- // It should tolerate this as it does other depreciated elements like <gml:coordinates>.
- return gml.replace("outerBoundaryIs", "exterior");
- }
-
- /**
- * Rough conversion from geometry to GML using a template.
- * @param geo base Geometry gets delegated
- * @return String gml encoding of the gemoetry
- */
- private static String geoToGmlRough(Geometry geo) {
- final Geometries theType = org.geotools.geometry.jts.Geometries.get(geo);
- switch (theType) {
- case POINT:
- return geoToGml((Point)geo);
- case LINESTRING:
- return geoToGml((LineString)geo);
- case POLYGON:
- return geoToGml((Polygon)geo);
- case MULTIPOINT:
- case MULTILINESTRING:
- case MULTIPOLYGON:
- default:
- throw new Error("No code to convert to GML for this type: "+theType);
- }
- }
-
- private static Point point(double x, double y) {
- return gf.createPoint(new Coordinate(x, y));
- }
-
- private static String geoToGml(Point point) {
- //CRS:84 long X,lat Y
- //ESPG:4326 lat Y,long X
- return "<Point"//
- + " srsName='CRS:84'"// TODO: point.getSRID()
- + "><pos>"+point.getX()+" "+point.getY()+"</pos> "// assumes Y=lat X=long
- + " </Point>";
- }
-
- private static LineString line(double x1, double y1, double x2, double y2) {
- return new LineString(new PackedCoordinateSequence.Double(new double[] { x1, y1, x2, y2 }, 2), gf);
- }
- /**
- * convert a lineString geometry to GML
- * @param line
- * @return String that is XML that is a GMLLiteral of line
- */
- private static String geoToGml(LineString line) {
- StringBuilder coordString = new StringBuilder() ;
- for (Coordinate coor : line.getCoordinates()) {
- coordString.append(" ").append(coor.x).append(" ").append(coor.y); //ESPG:4326 lat/long
- }
- return " <gml:LineString srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\" xmlns:gml='http://www.opengis.net/gml'>\n"
- + "<gml:posList srsDimension=\"2\">"//
- + coordString //
- + "</gml:posList></gml:LineString >";
- }
-
- private static Polygon poly(double[] arr) {
- LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(arr, 2));
- Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
- return p1;
- }
- /**
- * convert a Polygon geometry to GML
- * @param geometry
- * @return String that is XML that is a GMLLiteral of line
- */
- private static String geoToGml(Polygon poly) {
- StringBuilder coordString = new StringBuilder() ;
- for (Coordinate coor : poly.getCoordinates()) {
- coordString.append(" ").append(coor.x).append(" ").append(coor.y); //ESPG:4326 lat/long
- //with commas: coordString.append(" ").append(coor.x).append(",").append(coor.y);
- }
- return "<gml:Polygon srsName=\"EPSG:4326\" xmlns:gml='http://www.opengis.net/gml'>\r\n"//
- + "<gml:exterior><gml:LinearRing>\r\n"//
- + "<gml:posList srsDimension='2'>\r\n"
- + coordString
- + "</gml:posList>\r\n"//
- + "</gml:LinearRing></gml:exterior>\r\n</gml:Polygon>\r\n";
- }
-
- private static double[] bbox(double x1, double y1, double x2, double y2) {
- return new double[] { x1, y1, x1, y2, x2, y2, x2, y1, x1, y1 };
- }
-
- public void compare(CloseableIteration<Statement, ?> actual, Geometry... expected) throws Exception {
- Set<Statement> expectedSet = Sets.newHashSet();
- for (Geometry geo : expected) {
- expectedSet.add(RyaToRdfConversions.convertStatement(RyaStatement(geo,this.schemaToTest, encodeMethod)));
- }
-
- Assert.assertEquals(expectedSet, getSet(actual));
- }
-
- private static <X> Set<X> getSet(CloseableIteration<X, ?> iter) throws Exception {
- Set<X> set = new HashSet<X>();
- while (iter.hasNext()) {
- set.add(iter.next());
- }
- return set;
- }
-
- private static Geometry[] EMPTY_RESULTS = {};
-
- @Test
- public void testParsePoly() throws Exception {
- assertParseable(D);
- }
-
- @Test
- public void testParseLine() throws Exception {
- assertParseable(E);
- }
-
- @Test
- public void testParsePoint() throws Exception {
- assertParseable(F);
- }
-
- /**
- * Convert Geometry to Wkt|GML (schemaToTest), parse to Geometry, and compare to original.
- * @throws ParseException
- */
- public void assertParseable(Geometry originalGeom) throws ParseException {
- Geometry parsedGeom = GeoParseUtils.getGeometry(genericStatement(originalGeom,schemaToTest, encodeMethod));
- assertTrue("Parsed should equal original: "+originalGeom+" parsed: "+parsedGeom, originalGeom.equalsNorm(parsedGeom));
- // assertEquals( originalGeom, parsedGeom ); //also passes
- // assertTrue( originalGeom.equalsExact(parsedGeom) ); //also passes
- }
-
- @Test
- public void testEquals() throws Exception {
- // point
- compare(g.queryEquals(F, EMPTY_CONSTRAINTS), F);
- compare(g.queryEquals(point(-1, -1), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-
- // line
- compare(g.queryEquals(E, EMPTY_CONSTRAINTS), E);
- compare(g.queryEquals(line(-1, -1, 0, 0), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-
- // poly
- compare(g.queryEquals(A, EMPTY_CONSTRAINTS), A);
- compare(g.queryEquals(poly(bbox(-2, -2, 1, 2)), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-
- }
-
- @Test
- public void testDisjoint() throws Exception {
- // point
- compare(g.queryDisjoint(F, EMPTY_CONSTRAINTS), B, C, D, E, G);
-
- // line
- compare(g.queryDisjoint(E, EMPTY_CONSTRAINTS), B, C, F, G);
-
- // poly
- compare(g.queryDisjoint(A, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- compare(g.queryDisjoint(B, EMPTY_CONSTRAINTS), C, D, F, E, G);
- }
-
- @Test
- @Ignore
- public void testIntersectsPoint() throws Exception {
- // This seems like a bug
- // scala.MatchError: POINT (2 4) (of class com.vividsolutions.jts.geom.Point)
- // at org.locationtech.geomesa.filter.FilterHelper$.updateToIDLSafeFilter(FilterHelper.scala:53)
- // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), A, F);
- // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
-
- @Ignore
- @Test
- public void testIntersectsLine() throws Exception {
- // This seems like a bug
- // fails with:
- // scala.MatchError: LINESTRING (2 0, 3 3) (of class com.vividsolutions.jts.geom.LineString)
- // at org.locationtech.geomesa.filter.FilterHelper$.updateToIDLSafeFilter(FilterHelper.scala:53)
- //compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), A, E, D);
- //compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
-
- @Test
- public void testIntersectsPoly() throws Exception {
- compare(g.queryIntersects(A, EMPTY_CONSTRAINTS), A, B, C, D, F, E, G);
- }
-
- @Test
- public void testTouchesPoint() throws Exception {
- compare(g.queryTouches(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- compare(g.queryTouches(G, EMPTY_CONSTRAINTS), A, C);
- }
-
- @Test
- public void testTouchesLine() throws Exception {
- compare(g.queryTouches(E, EMPTY_CONSTRAINTS), D);
- }
-
- @Test
- public void testTouchesPoly() throws Exception {
- compare(g.queryTouches(A, EMPTY_CONSTRAINTS), C,G);
- }
-
- @Test
- public void testCrossesPoint() throws Exception {
- compare(g.queryCrosses(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- compare(g.queryCrosses(G, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- // bug? java.lang.IllegalStateException: getX called on empty Point
- // compare(g.queryCrosses(point(2, 0), EMPTY_CONSTRAINTS), E);
- }
-
- @Ignore
- @Test
- public void testCrossesLine() throws Exception {
- // fails with:
- // java.lang.IllegalStateException: getX called on empty Point
- // at com.vividsolutions.jts.geom.Point.getX(Point.java:124)
- // at org.locationtech.geomesa.utils.geohash.GeohashUtils$.considerCandidate$1(GeohashUtils.scala:1023)
-
- // compare(g.queryCrosses(E, EMPTY_CONSTRAINTS), A);
- }
-
- @Test
- public void testCrossesPoly() throws Exception {
- compare(g.queryCrosses(A, EMPTY_CONSTRAINTS), E);
- compare(g.queryCrosses(poly(bbox(-0.9, -2.9, -0.1, -1.1)), EMPTY_CONSTRAINTS), E);
- }
-
- @Test
- public void testWithin() throws Exception {
- // point
- // geomesa bug? scala.MatchError: POINT (2 4) (of class com.vividsolutions.jts.geom.Point)
- // compare(g.queryWithin(F, EMPTY_CONSTRAINTS), F);
-
- // line
- // geomesa bug? scala.MatchError: LINESTRING (2 0, 3 2) (of class com.vividsolutions.jts.geom.LineString)
- // compare(g.queryWithin(E, EMPTY_CONSTRAINTS), E);
-
- // poly
- compare(g.queryWithin(A, EMPTY_CONSTRAINTS), A, B, F);
- }
-
- @Test
- public void testContainsPoint() throws Exception {
- compare(g.queryContains(F, EMPTY_CONSTRAINTS), A, F);
- }
-
- @Ignore
- @Test
- public void testContainsLine() throws Exception {
- // compare(g.queryContains(E, EMPTY_CONSTRAINTS), E);
- }
-
- @Test
- public void testContainsPoly() throws Exception {
- compare(g.queryContains(A, EMPTY_CONSTRAINTS), A);
- compare(g.queryContains(B, EMPTY_CONSTRAINTS), A, B);
- }
-
- @Ignore
- @Test
- public void testOverlapsPoint() throws Exception {
- // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), F);
- // You cannot have overlapping points
- // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
-
- @Ignore
- @Test
- public void testOverlapsLine() throws Exception {
- // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), A, E);
- // You cannot have overlapping lines
- // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
-
- @Test
- public void testOverlapsPoly() throws Exception {
- compare(g.queryOverlaps(A, EMPTY_CONSTRAINTS), D);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java
deleted file mode 100644
index 1e95db7..0000000
--- a/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java
+++ /dev/null
@@ -1,400 +0,0 @@
-package mvm.rya.indexing.accumulo.geo;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static mvm.rya.api.resolver.RdfToRyaConversions.convertStatement;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import org.apache.accumulo.core.client.admin.TableOperations;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.openrdf.model.Resource;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.model.impl.ContextStatementImpl;
-import org.openrdf.model.impl.StatementImpl;
-import org.openrdf.model.impl.ValueFactoryImpl;
-
-import com.google.common.collect.Sets;
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.LinearRing;
-import com.vividsolutions.jts.geom.Point;
-import com.vividsolutions.jts.geom.Polygon;
-import com.vividsolutions.jts.geom.PrecisionModel;
-import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;
-
-import info.aduna.iteration.CloseableIteration;
-import mvm.rya.accumulo.AccumuloRdfConfiguration;
-import mvm.rya.api.RdfCloudTripleStoreConfiguration;
-import mvm.rya.indexing.StatementConstraints;
-import mvm.rya.indexing.accumulo.ConfigUtils;
-
-/**
- * Tests higher level functioning of the geoindexer parse WKT, predicate list,
- * prime and anti meridian, delete, search, context, search with Statement Constraints.
- */
-public class GeoIndexerTest {
-
- private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints();
-
- private AccumuloRdfConfiguration conf;
- GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
-
- @Before
- public void before() throws Exception {
- conf = new AccumuloRdfConfiguration();
- conf.setTablePrefix("triplestore_");
- String tableName = GeoMesaGeoIndexer.getTableName(conf);
- conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
- conf.set(ConfigUtils.CLOUDBASE_USER, "USERNAME");
- conf.set(ConfigUtils.CLOUDBASE_PASSWORD, "PASS");
- conf.set(ConfigUtils.CLOUDBASE_AUTHS, "U");
-
- TableOperations tops = ConfigUtils.getConnector(conf).tableOperations();
- // get all of the table names with the prefix
- Set<String> toDel = Sets.newHashSet();
- for (String t : tops.list()){
- if (t.startsWith(tableName)){
- toDel.add(t);
- }
- }
- for (String t : toDel) {
- tops.delete(t);
- }
- }
-
- @Test
- public void testRestrictPredicatesSearch() throws Exception {
- conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2");
- try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
- f.setConf(conf);
-
- ValueFactory vf = new ValueFactoryImpl();
-
- Point point = gf.createPoint(new Coordinate(10, 10));
- Value pointValue = vf.createLiteral("Point(10 10)", GeoConstants.XMLSCHEMA_OGC_WKT);
- URI invalidPredicate = GeoConstants.GEO_AS_WKT;
-
- // These should not be stored because they are not in the predicate list
- f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj1"), invalidPredicate, pointValue)));
- f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), invalidPredicate, pointValue)));
-
- URI pred1 = vf.createURI("pred:1");
- URI pred2 = vf.createURI("pred:2");
-
- // These should be stored because they are in the predicate list
- Statement s3 = new StatementImpl(vf.createURI("foo:subj3"), pred1, pointValue);
- Statement s4 = new StatementImpl(vf.createURI("foo:subj4"), pred2, pointValue);
- f.storeStatement(convertStatement(s3));
- f.storeStatement(convertStatement(s4));
-
- // This should not be stored because the object is not valid wkt
- f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj5"), pred1, vf.createLiteral("soint(10 10)"))));
-
- // This should not be stored because the object is not a literal
- f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj6"), pred1, vf.createURI("p:Point(10 10)"))));
-
- f.flush();
-
- Set<Statement> actual = getSet(f.queryEquals(point, EMPTY_CONSTRAINTS));
- Assert.assertEquals(2, actual.size());
- Assert.assertTrue(actual.contains(s3));
- Assert.assertTrue(actual.contains(s4));
- }
- }
-
- private static <X> Set<X> getSet(CloseableIteration<X, ?> iter) throws Exception {
- Set<X> set = new HashSet<X>();
- while (iter.hasNext()) {
- set.add(iter.next());
- }
- return set;
- }
-
- @Test
- public void testPrimeMeridianSearch() throws Exception {
- try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
- f.setConf(conf);
-
- ValueFactory vf = new ValueFactoryImpl();
- Resource subject = vf.createURI("foo:subj");
- URI predicate = GeoConstants.GEO_AS_WKT;
- Value object = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
- Resource context = vf.createURI("foo:context");
-
- Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- double[] ONE = { 1, 1, -1, 1, -1, -1, 1, -1, 1, 1 };
- double[] TWO = { 2, 2, -2, 2, -2, -2, 2, -2, 2, 2 };
- double[] THREE = { 3, 3, -3, 3, -3, -3, 3, -3, 3, 3 };
-
- LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
- LinearRing r2 = gf.createLinearRing(new PackedCoordinateSequence.Double(TWO, 2));
- LinearRing r3 = gf.createLinearRing(new PackedCoordinateSequence.Double(THREE, 2));
-
- Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
- Polygon p2 = gf.createPolygon(r2, new LinearRing[] {});
- Polygon p3 = gf.createPolygon(r3, new LinearRing[] {});
-
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS)));
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS)));
-
- // Test a ring with a hole in it
- Polygon p3m2 = gf.createPolygon(r3, new LinearRing[] { r2 });
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS)));
-
- // test a ring outside the point
- double[] OUT = { 3, 3, 1, 3, 1, 1, 3, 1, 3, 3 };
- LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
- Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
- }
- }
-
- @Test
- public void testDcSearch() throws Exception {
- // test a ring around dc
- try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
- f.setConf(conf);
-
- ValueFactory vf = new ValueFactoryImpl();
- Resource subject = vf.createURI("foo:subj");
- URI predicate = GeoConstants.GEO_AS_WKT;
- Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- Resource context = vf.createURI("foo:context");
-
- Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
- Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
-
- // test a ring outside the point
- double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
- LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
- Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
- }
- }
-
- @Test
- public void testDeleteSearch() throws Exception {
- // test a ring around dc
- try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
- f.setConf(conf);
-
- ValueFactory vf = new ValueFactoryImpl();
- Resource subject = vf.createURI("foo:subj");
- URI predicate = GeoConstants.GEO_AS_WKT;
- Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- Resource context = vf.createURI("foo:context");
-
- Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- f.deleteStatement(convertStatement(statement));
-
- // test a ring that the point would be inside of if not deleted
- double[] in = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(in, 2));
- Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
-
- // test a ring that the point would be outside of if not deleted
- double[] out = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
- LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(out, 2));
- Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
-
- // test a ring for the whole world and make sure the point is gone
- // Geomesa is a little sensitive around lon 180, so we only go to 179
- double[] world = { -180, 90, 179, 90, 179, -90, -180, -90, -180, 90 };
- LinearRing rWorld = gf.createLinearRing(new PackedCoordinateSequence.Double(world, 2));
- Polygon pWorld = gf.createPolygon(rWorld, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS)));
- }
- }
-
- @Test
- public void testDcSearchWithContext() throws Exception {
- // test a ring around dc
- try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
- f.setConf(conf);
-
- ValueFactory vf = new ValueFactoryImpl();
- Resource subject = vf.createURI("foo:subj");
- URI predicate = GeoConstants.GEO_AS_WKT;
- Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- Resource context = vf.createURI("foo:context");
-
- Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
- Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
-
- // query with correct context
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));
-
- // query with wrong context
- Assert.assertEquals(Sets.newHashSet(),
- getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
- }
- }
-
- @Test
- public void testDcSearchWithSubject() throws Exception {
- // test a ring around dc
- try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
- f.setConf(conf);
-
- ValueFactory vf = new ValueFactoryImpl();
- Resource subject = vf.createURI("foo:subj");
- URI predicate = GeoConstants.GEO_AS_WKT;
- Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- Resource context = vf.createURI("foo:context");
-
- Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
- Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
-
- // query with correct subject
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject))));
-
- // query with wrong subject
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
- }
- }
-
- @Test
- public void testDcSearchWithSubjectAndContext() throws Exception {
- // test a ring around dc
- try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
- f.setConf(conf);
-
- ValueFactory vf = new ValueFactoryImpl();
- Resource subject = vf.createURI("foo:subj");
- URI predicate = GeoConstants.GEO_AS_WKT;
- Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- Resource context = vf.createURI("foo:context");
-
- Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
- Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
-
- // query with correct context subject
- Assert.assertEquals(Sets.newHashSet(statement),
- getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject))));
-
- // query with wrong context
- Assert.assertEquals(Sets.newHashSet(),
- getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
-
- // query with wrong subject
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
- }
- }
-
- @Test
- public void testDcSearchWithPredicate() throws Exception {
- // test a ring around dc
- try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
- f.setConf(conf);
-
- ValueFactory vf = new ValueFactoryImpl();
- Resource subject = vf.createURI("foo:subj");
- URI predicate = GeoConstants.GEO_AS_WKT;
- Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- Resource context = vf.createURI("foo:context");
-
- Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
- Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
-
- // query with correct Predicate
- Assert.assertEquals(Sets.newHashSet(statement),
- getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate)))));
-
- // query with wrong predicate
- Assert.assertEquals(Sets.newHashSet(),
- getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createURI("other:pred"))))));
- }
- }
-
- // @Test
- public void testAntiMeridianSearch() throws Exception {
- // verify that a search works if the bounding box crosses the anti meridian
- try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
- f.setConf(conf);
-
- ValueFactory vf = new ValueFactoryImpl();
- Resource context = vf.createURI("foo:context");
-
- Resource subjectEast = vf.createURI("foo:subj:east");
- URI predicateEast = GeoConstants.GEO_AS_WKT;
- Value objectEast = vf.createLiteral("Point(179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
- Statement statementEast = new ContextStatementImpl(subjectEast, predicateEast, objectEast, context);
- f.storeStatement(convertStatement(statementEast));
-
- Resource subjectWest = vf.createURI("foo:subj:west");
- URI predicateWest = GeoConstants.GEO_AS_WKT;
- Value objectWest = vf.createLiteral("Point(-179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
- Statement statementWest = new ContextStatementImpl(subjectWest, predicateWest, objectWest, context);
- f.storeStatement(convertStatement(statementWest));
-
- f.flush();
-
- double[] ONE = { 178.1, 1, -178, 1, -178, -1, 178.1, -1, 178.1, 1 };
-
- LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
-
- Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
-
- Assert.assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerSfTest.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerSfTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerSfTest.java
deleted file mode 100644
index fe6b51a..0000000
--- a/extras/indexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerSfTest.java
+++ /dev/null
@@ -1,305 +0,0 @@
-package mvm.rya.indexing.mongo;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-
-import org.apache.hadoop.conf.Configuration;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.openrdf.model.Resource;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.model.impl.StatementImpl;
-import org.openrdf.model.impl.ValueFactoryImpl;
-
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.mongodb.MongoClient;
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.LineString;
-import com.vividsolutions.jts.geom.LinearRing;
-import com.vividsolutions.jts.geom.Point;
-import com.vividsolutions.jts.geom.Polygon;
-import com.vividsolutions.jts.geom.PrecisionModel;
-import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;
-
-import de.flapdoodle.embed.mongo.distribution.Version;
-import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
-import info.aduna.iteration.CloseableIteration;
-import mvm.rya.api.RdfCloudTripleStoreConfiguration;
-import mvm.rya.api.domain.RyaStatement;
-import mvm.rya.api.resolver.RdfToRyaConversions;
-import mvm.rya.api.resolver.RyaToRdfConversions;
-import mvm.rya.indexing.StatementConstraints;
-import mvm.rya.indexing.accumulo.ConfigUtils;
-import mvm.rya.indexing.accumulo.geo.GeoConstants;
-import mvm.rya.indexing.mongodb.geo.MongoGeoIndexer;
-import mvm.rya.mongodb.MongoDBRdfConfiguration;
-
-/**
- * Tests all of the "simple functions" of the geoindexer.
- */
-public class MongoGeoIndexerSfTest {
- private MongoDBRdfConfiguration conf;
- private static GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
- private static MongoGeoIndexer g;
-
- private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints();
-
- // Here is the landscape:
- /**
- * <pre>
- * +---+---+---+---+---+---+---+
- * | F | |
- * + A + + C +
- * | | |
- * +---+---+ E +---+---+
- * | | / |
- * + B + /+---+---+
- * | | / | |
- * +---+---+/--+---+---+
- * / | D |
- * / +---+---+
- * </pre>
- **/
-
- private static final Polygon A = poly(bbox(0, 1, 4, 5));
- private static final Polygon B = poly(bbox(0, 1, 2, 3));
- private static final Polygon C = poly(bbox(4, 3, 6, 5));
- private static final Polygon D = poly(bbox(3, 0, 5, 2));
-
- private static final Point F = point(2, 4);
-
- private static final LineString E = line(2, 0, 3, 3);
-
- private static final Map<Geometry, String> names = Maps.newHashMap();
- static {
- names.put(A, "A");
- names.put(B, "B");
- names.put(C, "C");
- names.put(D, "D");
- names.put(E, "E");
- names.put(F, "F");
- }
-
- @Before
- public void before() throws Exception {
- System.out.println(UUID.randomUUID().toString());
- conf = new MongoDBRdfConfiguration();
- conf.set(ConfigUtils.USE_MONGO, "true");
- conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true");
- conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
- conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
- conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
- conf.set(ConfigUtils.USE_GEO, "true");
- conf.setTablePrefix("rya_");
-
- final MongodForTestsFactory testsFactory = MongodForTestsFactory.with(Version.Main.PRODUCTION);
- final MongoClient mongoClient = testsFactory.newMongo();
- g = new MongoGeoIndexer();
- g.initIndexer(conf, mongoClient);
- g.storeStatement(statement(A));
- g.storeStatement(statement(B));
- g.storeStatement(statement(C));
- g.storeStatement(statement(D));
- g.storeStatement(statement(F));
- g.storeStatement(statement(E));
- }
-
- private static RyaStatement statement(final Geometry geo) {
- final ValueFactory vf = new ValueFactoryImpl();
- final Resource subject = vf.createURI("uri:" + names.get(geo));
- final URI predicate = GeoConstants.GEO_AS_WKT;
- final Value object = vf.createLiteral(geo.toString(), GeoConstants.XMLSCHEMA_OGC_WKT);
- return RdfToRyaConversions.convertStatement(new StatementImpl(subject, predicate, object));
-
- }
-
- private static Point point(final double x, final double y) {
- return gf.createPoint(new Coordinate(x, y));
- }
-
- private static LineString line(final double x1, final double y1, final double x2, final double y2) {
- return new LineString(new PackedCoordinateSequence.Double(new double[] { x1, y1, x2, y2 }, 2), gf);
- }
-
- private static Polygon poly(final double[] arr) {
- final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(arr, 2));
- final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
- return p1;
- }
-
- private static double[] bbox(final double x1, final double y1, final double x2, final double y2) {
- return new double[] { x1, y1, x1, y2, x2, y2, x2, y1, x1, y1 };
- }
-
- public void compare(final CloseableIteration<Statement, ?> actual, final Geometry... expected) throws Exception {
- final Set<Statement> expectedSet = Sets.newHashSet();
- for (final Geometry geo : expected) {
- expectedSet.add(RyaToRdfConversions.convertStatement(statement(geo)));
- }
-
- Assert.assertEquals(expectedSet, getSet(actual));
- }
-
- private static <X> Set<X> getSet(final CloseableIteration<X, ?> iter) throws Exception {
- final Set<X> set = new HashSet<X>();
- while (iter.hasNext()) {
- set.add(iter.next());
- }
- return set;
- }
-
- private static Geometry[] EMPTY_RESULTS = {};
-
- @Test
- public void testEquals() throws Exception {
- // point
- compare(g.queryEquals(F, EMPTY_CONSTRAINTS), F);
- compare(g.queryEquals(point(2, 2), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-
- // line
- compare(g.queryEquals(E, EMPTY_CONSTRAINTS), E);
- compare(g.queryEquals(line(2, 2, 3, 3), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-
- // poly
- compare(g.queryEquals(A, EMPTY_CONSTRAINTS), A);
- compare(g.queryEquals(poly(bbox(1, 1, 4, 5)), EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-
- }
-
-// @Test
-// public void testDisjoint() throws Exception {
-// // point
-// compare(g.queryDisjoint(F, EMPTY_CONSTRAINTS), B, C, D, E);
-//
-// // line
-// compare(g.queryDisjoint(E, EMPTY_CONSTRAINTS), B, C, D, F);
-//
-// // poly
-// compare(g.queryDisjoint(A, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-// compare(g.queryDisjoint(B, EMPTY_CONSTRAINTS), C, D, F, E);
-// }
-
- @Test
- public void testIntersectsPoint() throws Exception {
- // This seems like a bug
- // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), A, F);
- // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
-
- @Test
- public void testIntersectsLine() throws Exception {
- // This seems like a bug
- // compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), A, E);
- // compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
-
-// @Test
-// public void testIntersectsPoly() throws Exception {
-// compare(g.queryIntersects(A, EMPTY_CONSTRAINTS), A, B, C, D, F, E);
-// }
-
-// @Test
-// public void testTouchesPoint() throws Exception {
-// compare(g.queryTouches(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-// }
-//
-// @Test
-// public void testTouchesLine() throws Exception {
-// compare(g.queryTouches(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-// }
-
-// @Test
-// public void testTouchesPoly() throws Exception {
-// compare(g.queryTouches(A, EMPTY_CONSTRAINTS), C);
-// }
-
-// @Test
-// public void testCrossesPoint() throws Exception {
-// compare(g.queryCrosses(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
-// }
-
- @Test
- public void testCrossesLine() throws Exception {
- // compare(g.queryCrosses(E, EMPTY_CONSTRAINTS), A);
- }
-
-// @Test
-// public void testCrossesPoly() throws Exception {
-// compare(g.queryCrosses(A, EMPTY_CONSTRAINTS), E);
-// }
-
-// @Test
-// public void testWithin() throws Exception {
-// // point
-// // compare(g.queryWithin(F, EMPTY_CONSTRAINTS), F);
-//
-// // line
-//// compare(g.queryWithin(E, EMPTY_CONSTRAINTS), E);
-//
-// // poly
-// compare(g.queryWithin(A, EMPTY_CONSTRAINTS), A, B, F);
-// }
-
-// @Test
-// public void testContainsPoint() throws Exception {
-// compare(g.queryContains(F, EMPTY_CONSTRAINTS), A, F);
-// }
-
- @Test
- public void testContainsLine() throws Exception {
- // compare(g.queryContains(E, EMPTY_CONSTRAINTS), E);
- }
-
-// @Test
-// public void testContainsPoly() throws Exception {
-// compare(g.queryContains(A, EMPTY_CONSTRAINTS), A);
-// compare(g.queryContains(B, EMPTY_CONSTRAINTS), A, B);
-// }
-
- @Test
- public void testOverlapsPoint() throws Exception {
- // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), F);
- // You cannot have overlapping points
- // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
-
- @Test
- public void testOverlapsLine() throws Exception {
- // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), A, E);
- // You cannot have overlapping lines
- // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS);
- }
-
-// @Test
-// public void testOverlapsPoly() throws Exception {
-// compare(g.queryOverlaps(A, EMPTY_CONSTRAINTS), D);
-// }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerTest.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerTest.java
deleted file mode 100644
index 7a20deb..0000000
--- a/extras/indexing/src/test/java/mvm/rya/indexing/mongo/MongoGeoIndexerTest.java
+++ /dev/null
@@ -1,396 +0,0 @@
-package mvm.rya.indexing.mongo;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-
-import static mvm.rya.api.resolver.RdfToRyaConversions.convertStatement;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.hadoop.conf.Configuration;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.openrdf.model.Resource;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.model.impl.ContextStatementImpl;
-import org.openrdf.model.impl.StatementImpl;
-import org.openrdf.model.impl.ValueFactoryImpl;
-
-import com.google.common.collect.Sets;
-import com.mongodb.MongoClient;
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.LinearRing;
-import com.vividsolutions.jts.geom.Point;
-import com.vividsolutions.jts.geom.Polygon;
-import com.vividsolutions.jts.geom.PrecisionModel;
-import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;
-
-import de.flapdoodle.embed.mongo.distribution.Version;
-import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
-import info.aduna.iteration.CloseableIteration;
-import mvm.rya.indexing.StatementConstraints;
-import mvm.rya.indexing.accumulo.ConfigUtils;
-import mvm.rya.indexing.accumulo.geo.GeoConstants;
-import mvm.rya.indexing.mongodb.geo.MongoGeoIndexer;
-import mvm.rya.mongodb.MongoDBRdfConfiguration;
-
-public class MongoGeoIndexerTest {
-
- private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints();
-
- MongoDBRdfConfiguration conf;
- MongoClient mongoClient;
- GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
-
- @Before
- public void before() throws Exception {
- conf = new MongoDBRdfConfiguration();
- conf.set(ConfigUtils.USE_MONGO, "true");
- conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true");
- conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
- conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
- conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT");
- conf.set(ConfigUtils.USE_GEO, "true");
- conf.setTablePrefix("rya_");
-
- final MongodForTestsFactory testsFactory = MongodForTestsFactory.with(Version.Main.PRODUCTION);
- mongoClient = testsFactory.newMongo();
- }
-
- @Test
- public void testRestrictPredicatesSearch() throws Exception {
- conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2");
- try (MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, mongoClient);
-
- final ValueFactory vf = new ValueFactoryImpl();
-
- final Point point = gf.createPoint(new Coordinate(10, 10));
- final Value pointValue = vf.createLiteral("Point(10 10)", GeoConstants.XMLSCHEMA_OGC_WKT);
- final URI invalidPredicate = GeoConstants.GEO_AS_WKT;
-
- // These should not be stored because they are not in the predicate list
- f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj1"), invalidPredicate, pointValue)));
- f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), invalidPredicate, pointValue)));
-
- final URI pred1 = vf.createURI("pred:1");
- final URI pred2 = vf.createURI("pred:2");
-
- // These should be stored because they are in the predicate list
- final Statement s3 = new StatementImpl(vf.createURI("foo:subj3"), pred1, pointValue);
- final Statement s4 = new StatementImpl(vf.createURI("foo:subj4"), pred2, pointValue);
- f.storeStatement(convertStatement(s3));
- f.storeStatement(convertStatement(s4));
-
- // This should not be stored because the object is not valid wkt
- f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj5"), pred1, vf.createLiteral("soint(10 10)"))));
-
- // This should not be stored because the object is not a literal
- f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj6"), pred1, vf.createURI("p:Point(10 10)"))));
-
- f.flush();
-
- final Set<Statement> actual = getSet(f.queryEquals(point, EMPTY_CONSTRAINTS));
- Assert.assertEquals(2, actual.size());
- Assert.assertTrue(actual.contains(s3));
- Assert.assertTrue(actual.contains(s4));
- }
- }
-
- private static <X> Set<X> getSet(final CloseableIteration<X, ?> iter) throws Exception {
- final Set<X> set = new HashSet<X>();
- while (iter.hasNext()) {
- set.add(iter.next());
- }
- return set;
- }
-
- @Test
- public void testPrimeMeridianSearch() throws Exception {
- try (MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, mongoClient);
-
- final ValueFactory vf = new ValueFactoryImpl();
- final Resource subject = vf.createURI("foo:subj");
- final URI predicate = GeoConstants.GEO_AS_WKT;
- final Value object = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
- final Resource context = vf.createURI("foo:context");
-
- final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- final double[] ONE = { 1, 1, -1, 1, -1, -1, 1, -1, 1, 1 };
- final double[] TWO = { 2, 2, -2, 2, -2, -2, 2, -2, 2, 2 };
- final double[] THREE = { 3, 3, -3, 3, -3, -3, 3, -3, 3, 3 };
-
- final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
- final LinearRing r2 = gf.createLinearRing(new PackedCoordinateSequence.Double(TWO, 2));
- final LinearRing r3 = gf.createLinearRing(new PackedCoordinateSequence.Double(THREE, 2));
-
- final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
- final Polygon p2 = gf.createPolygon(r2, new LinearRing[] {});
- final Polygon p3 = gf.createPolygon(r3, new LinearRing[] {});
-
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS)));
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS)));
-
- // Test a ring with a hole in it
- final Polygon p3m2 = gf.createPolygon(r3, new LinearRing[] { r2 });
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS)));
-
- // test a ring outside the point
- final double[] OUT = { 3, 3, 1, 3, 1, 1, 3, 1, 3, 3 };
- final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
- final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
- }
- }
-
- @Test
- public void testDcSearch() throws Exception {
- // test a ring around dc
- try (MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, mongoClient);
-
- final ValueFactory vf = new ValueFactoryImpl();
- final Resource subject = vf.createURI("foo:subj");
- final URI predicate = GeoConstants.GEO_AS_WKT;
- final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- final Resource context = vf.createURI("foo:context");
-
- final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
- final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
-
- // test a ring outside the point
- final double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
- final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
- final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
- }
- }
-
- @Test
- public void testDeleteSearch() throws Exception {
- // test a ring around dc
- try (MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, mongoClient);
-
- final ValueFactory vf = new ValueFactoryImpl();
- final Resource subject = vf.createURI("foo:subj");
- final URI predicate = GeoConstants.GEO_AS_WKT;
- final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- final Resource context = vf.createURI("foo:context");
-
- final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- f.deleteStatement(convertStatement(statement));
-
- // test a ring that the point would be inside of if not deleted
- final double[] in = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(in, 2));
- final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
-
- // test a ring that the point would be outside of if not deleted
- final double[] out = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
- final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(out, 2));
- final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
-
- // test a ring for the whole world and make sure the point is gone
- // Geomesa is a little sensitive around lon 180, so we only go to 179
- final double[] world = { -180, 90, 179, 90, 179, -90, -180, -90, -180, 90 };
- final LinearRing rWorld = gf.createLinearRing(new PackedCoordinateSequence.Double(world, 2));
- final Polygon pWorld = gf.createPolygon(rWorld, new LinearRing[] {});
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS)));
- }
- }
-
- @Test
- public void testDcSearchWithContext() throws Exception {
- // test a ring around dc
- try (MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, mongoClient);
-
- final ValueFactory vf = new ValueFactoryImpl();
- final Resource subject = vf.createURI("foo:subj");
- final URI predicate = GeoConstants.GEO_AS_WKT;
- final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- final Resource context = vf.createURI("foo:context");
-
- final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
- final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
-
- // query with correct context
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));
-
- // query with wrong context
- Assert.assertEquals(Sets.newHashSet(),
- getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
- }
- }
-
- @Test
- public void testDcSearchWithSubject() throws Exception {
- // test a ring around dc
- try (MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, mongoClient);
-
- final ValueFactory vf = new ValueFactoryImpl();
- final Resource subject = vf.createURI("foo:subj");
- final URI predicate = GeoConstants.GEO_AS_WKT;
- final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- final Resource context = vf.createURI("foo:context");
-
- final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
- final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
-
- // query with correct subject
- Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject))));
-
- // query with wrong subject
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
- }
- }
-
- @Test
- public void testDcSearchWithSubjectAndContext() throws Exception {
- // test a ring around dc
- try (MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, mongoClient);
-
- final ValueFactory vf = new ValueFactoryImpl();
- final Resource subject = vf.createURI("foo:subj");
- final URI predicate = GeoConstants.GEO_AS_WKT;
- final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- final Resource context = vf.createURI("foo:context");
-
- final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
- final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
-
- // query with correct context subject
- Assert.assertEquals(Sets.newHashSet(statement),
- getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject))));
-
- // query with wrong context
- Assert.assertEquals(Sets.newHashSet(),
- getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
-
- // query with wrong subject
- Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
- }
- }
-
- @Test
- public void testDcSearchWithPredicate() throws Exception {
- // test a ring around dc
- try (MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, mongoClient);
-
- final ValueFactory vf = new ValueFactoryImpl();
- final Resource subject = vf.createURI("foo:subj");
- final URI predicate = GeoConstants.GEO_AS_WKT;
- final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
- final Resource context = vf.createURI("foo:context");
-
- final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
- f.storeStatement(convertStatement(statement));
- f.flush();
-
- final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
- final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
- final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
-
- // query with correct Predicate
- Assert.assertEquals(Sets.newHashSet(statement),
- getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate)))));
-
- // query with wrong predicate
- Assert.assertEquals(Sets.newHashSet(),
- getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createURI("other:pred"))))));
- }
- }
-
- // @Test
- public void testAntiMeridianSearch() throws Exception {
- // verify that a search works if the bounding box crosses the anti meridian
- try (MongoGeoIndexer f = new MongoGeoIndexer()) {
- f.initIndexer(conf, mongoClient);
-
- final ValueFactory vf = new ValueFactoryImpl();
- final Resource context = vf.createURI("foo:context");
-
- final Resource subjectEast = vf.createURI("foo:subj:east");
- final URI predicateEast = GeoConstants.GEO_AS_WKT;
- final Value objectEast = vf.createLiteral("Point(179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
- final Statement statementEast = new ContextStatementImpl(subjectEast, predicateEast, objectEast, context);
- f.storeStatement(convertStatement(statementEast));
-
- final Resource subjectWest = vf.createURI("foo:subj:west");
- final URI predicateWest = GeoConstants.GEO_AS_WKT;
- final Value objectWest = vf.createLiteral("Point(-179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
- final Statement statementWest = new ContextStatementImpl(subjectWest, predicateWest, objectWest, context);
- f.storeStatement(convertStatement(statementWest));
-
- f.flush();
-
- final double[] ONE = { 178.1, 1, -178, 1, -178, -1, 178.1, -1, 178.1, 1 };
-
- final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
-
- final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
-
- Assert.assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
- }
- }
-}
[5/6] incubator-rya git commit: RYA-177 adding optional geoindexing
profile
Posted by mi...@apache.org.
RYA-177 adding optional geoindexing profile
Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/7727b165
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/7727b165
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/7727b165
Branch: refs/heads/master
Commit: 7727b1651b734d4b06d518032897f0c0dc4f88d5
Parents: 5913670
Author: pujav65 <pu...@gmail.com>
Authored: Fri Oct 7 11:26:43 2016 -0400
Committer: pujav65 <pu...@gmail.com>
Committed: Fri Oct 7 11:26:43 2016 -0400
----------------------------------------------------------------------
extras/indexing/pom.xml | 27 +-
.../api/client/accumulo/AccumuloInstall.java | 3 +-
.../rya/indexing/FilterFunctionOptimizer.java | 21 +-
.../java/mvm/rya/indexing/GeoConstants.java | 46 ++
.../main/java/mvm/rya/indexing/GeoIndexer.java | 185 -------
.../rya/indexing/IndexingFunctionRegistry.java | 2 -
.../mvm/rya/indexing/accumulo/ConfigUtils.java | 29 +-
.../rya/indexing/accumulo/geo/GeoConstants.java | 46 --
.../accumulo/geo/GeoMesaGeoIndexer.java | 517 ------------------
.../indexing/accumulo/geo/GeoParseUtils.java | 123 -----
.../rya/indexing/accumulo/geo/GeoTupleSet.java | 362 -------------
.../mongodb/geo/GeoMongoDBStorageStrategy.java | 143 -----
.../indexing/mongodb/geo/MongoGeoIndexer.java | 112 ----
.../indexing/mongodb/geo/MongoGeoTupleSet.java | 361 -------------
.../mvm/rya/sail/config/RyaSailFactory.java | 2 +-
.../indexing/accumulo/geo/GeoIndexerSfTest.java | 514 ------------------
.../indexing/accumulo/geo/GeoIndexerTest.java | 400 --------------
.../indexing/mongo/MongoGeoIndexerSfTest.java | 305 -----------
.../rya/indexing/mongo/MongoGeoIndexerTest.java | 396 --------------
.../src/main/java/MongoRyaDirectExample.java | 114 ++--
.../src/main/java/RyaDirectExample.java | 489 +++++++++--------
extras/pom.xml | 9 +
extras/rya.geoindexing/pom.xml | 224 ++++++++
.../GeoEnabledFilterFunctionOptimizer.java | 353 +++++++++++++
.../main/java/mvm/rya/indexing/GeoIndexer.java | 185 +++++++
.../mvm/rya/indexing/GeoRyaSailFactory.java | 146 ++++++
.../mvm/rya/indexing/OptionalConfigUtils.java | 141 +++++
.../accumulo/geo/GeoMesaGeoIndexer.java | 518 +++++++++++++++++++
.../indexing/accumulo/geo/GeoParseUtils.java | 119 +++++
.../rya/indexing/accumulo/geo/GeoTupleSet.java | 363 +++++++++++++
.../mongodb/geo/GeoMongoDBStorageStrategy.java | 143 +++++
.../indexing/mongodb/geo/MongoGeoIndexer.java | 112 ++++
.../indexing/mongodb/geo/MongoGeoTupleSet.java | 360 +++++++++++++
.../indexing/accumulo/geo/GeoIndexerSfTest.java | 514 ++++++++++++++++++
.../indexing/accumulo/geo/GeoIndexerTest.java | 401 ++++++++++++++
.../indexing/mongo/MongoGeoIndexerSfTest.java | 304 +++++++++++
.../rya/indexing/mongo/MongoGeoIndexerTest.java | 396 ++++++++++++++
extras/rya.prospector/pom.xml | 1 +
.../rya/accumulo/mr/AbstractAccumuloMRTool.java | 1 -
.../mvm/rya/accumulo/mr/RyaOutputFormat.java | 37 +-
.../rya/accumulo/mr/RyaOutputFormatTest.java | 37 --
41 files changed, 4644 insertions(+), 3917 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/pom.xml
----------------------------------------------------------------------
diff --git a/extras/indexing/pom.xml b/extras/indexing/pom.xml
index fb3042f..8e21879 100644
--- a/extras/indexing/pom.xml
+++ b/extras/indexing/pom.xml
@@ -25,15 +25,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <geotools.version>14.3</geotools.version>
- </properties>
- <repositories>
- <repository>
- <id>osgeo</id>
- <name>Open Source Geospatial Foundation Repository</name>
- <url>http://download.osgeo.org/webdav/geotools/</url>
- </repository>
- </repositories>
+ </properties>
<dependencies>
@@ -82,11 +74,6 @@
<artifactId>commons-codec</artifactId>
</dependency>
- <!-- Geo Indexing -->
- <dependency>
- <groupId>org.locationtech.geomesa</groupId>
- <artifactId>geomesa-accumulo-datastore</artifactId>
- </dependency>
<!-- PCJ Indexing -->
<dependency>
@@ -119,17 +106,7 @@
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
- <dependency>
- <groupId>org.geotools.xsd</groupId>
- <artifactId>gt-xsd-gml3</artifactId>
- <version>${geotools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.geotools</groupId>
- <artifactId>gt-api</artifactId>
- <version>${geotools.version}</version>
- </dependency>
- <dependency>
+ <dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</version>
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/api/client/accumulo/AccumuloInstall.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/api/client/accumulo/AccumuloInstall.java b/extras/indexing/src/main/java/mvm/rya/api/client/accumulo/AccumuloInstall.java
index 841be01..08c1932 100644
--- a/extras/indexing/src/main/java/mvm/rya/api/client/accumulo/AccumuloInstall.java
+++ b/extras/indexing/src/main/java/mvm/rya/api/client/accumulo/AccumuloInstall.java
@@ -186,7 +186,8 @@ public class AccumuloInstall extends AccumuloCommand implements Install {
conf.setTablePrefix( details.getRyaInstanceName() );
// Enable the indexers that the instance is configured to use.
- conf.set(ConfigUtils.USE_GEO, "" + details.getGeoIndexDetails().isEnabled() );
+ // TODO fix me, not sure why the install command is here.
+// conf.set(ConfigUtils.USE_GEO, "" + details.getGeoIndexDetails().isEnabled() );
conf.set(ConfigUtils.USE_FREETEXT, "" + details.getFreeTextIndexDetails().isEnabled() );
conf.set(ConfigUtils.USE_TEMPORAL, "" + details.getTemporalIndexDetails().isEnabled() );
conf.set(ConfigUtils.USE_ENTITY, "" + details.getEntityCentricIndexDetails().isEnabled());
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/FilterFunctionOptimizer.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/FilterFunctionOptimizer.java b/extras/indexing/src/main/java/mvm/rya/indexing/FilterFunctionOptimizer.java
index 6c0cd9a..d148b74 100644
--- a/extras/indexing/src/main/java/mvm/rya/indexing/FilterFunctionOptimizer.java
+++ b/extras/indexing/src/main/java/mvm/rya/indexing/FilterFunctionOptimizer.java
@@ -34,7 +34,6 @@ import org.apache.commons.lang.Validate;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
import org.apache.log4j.Logger;
-import org.geotools.feature.SchemaException;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
@@ -58,28 +57,21 @@ import org.openrdf.query.algebra.evaluation.QueryOptimizer;
import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
import com.google.common.collect.Lists;
-import com.mongodb.MongoClient;
import mvm.rya.accumulo.AccumuloRdfConfiguration;
import mvm.rya.indexing.IndexingFunctionRegistry.FUNCTION_TYPE;
import mvm.rya.indexing.accumulo.ConfigUtils;
import mvm.rya.indexing.accumulo.freetext.AccumuloFreeTextIndexer;
import mvm.rya.indexing.accumulo.freetext.FreeTextTupleSet;
-import mvm.rya.indexing.accumulo.geo.GeoMesaGeoIndexer;
-import mvm.rya.indexing.accumulo.geo.GeoTupleSet;
import mvm.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer;
-import mvm.rya.indexing.mongodb.AbstractMongoIndexer;
import mvm.rya.indexing.mongodb.freetext.MongoFreeTextIndexer;
-import mvm.rya.indexing.mongodb.geo.MongoGeoIndexer;
import mvm.rya.indexing.mongodb.temporal.MongoTemporalIndexer;
-import mvm.rya.mongodb.MongoConnectorFactory;
public class FilterFunctionOptimizer implements QueryOptimizer, Configurable {
private static final Logger LOG = Logger.getLogger(FilterFunctionOptimizer.class);
private final ValueFactory valueFactory = new ValueFactoryImpl();
private Configuration conf;
- private GeoIndexer geoIndexer;
private FreeTextIndexer freeTextIndexer;
private TemporalIndexer temporalIndexer;
private boolean init = false;
@@ -88,7 +80,7 @@ public class FilterFunctionOptimizer implements QueryOptimizer, Configurable {
}
public FilterFunctionOptimizer(final AccumuloRdfConfiguration conf) throws AccumuloException, AccumuloSecurityException,
- TableNotFoundException, IOException, SchemaException, TableExistsException, NumberFormatException, UnknownHostException {
+ TableNotFoundException, IOException, TableExistsException, NumberFormatException, UnknownHostException {
this.conf = conf;
init();
}
@@ -106,16 +98,12 @@ public class FilterFunctionOptimizer implements QueryOptimizer, Configurable {
private synchronized void init() {
if (!init) {
if (ConfigUtils.getUseMongo(conf)) {
- geoIndexer = new MongoGeoIndexer();
- geoIndexer.setConf(conf);
freeTextIndexer = new MongoFreeTextIndexer();
freeTextIndexer.setConf(conf);
temporalIndexer = new MongoTemporalIndexer();
temporalIndexer.setConf(conf);
} else {
- geoIndexer = new GeoMesaGeoIndexer();
- geoIndexer.setConf(conf);
- freeTextIndexer = new AccumuloFreeTextIndexer();
+ freeTextIndexer = new AccumuloFreeTextIndexer();
freeTextIndexer.setConf(conf);
temporalIndexer = new AccumuloTemporalIndexer();
temporalIndexer.setConf(conf);
@@ -309,11 +297,6 @@ public class FilterFunctionOptimizer implements QueryOptimizer, Configurable {
public List<TupleExpr> createReplacement(final TupleExpr org) {
final List<TupleExpr> indexTuples = Lists.newArrayList();
switch (type) {
- case GEO:
- for (final IndexingExpr indx : indxExpr) {
- indexTuples.add(new GeoTupleSet(indx, geoIndexer));
- }
- break;
case FREETEXT:
for (final IndexingExpr indx : indxExpr) {
indexTuples.add(new FreeTextTupleSet(indx, freeTextIndexer));
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/GeoConstants.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/GeoConstants.java b/extras/indexing/src/main/java/mvm/rya/indexing/GeoConstants.java
new file mode 100644
index 0000000..a692edd
--- /dev/null
+++ b/extras/indexing/src/main/java/mvm/rya/indexing/GeoConstants.java
@@ -0,0 +1,46 @@
+package mvm.rya.indexing;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.openrdf.model.URI;
+import org.openrdf.model.impl.URIImpl;
+
+/**
+ * A set of URIs used in GeoSPARQL
+ */
+public class GeoConstants {
+ public static final String NS_GEO = "http://www.opengis.net/ont/geosparql#";
+ public static final String NS_GEOF = "http://www.opengis.net/def/function/geosparql/";
+
+ public static final URI XMLSCHEMA_OGC_WKT = new URIImpl(NS_GEO + "wktLiteral");
+ public static final URI GEO_AS_WKT = new URIImpl(NS_GEO + "asWKT");
+
+ public static final URI XMLSCHEMA_OGC_GML = new URIImpl(NS_GEO + "gmlLiteral");
+ public static final URI GEO_AS_GML = new URIImpl(NS_GEO + "asGML");
+
+ public static final URI GEO_SF_EQUALS = new URIImpl(NS_GEOF + "sfEquals");
+ public static final URI GEO_SF_DISJOINT = new URIImpl(NS_GEOF + "sfDisjoint");
+ public static final URI GEO_SF_INTERSECTS = new URIImpl(NS_GEOF + "sfIntersects");
+ public static final URI GEO_SF_TOUCHES = new URIImpl(NS_GEOF + "sfTouches");
+ public static final URI GEO_SF_CROSSES = new URIImpl(NS_GEOF + "sfCrosses");
+ public static final URI GEO_SF_WITHIN = new URIImpl(NS_GEOF + "sfWithin");
+ public static final URI GEO_SF_CONTAINS = new URIImpl(NS_GEOF + "sfContains");
+ public static final URI GEO_SF_OVERLAPS = new URIImpl(NS_GEOF + "sfOverlaps");
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/GeoIndexer.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/GeoIndexer.java b/extras/indexing/src/main/java/mvm/rya/indexing/GeoIndexer.java
deleted file mode 100644
index 40dfeec..0000000
--- a/extras/indexing/src/main/java/mvm/rya/indexing/GeoIndexer.java
+++ /dev/null
@@ -1,185 +0,0 @@
-package mvm.rya.indexing;
-
-import org.openrdf.model.Statement;
-import org.openrdf.query.QueryEvaluationException;
-
-import com.vividsolutions.jts.geom.Geometry;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-
-import info.aduna.iteration.CloseableIteration;
-import mvm.rya.api.persist.index.RyaSecondaryIndexer;
-
-/**
- * A repository to store, index, and retrieve {@link Statement}s based on geospatial features.
- */
-public interface GeoIndexer extends RyaSecondaryIndexer {
- /**
- * Returns statements that contain a geometry that is equal to the queried {@link Geometry} and meet the {@link StatementConstraints}.
- *
- * <p>
- * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
- * <ul>
- * <li>
- * "Two geometries are topologically equal if their interiors intersect and no part of the interior or boundary of one geometry intersects the exterior of the other"
- * <li>"A is equal to B if A is within B and A contains B"
- * </ul>
- *
- * @param query
- * the queried geometry
- * @param contraints
- * the {@link StatementConstraints}
- * @return
- */
- public abstract CloseableIteration<Statement, QueryEvaluationException> queryEquals(Geometry query, StatementConstraints contraints);
-
- /**
- * Returns statements that contain a geometry that is disjoint to the queried {@link Geometry} and meet the {@link StatementConstraints}.
- *
- * <p>
- * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
- * <ul>
- * <li>"A and B are disjoint if they have no point in common. They form a set of disconnected geometries."
- * <li>"A and B are disjoint if A does not intersect B"
- * </ul>
- *
- * @param query
- * the queried geometry
- * @param contraints
- * the {@link StatementConstraints}
- * @return
- */
- public abstract CloseableIteration<Statement, QueryEvaluationException> queryDisjoint(Geometry query, StatementConstraints contraints);
-
- /**
- * Returns statements that contain a geometry that Intersects the queried {@link Geometry} and meet the {@link StatementConstraints}.
- *
- * <p>
- * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
- * <ul>
- * <li>"a intersects b: geometries a and b have at least one point in common."
- * <li>"not Disjoint"
- * </ul>
- *
- *
- * @param query
- * the queried geometry
- * @param contraints
- * the {@link StatementConstraints}
- * @return
- */
- public abstract CloseableIteration<Statement, QueryEvaluationException> queryIntersects(Geometry query, StatementConstraints contraints);
-
- /**
- * Returns statements that contain a geometry that Touches the queried {@link Geometry} and meet the {@link StatementConstraints}.
- *
- * <p>
- * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
- * <ul>
- * <li>"a touches b, they have at least one boundary point in common, but no interior points."
- * </ul>
- *
- *
- * @param query
- * the queried geometry
- * @param contraints
- * the {@link StatementConstraints}
- * @return
- */
- public abstract CloseableIteration<Statement, QueryEvaluationException> queryTouches(Geometry query, StatementConstraints contraints);
-
- /**
- * Returns statements that contain a geometry that crosses the queried {@link Geometry} and meet the {@link StatementConstraints}.
- *
- * <p>
- * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
- * <ul>
- * <li>
- * "a crosses b, they have some but not all interior points in common (and the dimension of the intersection is less than that of at least one of them)."
- * </ul>
- *
- * @param query
- * the queried geometry
- * @param contraints
- * the {@link StatementConstraints}
- * @return
- */
- public abstract CloseableIteration<Statement, QueryEvaluationException> queryCrosses(Geometry query, StatementConstraints contraints);
-
- /**
- * Returns statements that contain a geometry that is Within the queried {@link Geometry} and meet the {@link StatementConstraints}.
- *
- * <p>
- * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
- * <ul>
- * <li>"a is within b, a lies in the interior of b"
- * <li>Same as: "Contains(b,a)"
- * </ul>
- *
- *
- * @param query
- * the queried geometry
- * @param contraints
- * the {@link StatementConstraints}
- * @return
- */
- public abstract CloseableIteration<Statement, QueryEvaluationException> queryWithin(Geometry query, StatementConstraints contraints);
-
- /**
- * Returns statements that contain a geometry that Contains the queried {@link Geometry} and meet the {@link StatementConstraints}.
- *
- * <p>
- * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
- * <ul>
- * <li>b is within a. Geometry b lies in the interior of a. Another definition:
- * "a 'contains' b iff no points of b lie in the exterior of a, and at least one point of the interior of b lies in the interior of a"
- * <li>Same: Within(b,a)
- * </ul>
- *
- *
- * @param query
- * the queried geometry
- * @param contraints
- * the {@link StatementConstraints}
- * @return
- */
- public abstract CloseableIteration<Statement, QueryEvaluationException> queryContains(Geometry query, StatementConstraints contraints);
-
- /**
- * Returns statements that contain a geometry that Overlaps the queried {@link Geometry} and meet the {@link StatementConstraints}.
- *
- * <p>
- * From Wikipedia (http://en.wikipedia.org/wiki/DE-9IM):
- * <ul>
- * <li>a crosses b, they have some but not all interior points in common (and the dimension of the intersection is less than that of at
- * least one of them).
- * </ul>
- *
- *
- * @param query
- * the queried geometry
- * @param contraints
- * the {@link StatementConstraints}
- * @return
- */
- public abstract CloseableIteration<Statement, QueryEvaluationException> queryOverlaps(Geometry query, StatementConstraints contraints);
-}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/IndexingFunctionRegistry.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/IndexingFunctionRegistry.java b/extras/indexing/src/main/java/mvm/rya/indexing/IndexingFunctionRegistry.java
index e96b8a3..2f2c486 100644
--- a/extras/indexing/src/main/java/mvm/rya/indexing/IndexingFunctionRegistry.java
+++ b/extras/indexing/src/main/java/mvm/rya/indexing/IndexingFunctionRegistry.java
@@ -24,8 +24,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import mvm.rya.indexing.accumulo.geo.GeoConstants;
-
import org.openrdf.model.URI;
import org.openrdf.model.impl.URIImpl;
import org.openrdf.query.algebra.ValueConstant;
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/ConfigUtils.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/ConfigUtils.java b/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/ConfigUtils.java
index 01c76db..7c608de 100644
--- a/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/ConfigUtils.java
+++ b/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/ConfigUtils.java
@@ -58,11 +58,9 @@ import mvm.rya.indexing.accumulo.entity.EntityOptimizer;
import mvm.rya.indexing.accumulo.freetext.AccumuloFreeTextIndexer;
import mvm.rya.indexing.accumulo.freetext.LuceneTokenizer;
import mvm.rya.indexing.accumulo.freetext.Tokenizer;
-import mvm.rya.indexing.accumulo.geo.GeoMesaGeoIndexer;
import mvm.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer;
import mvm.rya.indexing.external.PrecomputedJoinIndexer;
import mvm.rya.indexing.mongodb.freetext.MongoFreeTextIndexer;
-import mvm.rya.indexing.mongodb.geo.MongoGeoIndexer;
import mvm.rya.indexing.pcj.matching.PCJOptimizer;
/**
@@ -87,9 +85,6 @@ public class ConfigUtils {
public static final String FREE_TEXT_QUERY_TERM_LIMIT = "sc.freetext.querytermlimit";
- public static final String GEO_NUM_PARTITIONS = "sc.geo.numPartitions";
-
- public static final String USE_GEO = "sc.use_geo";
public static final String USE_FREETEXT = "sc.use_freetext";
public static final String USE_TEMPORAL = "sc.use_temporal";
public static final String USE_ENTITY = "sc.use_entity";
@@ -199,7 +194,7 @@ public class ConfigUtils {
return getPredicates(conf, TEMPORAL_PREDICATES_LIST);
}
- private static Set<URI> getPredicates(final Configuration conf, final String confName) {
+ protected static Set<URI> getPredicates(final Configuration conf, final String confName) {
final String[] validPredicateStrings = conf.getStrings(confName, new String[] {});
final Set<URI> predicates = new HashSet<URI>();
for (final String prediateString : validPredicateStrings) {
@@ -316,7 +311,7 @@ public class ConfigUtils {
return conf.getBoolean(USE_MOCK_INSTANCE, false);
}
- private static int getNumPartitions(final Configuration conf) {
+ protected static int getNumPartitions(final Configuration conf) {
return conf.getInt(NUM_PARTITIONS, 25);
}
@@ -328,15 +323,7 @@ public class ConfigUtils {
return conf.getInt(FREETEXT_TERM_NUM_PARTITIONS, getNumPartitions(conf));
}
- public static int getGeoNumPartitions(final Configuration conf) {
- return conf.getInt(GEO_NUM_PARTITIONS, getNumPartitions(conf));
- }
-
- public static boolean getUseGeo(final Configuration conf) {
- return conf.getBoolean(USE_GEO, false);
- }
-
- public static boolean getUseFreeText(final Configuration conf) {
+ public static boolean getUseFreeText(final Configuration conf) {
return conf.getBoolean(USE_FREETEXT, false);
}
@@ -384,11 +371,7 @@ public class ConfigUtils {
boolean useFilterIndex = false;
if (ConfigUtils.getUseMongo(conf)) {
- if (getUseGeo(conf)) {
- indexList.add(MongoGeoIndexer.class.getName());
- useFilterIndex = true;
- }
- if (getUseFreeText(conf)) {
+ if (getUseFreeText(conf)) {
indexList.add(MongoFreeTextIndexer.class.getName());
useFilterIndex = true;
}
@@ -402,10 +385,6 @@ public class ConfigUtils {
indexList.add(PrecomputedJoinIndexer.class.getName());
}
- if (getUseGeo(conf)) {
- indexList.add(GeoMesaGeoIndexer.class.getName());
- useFilterIndex = true;
- }
if (getUseFreeText(conf)) {
indexList.add(AccumuloFreeTextIndexer.class.getName());
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoConstants.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoConstants.java b/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoConstants.java
deleted file mode 100644
index 8f563e0..0000000
--- a/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoConstants.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package mvm.rya.indexing.accumulo.geo;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.openrdf.model.URI;
-import org.openrdf.model.impl.URIImpl;
-
-/**
- * A set of URIs used in GeoSPARQL
- */
-public class GeoConstants {
- public static final String NS_GEO = "http://www.opengis.net/ont/geosparql#";
- public static final String NS_GEOF = "http://www.opengis.net/def/function/geosparql/";
-
- public static final URI XMLSCHEMA_OGC_WKT = new URIImpl(NS_GEO + "wktLiteral");
- public static final URI GEO_AS_WKT = new URIImpl(NS_GEO + "asWKT");
-
- public static final URI XMLSCHEMA_OGC_GML = new URIImpl(NS_GEO + "gmlLiteral");
- public static final URI GEO_AS_GML = new URIImpl(NS_GEO + "asGML");
-
- public static final URI GEO_SF_EQUALS = new URIImpl(NS_GEOF + "sfEquals");
- public static final URI GEO_SF_DISJOINT = new URIImpl(NS_GEOF + "sfDisjoint");
- public static final URI GEO_SF_INTERSECTS = new URIImpl(NS_GEOF + "sfIntersects");
- public static final URI GEO_SF_TOUCHES = new URIImpl(NS_GEOF + "sfTouches");
- public static final URI GEO_SF_CROSSES = new URIImpl(NS_GEOF + "sfCrosses");
- public static final URI GEO_SF_WITHIN = new URIImpl(NS_GEOF + "sfWithin");
- public static final URI GEO_SF_CONTAINS = new URIImpl(NS_GEOF + "sfContains");
- public static final URI GEO_SF_OVERLAPS = new URIImpl(NS_GEOF + "sfOverlaps");
-}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java b/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java
deleted file mode 100644
index 7bfe6b7..0000000
--- a/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java
+++ /dev/null
@@ -1,517 +0,0 @@
-package mvm.rya.indexing.accumulo.geo;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.Instance;
-import org.apache.accumulo.core.client.mock.MockInstance;
-import org.apache.commons.lang.StringUtils;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.log4j.Logger;
-import org.geotools.data.DataStore;
-import org.geotools.data.DataStoreFinder;
-import org.geotools.data.DataUtilities;
-import org.geotools.data.FeatureSource;
-import org.geotools.data.FeatureStore;
-import org.geotools.data.Query;
-import org.geotools.factory.CommonFactoryFinder;
-import org.geotools.factory.Hints;
-import org.geotools.feature.DefaultFeatureCollection;
-import org.geotools.feature.FeatureIterator;
-import org.geotools.feature.SchemaException;
-import org.geotools.feature.simple.SimpleFeatureBuilder;
-import org.geotools.filter.text.cql2.CQLException;
-import org.geotools.filter.text.ecql.ECQL;
-import org.locationtech.geomesa.accumulo.data.AccumuloDataStore;
-import org.locationtech.geomesa.accumulo.index.Constants;
-import org.locationtech.geomesa.utils.geotools.SimpleFeatureTypes;
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.feature.simple.SimpleFeatureType;
-import org.opengis.filter.Filter;
-import org.opengis.filter.FilterFactory;
-import org.opengis.filter.identity.Identifier;
-import org.openrdf.model.Literal;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.query.QueryEvaluationException;
-
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.io.ParseException;
-import com.vividsolutions.jts.io.WKTReader;
-
-import info.aduna.iteration.CloseableIteration;
-import mvm.rya.accumulo.experimental.AbstractAccumuloIndexer;
-import mvm.rya.api.RdfCloudTripleStoreConfiguration;
-import mvm.rya.api.domain.RyaStatement;
-import mvm.rya.api.resolver.RyaToRdfConversions;
-import mvm.rya.indexing.GeoIndexer;
-import mvm.rya.indexing.Md5Hash;
-import mvm.rya.indexing.StatementConstraints;
-import mvm.rya.indexing.StatementSerializer;
-import mvm.rya.indexing.accumulo.ConfigUtils;
-
-/**
- * A {@link GeoIndexer} wrapper around a GeoMesa {@link AccumuloDataStore}. This class configures and connects to the Datastore, creates the
- * RDF Feature Type, and interacts with the Datastore.
- * <p>
- * Specifically, this class creates a RDF Feature type and stores each RDF Statement as a RDF Feature in the datastore. Each feature
- * contains the standard set of GeoMesa attributes (Geometry, Start Date, and End Date). The GeoMesaGeoIndexer populates the Geometry
- * attribute by parsing the Well-Known Text contained in the RDF Statement\u2019s object literal value.
- * <p>
- * The RDF Feature contains four additional attributes for each component of the RDF Statement. These attributes are:
- * <p>
- * <table border="1">
- * <tr>
- * <th>Name</th>
- * <th>Symbol</th>
- * <th>Type</th>
- * </tr>
- * <tr>
- * <td>Subject Attribute</td>
- * <td>S</td>
- * <td>String</td>
- * </tr>
- * </tr>
- * <tr>
- * <td>Predicate Attribute</td>
- * <td>P</td>
- * <td>String</td>
- * </tr>
- * </tr>
- * <tr>
- * <td>Object Attribute</td>
- * <td>O</td>
- * <td>String</td>
- * </tr>
- * </tr>
- * <tr>
- * <td>Context Attribute</td>
- * <td>C</td>
- * <td>String</td>
- * </tr>
- * </table>
- */
-public class GeoMesaGeoIndexer extends AbstractAccumuloIndexer implements GeoIndexer {
-
- private static final String TABLE_SUFFIX = "geo";
-
- private static final Logger logger = Logger.getLogger(GeoMesaGeoIndexer.class);
-
- private static final String FEATURE_NAME = "RDF";
-
- private static final String SUBJECT_ATTRIBUTE = "S";
- private static final String PREDICATE_ATTRIBUTE = "P";
- private static final String OBJECT_ATTRIBUTE = "O";
- private static final String CONTEXT_ATTRIBUTE = "C";
-
- private Set<URI> validPredicates;
- private Configuration conf;
- private FeatureStore<SimpleFeatureType, SimpleFeature> featureStore;
- private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource;
- private SimpleFeatureType featureType;
- private boolean isInit = false;
-
- //initialization occurs in setConf because index is created using reflection
- @Override
- public void setConf(final Configuration conf) {
- this.conf = conf;
- if (!isInit) {
- try {
- initInternal();
- isInit = true;
- } catch (final IOException e) {
- logger.warn("Unable to initialize index. Throwing Runtime Exception. ", e);
- throw new RuntimeException(e);
- }
- }
- }
-
- @Override
- public Configuration getConf() {
- return conf;
- }
-
-
- private void initInternal() throws IOException {
- validPredicates = ConfigUtils.getGeoPredicates(conf);
-
- final DataStore dataStore = createDataStore(conf);
-
- try {
- featureType = getStatementFeatureType(dataStore);
- } catch (final IOException e) {
- throw new IOException(e);
- } catch (final SchemaException e) {
- throw new IOException(e);
- }
-
- featureSource = dataStore.getFeatureSource(featureType.getName());
- if (!(featureSource instanceof FeatureStore)) {
- throw new IllegalStateException("Could not retrieve feature store");
- }
- featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) featureSource;
- }
-
- private static DataStore createDataStore(final Configuration conf) throws IOException {
- // get the configuration parameters
- final Instance instance = ConfigUtils.getInstance(conf);
- final boolean useMock = instance instanceof MockInstance;
- final String instanceId = instance.getInstanceName();
- final String zookeepers = instance.getZooKeepers();
- final String user = ConfigUtils.getUsername(conf);
- final String password = ConfigUtils.getPassword(conf);
- final String auths = ConfigUtils.getAuthorizations(conf).toString();
- final String tableName = getTableName(conf);
- final int numParitions = ConfigUtils.getGeoNumPartitions(conf);
-
- final String featureSchemaFormat = "%~#s%" + numParitions + "#r%" + FEATURE_NAME
- + "#cstr%0,3#gh%yyyyMMdd#d::%~#s%3,2#gh::%~#s%#id";
- // build the map of parameters
- final Map<String, Serializable> params = new HashMap<String, Serializable>();
- params.put("instanceId", instanceId);
- params.put("zookeepers", zookeepers);
- params.put("user", user);
- params.put("password", password);
- params.put("auths", auths);
- params.put("tableName", tableName);
- params.put("indexSchemaFormat", featureSchemaFormat);
- params.put("useMock", Boolean.toString(useMock));
-
- // fetch the data store from the finder
- return DataStoreFinder.getDataStore(params);
- }
-
- private static SimpleFeatureType getStatementFeatureType(final DataStore dataStore) throws IOException, SchemaException {
- SimpleFeatureType featureType;
-
- final String[] datastoreFeatures = dataStore.getTypeNames();
- if (Arrays.asList(datastoreFeatures).contains(FEATURE_NAME)) {
- featureType = dataStore.getSchema(FEATURE_NAME);
- } else {
- final String featureSchema = SUBJECT_ATTRIBUTE + ":String," //
- + PREDICATE_ATTRIBUTE + ":String," //
- + OBJECT_ATTRIBUTE + ":String," //
- + CONTEXT_ATTRIBUTE + ":String," //
- + Constants.SF_PROPERTY_GEOMETRY + ":Geometry:srid=4326";
- featureType = SimpleFeatureTypes.createType(FEATURE_NAME, featureSchema);
- dataStore.createSchema(featureType);
- }
- return featureType;
- }
-
- @Override
- public void storeStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
- // create a feature collection
- final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
- for (final RyaStatement ryaStatement : ryaStatements) {
- final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
- // if the predicate list is empty, accept all predicates.
- // Otherwise, make sure the predicate is on the "valid" list
- final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
-
- if (isValidPredicate && (statement.getObject() instanceof Literal)) {
- try {
- final SimpleFeature feature = createFeature(featureType, statement);
- featureCollection.add(feature);
- } catch (final ParseException e) {
- logger.warn("Error getting geo from statement: " + statement.toString(), e);
- }
- }
- }
-
- // write this feature collection to the store
- if (!featureCollection.isEmpty()) {
- featureStore.addFeatures(featureCollection);
- }
- }
-
-
- @Override
- public void storeStatement(final RyaStatement statement) throws IOException {
- storeStatements(Collections.singleton(statement));
- }
-
- private static SimpleFeature createFeature(final SimpleFeatureType featureType, final Statement statement) throws ParseException {
- final String subject = StatementSerializer.writeSubject(statement);
- final String predicate = StatementSerializer.writePredicate(statement);
- final String object = StatementSerializer.writeObject(statement);
- final String context = StatementSerializer.writeContext(statement);
-
- // create the feature
- final Object[] noValues = {};
-
- // create the hash
- final String statementId = Md5Hash.md5Base64(StatementSerializer.writeStatement(statement));
- final SimpleFeature newFeature = SimpleFeatureBuilder.build(featureType, noValues, statementId);
-
- // write the statement data to the fields
- final Geometry geom = GeoParseUtils.getGeometry(statement);
- if(geom == null || geom.isEmpty() || !geom.isValid()) {
- throw new ParseException("Could not create geometry for statement " + statement);
- }
- newFeature.setDefaultGeometry(geom);
-
- newFeature.setAttribute(SUBJECT_ATTRIBUTE, subject);
- newFeature.setAttribute(PREDICATE_ATTRIBUTE, predicate);
- newFeature.setAttribute(OBJECT_ATTRIBUTE, object);
- newFeature.setAttribute(CONTEXT_ATTRIBUTE, context);
-
- // preserve the ID that we created for this feature
- // (set the hint to FALSE to have GeoTools generate IDs)
- newFeature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);
-
- return newFeature;
- }
-
- private CloseableIteration<Statement, QueryEvaluationException> performQuery(final String type, final Geometry geometry,
- final StatementConstraints contraints) {
- final List<String> filterParms = new ArrayList<String>();
-
- filterParms.add(type + "(" + Constants.SF_PROPERTY_GEOMETRY + ", " + geometry + " )");
-
- if (contraints.hasSubject()) {
- filterParms.add("( " + SUBJECT_ATTRIBUTE + "= '" + contraints.getSubject() + "') ");
- }
- if (contraints.hasContext()) {
- filterParms.add("( " + CONTEXT_ATTRIBUTE + "= '" + contraints.getContext() + "') ");
- }
- if (contraints.hasPredicates()) {
- final List<String> predicates = new ArrayList<String>();
- for (final URI u : contraints.getPredicates()) {
- predicates.add("( " + PREDICATE_ATTRIBUTE + "= '" + u.stringValue() + "') ");
- }
- filterParms.add("(" + StringUtils.join(predicates, " OR ") + ")");
- }
-
- final String filterString = StringUtils.join(filterParms, " AND ");
- logger.info("Performing geomesa query : " + filterString);
-
- return getIteratorWrapper(filterString);
- }
-
- private CloseableIteration<Statement, QueryEvaluationException> getIteratorWrapper(final String filterString) {
-
- return new CloseableIteration<Statement, QueryEvaluationException>() {
-
- private FeatureIterator<SimpleFeature> featureIterator = null;
-
- FeatureIterator<SimpleFeature> getIterator() throws QueryEvaluationException {
- if (featureIterator == null) {
- Filter cqlFilter;
- try {
- cqlFilter = ECQL.toFilter(filterString);
- } catch (final CQLException e) {
- logger.error("Error parsing query: " + filterString, e);
- throw new QueryEvaluationException(e);
- }
-
- final Query query = new Query(featureType.getTypeName(), cqlFilter);
- try {
- featureIterator = featureSource.getFeatures(query).features();
- } catch (final IOException e) {
- logger.error("Error performing query: " + filterString, e);
- throw new QueryEvaluationException(e);
- }
-
- }
- return featureIterator;
- }
-
- @Override
- public boolean hasNext() throws QueryEvaluationException {
- return getIterator().hasNext();
- }
-
- @Override
- public Statement next() throws QueryEvaluationException {
- final SimpleFeature feature = getIterator().next();
- final String subjectString = feature.getAttribute(SUBJECT_ATTRIBUTE).toString();
- final String predicateString = feature.getAttribute(PREDICATE_ATTRIBUTE).toString();
- final String objectString = feature.getAttribute(OBJECT_ATTRIBUTE).toString();
- final String contextString = feature.getAttribute(CONTEXT_ATTRIBUTE).toString();
- final Statement statement = StatementSerializer.readStatement(subjectString, predicateString, objectString, contextString);
- return statement;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("Remove not implemented");
- }
-
- @Override
- public void close() throws QueryEvaluationException {
- getIterator().close();
- }
- };
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryEquals(final Geometry query, final StatementConstraints contraints) {
- return performQuery("EQUALS", query, contraints);
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryDisjoint(final Geometry query, final StatementConstraints contraints) {
- return performQuery("DISJOINT", query, contraints);
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryIntersects(final Geometry query, final StatementConstraints contraints) {
- return performQuery("INTERSECTS", query, contraints);
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryTouches(final Geometry query, final StatementConstraints contraints) {
- return performQuery("TOUCHES", query, contraints);
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryCrosses(final Geometry query, final StatementConstraints contraints) {
- return performQuery("CROSSES", query, contraints);
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryWithin(final Geometry query, final StatementConstraints contraints) {
- return performQuery("WITHIN", query, contraints);
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryContains(final Geometry query, final StatementConstraints contraints) {
- return performQuery("CONTAINS", query, contraints);
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryOverlaps(final Geometry query, final StatementConstraints contraints) {
- return performQuery("OVERLAPS", query, contraints);
- }
-
- @Override
- public Set<URI> getIndexablePredicates() {
- return validPredicates;
- }
-
- @Override
- public void flush() throws IOException {
- // TODO cache and flush features instead of writing them one at a time
- }
-
- @Override
- public void close() throws IOException {
- flush();
- }
-
-
- @Override
- public String getTableName() {
- return getTableName(conf);
- }
-
- /**
- * Get the Accumulo table that will be used by this index.
- * @param conf
- * @return table name guaranteed to be used by instances of this index
- */
- public static String getTableName(Configuration conf) {
- return ConfigUtils.getTablePrefix(conf) + TABLE_SUFFIX;
- }
-
- private void deleteStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
- // create a feature collection
- final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
-
- for (final RyaStatement ryaStatement : ryaStatements) {
- final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
- // if the predicate list is empty, accept all predicates.
- // Otherwise, make sure the predicate is on the "valid" list
- final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
-
- if (isValidPredicate && (statement.getObject() instanceof Literal)) {
- try {
- final SimpleFeature feature = createFeature(featureType, statement);
- featureCollection.add(feature);
- } catch (final ParseException e) {
- logger.warn("Error getting geo from statement: " + statement.toString(), e);
- }
- }
- }
-
- // remove this feature collection from the store
- if (!featureCollection.isEmpty()) {
- final Set<Identifier> featureIds = new HashSet<Identifier>();
- final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
- final Set<String> stringIds = DataUtilities.fidSet(featureCollection);
- for (final String id : stringIds) {
- featureIds.add(filterFactory.featureId(id));
- }
- final Filter filter = filterFactory.id(featureIds);
- featureStore.removeFeatures(filter);
- }
- }
-
-
- @Override
- public void deleteStatement(final RyaStatement statement) throws IOException {
- deleteStatements(Collections.singleton(statement));
- }
-
- @Override
- public void init() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void setConnector(final Connector connector) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void destroy() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void purge(final RdfCloudTripleStoreConfiguration configuration) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void dropAndDestroy() {
- // TODO Auto-generated method stub
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoParseUtils.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoParseUtils.java b/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoParseUtils.java
deleted file mode 100644
index 119f351..0000000
--- a/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoParseUtils.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package mvm.rya.indexing.accumulo.geo;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.StringReader;
-import java.nio.charset.StandardCharsets;
-
-import javax.xml.parsers.ParserConfigurationException;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import org.apache.log4j.Logger;
-import org.geotools.data.collection.ListFeatureCollection;
-import org.geotools.gml3.GMLConfiguration;
-import org.geotools.xml.Parser;
-import org.openrdf.model.Literal;
-import org.openrdf.model.Statement;
-import org.xml.sax.SAXException;
-
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.io.ParseException;
-import com.vividsolutions.jts.io.WKTReader;
-
-import mvm.rya.api.domain.RyaStatement;
-
-public class GeoParseUtils {
- static final Logger logger = Logger.getLogger(GeoParseUtils.class);
- /**
- * @deprecated Not needed since geo literals may be WKT or GML.
- *
- * This method warns on a condition that must already be tested. Replaced by
- * {@link #getLiteral(Statement)} and {@link #getGeometry(Statement}
- * and getLiteral(statement).toString()
- * and getLiteral(statement).getDatatype()
- */
- @Deprecated
- public static String getWellKnownText(Statement statement) throws ParseException {
- Literal lit = getLiteral(statement);
- if (!GeoConstants.XMLSCHEMA_OGC_WKT.equals(lit.getDatatype())) {
- logger.warn("Literal is not of type " + GeoConstants.XMLSCHEMA_OGC_WKT + ": " + statement.toString());
- }
- return lit.getLabel().toString();
- }
-
- public static Literal getLiteral(Statement statement) throws ParseException {
- org.openrdf.model.Value v = statement.getObject();
- if (!(v instanceof Literal)) {
- throw new ParseException("Statement does not contain Literal: " + statement.toString());
- }
- Literal lit = (Literal) v;
- return lit;
- }
-
- /**
- * Parse GML/wkt literal to Geometry
- *
- * @param statement
- * @return
- * @throws ParseException
- * @throws ParserConfigurationException
- * @throws SAXException
- * @throws IOException
- */
- public static Geometry getGeometry(Statement statement) throws ParseException {
- // handle GML or WKT
- Literal lit = getLiteral(statement);
- if (GeoConstants.XMLSCHEMA_OGC_WKT.equals(lit.getDatatype())) {
- final String wkt = lit.getLabel().toString();
- return (new WKTReader()).read(wkt);
- } else if (GeoConstants.XMLSCHEMA_OGC_GML.equals(lit.getDatatype())) {
- String gml = lit.getLabel().toString();
- try {
- return getGeometryGml(gml);
- } catch (IOException | SAXException | ParserConfigurationException e) {
- throw new ParseException(e);
- }
- } else {
- throw new ParseException("Literal is unknown geo type, expecting WKT or GML: " + statement.toString());
- }
- }
- /**
- * Convert GML/XML string into a geometry that can be indexed.
- * @param gmlString
- * @return
- * @throws IOException
- * @throws SAXException
- * @throws ParserConfigurationException
- */
- public static Geometry getGeometryGml(String gmlString) throws IOException, SAXException, ParserConfigurationException {
- Reader reader = new StringReader(gmlString);
- GMLConfiguration gmlConfiguration = new GMLConfiguration();
- Parser gmlParser = new Parser(gmlConfiguration);
- // gmlParser.setStrict(false); // attempt at allowing deprecated elements, but no.
- // gmlParser.setValidating(false);
- final Geometry geometry = (Geometry) gmlParser.parse(reader);
- // This sometimes gets populated with the SRS/CRS: geometry.getUserData()
- // Always returns 0 : geometry.getSRID()
- //TODO geometry.setUserData(some default CRS); OR geometry.setSRID(some default CRS)
-
- return geometry;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoTupleSet.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoTupleSet.java b/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoTupleSet.java
deleted file mode 100644
index d1468b8..0000000
--- a/extras/indexing/src/main/java/mvm/rya/indexing/accumulo/geo/GeoTupleSet.java
+++ /dev/null
@@ -1,362 +0,0 @@
-package mvm.rya.indexing.accumulo.geo;
-
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.hadoop.conf.Configuration;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.query.BindingSet;
-import org.openrdf.query.QueryEvaluationException;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.Maps;
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.io.ParseException;
-import com.vividsolutions.jts.io.WKTReader;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import info.aduna.iteration.CloseableIteration;
-import mvm.rya.indexing.GeoIndexer;
-import mvm.rya.indexing.IndexingExpr;
-import mvm.rya.indexing.IteratorFactory;
-import mvm.rya.indexing.SearchFunction;
-import mvm.rya.indexing.StatementConstraints;
-import mvm.rya.indexing.external.tupleSet.ExternalTupleSet;
-
-//Indexing Node for geo expressions to be inserted into execution plan
-//to delegate geo portion of query to geo index
-public class GeoTupleSet extends ExternalTupleSet {
-
- private final Configuration conf;
- private final GeoIndexer geoIndexer;
- private final IndexingExpr filterInfo;
-
-
- public GeoTupleSet(final IndexingExpr filterInfo, final GeoIndexer geoIndexer) {
- this.filterInfo = filterInfo;
- this.geoIndexer = geoIndexer;
- conf = geoIndexer.getConf();
- }
-
- @Override
- public Set<String> getBindingNames() {
- return filterInfo.getBindingNames();
- }
-
- @Override
- public GeoTupleSet clone() {
- return new GeoTupleSet(filterInfo, geoIndexer);
- }
-
- @Override
- public double cardinality() {
- return 0.0; // No idea how the estimate cardinality here.
- }
-
-
- @Override
- public String getSignature() {
- return "(GeoTuple Projection) " + "variables: " + Joiner.on(", ").join(getBindingNames()).replaceAll("\\s+", " ");
- }
-
-
-
- @Override
- public boolean equals(final Object other) {
- if (other == this) {
- return true;
- }
- if (!(other instanceof GeoTupleSet)) {
- return false;
- }
- final GeoTupleSet arg = (GeoTupleSet) other;
- return filterInfo.equals(arg.filterInfo);
- }
-
- @Override
- public int hashCode() {
- int result = 17;
- result = 31*result + filterInfo.hashCode();
-
- return result;
- }
-
-
-
- /**
- * Returns an iterator over the result set of the contained IndexingExpr.
- * <p>
- * Should be thread-safe (concurrent invocation {@link OfflineIterable} this
- * method can be expected with some query evaluators.
- */
- @Override
- public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings)
- throws QueryEvaluationException {
-
-
- final URI funcURI = filterInfo.getFunction();
- final SearchFunction searchFunction = new GeoSearchFunctionFactory(conf).getSearchFunction(funcURI);
- if(filterInfo.getArguments().length > 1) {
- throw new IllegalArgumentException("Index functions do not support more than two arguments.");
- }
-
- final String queryText = filterInfo.getArguments()[0].stringValue();
-
- return IteratorFactory.getIterator(filterInfo.getSpConstraint(), bindings, queryText, searchFunction);
- }
-
-
-
- //returns appropriate search function for a given URI
- //search functions used in GeoMesaGeoIndexer to access index
- public class GeoSearchFunctionFactory {
-
- Configuration conf;
-
- private final Map<URI, SearchFunction> SEARCH_FUNCTION_MAP = Maps.newHashMap();
-
- public GeoSearchFunctionFactory(final Configuration conf) {
- this.conf = conf;
- }
-
-
- /**
- * Get a {@link GeoSearchFunction} for a given URI.
- *
- * @param searchFunction
- * @return
- */
- public SearchFunction getSearchFunction(final URI searchFunction) {
-
- SearchFunction geoFunc = null;
-
- try {
- geoFunc = getSearchFunctionInternal(searchFunction);
- } catch (final QueryEvaluationException e) {
- e.printStackTrace();
- }
-
- return geoFunc;
- }
-
- private SearchFunction getSearchFunctionInternal(final URI searchFunction) throws QueryEvaluationException {
- final SearchFunction sf = SEARCH_FUNCTION_MAP.get(searchFunction);
-
- if (sf != null) {
- return sf;
- } else {
- throw new QueryEvaluationException("Unknown Search Function: " + searchFunction.stringValue());
- }
- }
-
- private final SearchFunction GEO_EQUALS = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
- final StatementConstraints contraints) throws QueryEvaluationException {
- try {
- final WKTReader reader = new WKTReader();
- final Geometry geometry = reader.read(queryText);
- final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (final ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_EQUALS";
- };
- };
-
- private final SearchFunction GEO_DISJOINT = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
- final StatementConstraints contraints) throws QueryEvaluationException {
- try {
- final WKTReader reader = new WKTReader();
- final Geometry geometry = reader.read(queryText);
- final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (final ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_DISJOINT";
- };
- };
-
- private final SearchFunction GEO_INTERSECTS = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
- final StatementConstraints contraints) throws QueryEvaluationException {
- try {
- final WKTReader reader = new WKTReader();
- final Geometry geometry = reader.read(queryText);
- final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (final ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_INTERSECTS";
- };
- };
-
- private final SearchFunction GEO_TOUCHES = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
- final StatementConstraints contraints) throws QueryEvaluationException {
- try {
- final WKTReader reader = new WKTReader();
- final Geometry geometry = reader.read(queryText);
- final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (final ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_TOUCHES";
- };
- };
-
- private final SearchFunction GEO_CONTAINS = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
- final StatementConstraints contraints) throws QueryEvaluationException {
- try {
- final WKTReader reader = new WKTReader();
- final Geometry geometry = reader.read(queryText);
- final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (final ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_CONTAINS";
- };
- };
-
- private final SearchFunction GEO_OVERLAPS = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
- final StatementConstraints contraints) throws QueryEvaluationException {
- try {
- final WKTReader reader = new WKTReader();
- final Geometry geometry = reader.read(queryText);
- final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (final ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_OVERLAPS";
- };
- };
-
- private final SearchFunction GEO_CROSSES = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
- final StatementConstraints contraints) throws QueryEvaluationException {
- try {
- final WKTReader reader = new WKTReader();
- final Geometry geometry = reader.read(queryText);
- final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (final ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_CROSSES";
- };
- };
-
- private final SearchFunction GEO_WITHIN = new SearchFunction() {
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
- final StatementConstraints contraints) throws QueryEvaluationException {
- try {
- final WKTReader reader = new WKTReader();
- final Geometry geometry = reader.read(queryText);
- final CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin(
- geometry, contraints);
- return statements;
- } catch (final ParseException e) {
- throw new QueryEvaluationException(e);
- }
- }
-
- @Override
- public String toString() {
- return "GEO_WITHIN";
- };
- };
-
- {
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_EQUALS, GEO_EQUALS);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_DISJOINT, GEO_DISJOINT);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_INTERSECTS, GEO_INTERSECTS);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_TOUCHES, GEO_TOUCHES);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_CONTAINS, GEO_CONTAINS);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_OVERLAPS, GEO_OVERLAPS);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_CROSSES, GEO_CROSSES);
- SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_WITHIN, GEO_WITHIN);
- }
-
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/GeoMongoDBStorageStrategy.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/GeoMongoDBStorageStrategy.java b/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/GeoMongoDBStorageStrategy.java
deleted file mode 100644
index 9411330..0000000
--- a/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/GeoMongoDBStorageStrategy.java
+++ /dev/null
@@ -1,143 +0,0 @@
-package mvm.rya.indexing.mongodb.geo;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.openrdf.model.Statement;
-
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBCollection;
-import com.mongodb.DBObject;
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.io.ParseException;
-import com.vividsolutions.jts.io.WKTReader;
-
-import mvm.rya.api.domain.RyaStatement;
-import mvm.rya.api.resolver.RyaToRdfConversions;
-import mvm.rya.indexing.accumulo.geo.GeoParseUtils;
-import mvm.rya.indexing.mongodb.IndexingMongoDBStorageStrategy;
-
-public class GeoMongoDBStorageStrategy extends IndexingMongoDBStorageStrategy {
- private static final Logger LOG = Logger.getLogger(GeoMongoDBStorageStrategy.class);
-
- private static final String GEO = "location";
- public enum GeoQueryType {
- INTERSECTS {
- @Override
- public String getKeyword() {
- return "$geoIntersects";
- }
- }, WITHIN {
- @Override
- public String getKeyword() {
- return "$geoWithin";
- }
- },
- EQUALS {
- @Override
- public String getKeyword() {
- return "$near";
- }
- };
-
- public abstract String getKeyword();
- }
-
- static class GeoQuery {
- private final GeoQueryType queryType;
- private final Geometry geo;
-
- public GeoQuery(final GeoQueryType queryType, final Geometry geo) {
- this.queryType = queryType;
- this.geo = geo;
- }
-
- public GeoQueryType getQueryType() {
- return queryType;
- }
- public Geometry getGeo() {
- return geo;
- }
- }
-
- private final double maxDistance;
-
- public GeoMongoDBStorageStrategy(final double maxDistance) {
- this.maxDistance = maxDistance;
- }
-
- @Override
- public void createIndices(final DBCollection coll){
- coll.createIndex("{" + GEO + " : \"2dsphere\"" );
- }
-
- public DBObject getQuery(final GeoQuery queryObj) {
- final Geometry geo = queryObj.getGeo();
- final GeoQueryType queryType = queryObj.getQueryType();
-
- BasicDBObject query;
- if (queryType.equals(GeoQueryType.EQUALS)){
- final List<double[]> points = getCorrespondingPoints(geo);
- if (points.size() == 1){
- final List circle = new ArrayList();
- circle.add(points.get(0));
- circle.add(maxDistance);
- final BasicDBObject polygon = new BasicDBObject("$centerSphere", circle);
- query = new BasicDBObject(GEO, new BasicDBObject(GeoQueryType.WITHIN.getKeyword(), polygon));
- } else {
- query = new BasicDBObject(GEO, points);
- }
- } else {
- query = new BasicDBObject(GEO, new BasicDBObject(queryType.getKeyword(), new BasicDBObject("$polygon", getCorrespondingPoints(geo))));
- }
-
- return query;
- }
-
- @Override
- public DBObject serialize(final RyaStatement ryaStatement) {
- // if the object is wkt, then try to index it
- // write the statement data to the fields
- try {
- final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
- final Geometry geo = (new WKTReader()).read(GeoParseUtils.getWellKnownText(statement));
- final BasicDBObject base = (BasicDBObject) super.serialize(ryaStatement);
- base.append(GEO, getCorrespondingPoints(geo));
- return base;
- } catch(final ParseException e) {
- LOG.error("Could not create geometry for statement " + ryaStatement, e);
- return null;
- }
- }
-
- private List<double[]> getCorrespondingPoints(final Geometry geo){
- final List<double[]> points = new ArrayList<double[]>();
- for (final Coordinate coord : geo.getCoordinates()){
- points.add(new double[] {
- coord.x, coord.y
- });
- }
- return points;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/7727b165/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoIndexer.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoIndexer.java b/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoIndexer.java
deleted file mode 100644
index 7589f03..0000000
--- a/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/geo/MongoGeoIndexer.java
+++ /dev/null
@@ -1,112 +0,0 @@
-package mvm.rya.indexing.mongodb.geo;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static mvm.rya.indexing.mongodb.geo.GeoMongoDBStorageStrategy.GeoQueryType.EQUALS;
-import static mvm.rya.indexing.mongodb.geo.GeoMongoDBStorageStrategy.GeoQueryType.INTERSECTS;
-import static mvm.rya.indexing.mongodb.geo.GeoMongoDBStorageStrategy.GeoQueryType.WITHIN;
-
-import org.apache.log4j.Logger;
-import org.openrdf.model.Statement;
-import org.openrdf.query.QueryEvaluationException;
-
-import com.mongodb.DBObject;
-import com.vividsolutions.jts.geom.Geometry;
-
-import info.aduna.iteration.CloseableIteration;
-import mvm.rya.indexing.GeoIndexer;
-import mvm.rya.indexing.StatementConstraints;
-import mvm.rya.indexing.accumulo.ConfigUtils;
-import mvm.rya.indexing.mongodb.AbstractMongoIndexer;
-import mvm.rya.indexing.mongodb.geo.GeoMongoDBStorageStrategy.GeoQuery;
-import mvm.rya.mongodb.MongoDBRdfConfiguration;
-
-public class MongoGeoIndexer extends AbstractMongoIndexer<GeoMongoDBStorageStrategy> implements GeoIndexer {
- private static final String COLLECTION_SUFFIX = "geo";
- private static final Logger logger = Logger.getLogger(MongoGeoIndexer.class);
-
- @Override
- public void init() {
- initCore();
- predicates = ConfigUtils.getGeoPredicates(conf);
- storageStrategy = new GeoMongoDBStorageStrategy(Double.valueOf(conf.get(MongoDBRdfConfiguration.MONGO_GEO_MAXDISTANCE, "1e-10")));
- storageStrategy.createIndices(collection);
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryEquals(
- final Geometry query, final StatementConstraints constraints) {
- final DBObject queryObj = storageStrategy.getQuery(new GeoQuery(EQUALS, query));
- return withConstraints(constraints, queryObj);
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryDisjoint(
- final Geometry query, final StatementConstraints constraints) {
- throw new UnsupportedOperationException(
- "Disjoint queries are not supported in Mongo DB.");
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryIntersects(
- final Geometry query, final StatementConstraints constraints) {
- final DBObject queryObj = storageStrategy.getQuery(new GeoQuery(INTERSECTS, query));
- return withConstraints(constraints, queryObj);
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryTouches(
- final Geometry query, final StatementConstraints constraints) {
- throw new UnsupportedOperationException(
- "Touches queries are not supported in Mongo DB.");
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryCrosses(
- final Geometry query, final StatementConstraints constraints) {
- throw new UnsupportedOperationException(
- "Crosses queries are not supported in Mongo DB.");
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryWithin(
- final Geometry query, final StatementConstraints constraints) {
- final DBObject queryObj = storageStrategy.getQuery(new GeoQuery(WITHIN, query));
- return withConstraints(constraints, queryObj);
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryContains(
- final Geometry query, final StatementConstraints constraints) {
- throw new UnsupportedOperationException(
- "Contains queries are not supported in Mongo DB.");
- }
-
- @Override
- public CloseableIteration<Statement, QueryEvaluationException> queryOverlaps(
- final Geometry query, final StatementConstraints constraints) {
- throw new UnsupportedOperationException(
- "Overlaps queries are not supported in Mongo DB.");
- }
-
- @Override
- public String getCollectionName() {
- return ConfigUtils.getTablePrefix(conf) + COLLECTION_SUFFIX;
- }
-}
\ No newline at end of file
[6/6] incubator-rya git commit: RYA-177 removing unreferenced jars
Posted by mi...@apache.org.
RYA-177 removing unreferenced jars
closes #101
Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/59570b4f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/59570b4f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/59570b4f
Branch: refs/heads/master
Commit: 59570b4f7d8afbdfbd06308dbe082de6edf762c7
Parents: 7727b16
Author: pujav65 <pu...@gmail.com>
Authored: Fri Oct 7 11:57:22 2016 -0400
Committer: Aaron Mihalik <mi...@alum.mit.edu>
Committed: Wed Oct 12 16:26:45 2016 -0400
----------------------------------------------------------------------
extras/indexing/pom.xml | 5 -----
extras/indexingExample/pom.xml | 5 -----
2 files changed, 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/59570b4f/extras/indexing/pom.xml
----------------------------------------------------------------------
diff --git a/extras/indexing/pom.xml b/extras/indexing/pom.xml
index 8e21879..32e9ef2 100644
--- a/extras/indexing/pom.xml
+++ b/extras/indexing/pom.xml
@@ -106,11 +106,6 @@
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
- <dependency>
- <groupId>com.vividsolutions</groupId>
- <artifactId>jts</artifactId>
- <version>1.13</version>
- </dependency>
</dependencies>
<build>
<pluginManagement>
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/59570b4f/extras/indexingExample/pom.xml
----------------------------------------------------------------------
diff --git a/extras/indexingExample/pom.xml b/extras/indexingExample/pom.xml
index 58689de..212210e 100644
--- a/extras/indexingExample/pom.xml
+++ b/extras/indexingExample/pom.xml
@@ -59,11 +59,6 @@ under the License.
<groupId>org.apache.accumulo</groupId>
<artifactId>accumulo-core</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.locationtech.geomesa</groupId>
- <artifactId>geomesa-accumulo-distributed-runtime</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.accumulo</groupId>