You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/05/14 17:22:00 UTC
[04/40] jena git commit: Fix line endings
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-maven-tools/src/test/java/org/apache/jena/tools/schemagen/SchemagenMojoTest.java
----------------------------------------------------------------------
diff --git a/jena-maven-tools/src/test/java/org/apache/jena/tools/schemagen/SchemagenMojoTest.java b/jena-maven-tools/src/test/java/org/apache/jena/tools/schemagen/SchemagenMojoTest.java
index 132010a..8df6faf 100644
--- a/jena-maven-tools/src/test/java/org/apache/jena/tools/schemagen/SchemagenMojoTest.java
+++ b/jena-maven-tools/src/test/java/org/apache/jena/tools/schemagen/SchemagenMojoTest.java
@@ -1,83 +1,83 @@
-/**
- * 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 org.apache.jena.tools.schemagen;
-
-// Imports
-///////////////
-
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.util.List;
-
-import org.junit.Test;
-import org.apache.jena.tools.schemagen.SchemagenMojo;
-
-/**
- * <p>Unit tests for {@link SchemagenMojo}</p>
- */
-public class SchemagenMojoTest {
-
- @Test
- public void testMatchFileNames0() {
- SchemagenMojo sm = new SchemagenMojo();
-
- List<String> s = sm.matchFileNames();
- assertNotNull(s);
- assertTrue( s.isEmpty() );
- }
-
- @Test
- public void testMatchFileNames1() {
- SchemagenMojo sm = new SchemagenMojo();
- String f = "src/test/resources/test1/test1.ttl";
- sm.addIncludes( f );
- List<String> s = sm.matchFileNames();
- assertNotNull(s);
- assertEquals( 1, s.size() );
- assertEquals( new File(f), new File(s.get(0)) );
- }
-
- @Test
- public void testMatchFileNames2() {
- SchemagenMojo sm = new SchemagenMojo();
- String f = "src/test/resources/test1/*.ttl";
- sm.addIncludes( f );
- List<String> s = sm.matchFileNames();
- assertNotNull(s);
- assertEquals( 2, s.size() );
- assertTrue( s.get(0).endsWith( "test1.ttl" ));
- assertTrue( s.get(1).endsWith( "test2.ttl" ));
- }
-
- @Test
- public void testMatchFileNames3() {
- SchemagenMojo sm = new SchemagenMojo();
- String f = "src/test/resources/test1/*.ttl";
- sm.addIncludes( f );
- sm.addExcludes( "src/test/resources/test1/test1.ttl" );
-
- List<String> s = sm.matchFileNames();
- assertNotNull(s);
- assertEquals( 1, s.size() );
- assertTrue( s.get(0).endsWith( "test2.ttl" ));
- }
-
-
-}
+/**
+ * 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 org.apache.jena.tools.schemagen;
+
+// Imports
+///////////////
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.List;
+
+import org.junit.Test;
+import org.apache.jena.tools.schemagen.SchemagenMojo;
+
+/**
+ * <p>Unit tests for {@link SchemagenMojo}</p>
+ */
+public class SchemagenMojoTest {
+
+ @Test
+ public void testMatchFileNames0() {
+ SchemagenMojo sm = new SchemagenMojo();
+
+ List<String> s = sm.matchFileNames();
+ assertNotNull(s);
+ assertTrue( s.isEmpty() );
+ }
+
+ @Test
+ public void testMatchFileNames1() {
+ SchemagenMojo sm = new SchemagenMojo();
+ String f = "src/test/resources/test1/test1.ttl";
+ sm.addIncludes( f );
+ List<String> s = sm.matchFileNames();
+ assertNotNull(s);
+ assertEquals( 1, s.size() );
+ assertEquals( new File(f), new File(s.get(0)) );
+ }
+
+ @Test
+ public void testMatchFileNames2() {
+ SchemagenMojo sm = new SchemagenMojo();
+ String f = "src/test/resources/test1/*.ttl";
+ sm.addIncludes( f );
+ List<String> s = sm.matchFileNames();
+ assertNotNull(s);
+ assertEquals( 2, s.size() );
+ assertTrue( s.get(0).endsWith( "test1.ttl" ));
+ assertTrue( s.get(1).endsWith( "test2.ttl" ));
+ }
+
+ @Test
+ public void testMatchFileNames3() {
+ SchemagenMojo sm = new SchemagenMojo();
+ String f = "src/test/resources/test1/*.ttl";
+ sm.addIncludes( f );
+ sm.addExcludes( "src/test/resources/test1/test1.ttl" );
+
+ List<String> s = sm.matchFileNames();
+ assertNotNull(s);
+ assertEquals( 1, s.size() );
+ assertTrue( s.get(0).endsWith( "test2.ttl" ));
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-spatial/src/main/java/org/apache/jena/query/spatial/DistanceUnitsUtils.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/DistanceUnitsUtils.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/DistanceUnitsUtils.java
index d201f3b..1cd19de 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/DistanceUnitsUtils.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/DistanceUnitsUtils.java
@@ -1,87 +1,87 @@
-/*
- * 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 org.apache.jena.query.spatial;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.spatial4j.core.distance.DistanceUtils;
-
-public class DistanceUnitsUtils {
-
- public final static String defaultDistanceUnit = "kilometres" ;
-
- public final static List<String> SUPPORTED_UNITS;
- static {
- // International spelling "metres"
- // As used by http://en.wikipedia.org/wiki/International_Bureau_of_Weights_and_Measures
- SUPPORTED_UNITS = new ArrayList<String>();
- SUPPORTED_UNITS.add("kilometres");
- SUPPORTED_UNITS.add("kilometers"); // America spelling
- SUPPORTED_UNITS.add("km");
- SUPPORTED_UNITS.add("meters");
- SUPPORTED_UNITS.add("metres");
- SUPPORTED_UNITS.add("m");
- SUPPORTED_UNITS.add("centimeters");
- SUPPORTED_UNITS.add("centimetres");
- SUPPORTED_UNITS.add("cm");
- SUPPORTED_UNITS.add("millimetres");
- SUPPORTED_UNITS.add("millimeters");
- SUPPORTED_UNITS.add("mm");
- SUPPORTED_UNITS.add("miles");
- SUPPORTED_UNITS.add("mi");
- SUPPORTED_UNITS.add("degrees");
- SUPPORTED_UNITS.add("de");
- }
-
- public static double dist2Degrees(double dist, String units) {
- double degrees = dist;
-
- if (units.equals("kilometers") || units.equals("kilometres") || units.equals("km"))
- return DistanceUtils.dist2Degrees(dist,
- DistanceUtils.EARTH_MEAN_RADIUS_KM);
-
- else if (units.equals("meters") || units.equals("metres") || units.equals("m"))
- return DistanceUtils.dist2Degrees(dist / 1000,
- DistanceUtils.EARTH_MEAN_RADIUS_KM);
-
- else if (units.equals("centimeters") || units.equals("centimetres") || units.equals("cm"))
- return DistanceUtils.dist2Degrees(dist / (1000 * 100),
- DistanceUtils.EARTH_MEAN_RADIUS_KM) ;
-
- else if ( units.equals("millimeters") || units.equals("millimetres") || units.equals("mm") ||
- units.equals("milimeters") || units.equals("milimetres") ) // Common spelling mistake.
- return DistanceUtils.dist2Degrees(dist / (1000 * 1000),
- DistanceUtils.EARTH_MEAN_RADIUS_KM) ;
-
- else if (units.equals("miles") || units.equals("mi"))
- return DistanceUtils.dist2Degrees(dist,
- DistanceUtils.EARTH_MEAN_RADIUS_MI);
-
- else if (units.equals("degrees") || units.equals("de"))
- return degrees;
-
- throw new IllegalArgumentException("unknow distance units: "+ units);
- }
-
- public static boolean isSupportedUnits(String units){
- return SUPPORTED_UNITS.contains(units);
- }
-
-}
+/*
+ * 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 org.apache.jena.query.spatial;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.spatial4j.core.distance.DistanceUtils;
+
+public class DistanceUnitsUtils {
+
+ public final static String defaultDistanceUnit = "kilometres" ;
+
+ public final static List<String> SUPPORTED_UNITS;
+ static {
+ // International spelling "metres"
+ // As used by http://en.wikipedia.org/wiki/International_Bureau_of_Weights_and_Measures
+ SUPPORTED_UNITS = new ArrayList<String>();
+ SUPPORTED_UNITS.add("kilometres");
+ SUPPORTED_UNITS.add("kilometers"); // America spelling
+ SUPPORTED_UNITS.add("km");
+ SUPPORTED_UNITS.add("meters");
+ SUPPORTED_UNITS.add("metres");
+ SUPPORTED_UNITS.add("m");
+ SUPPORTED_UNITS.add("centimeters");
+ SUPPORTED_UNITS.add("centimetres");
+ SUPPORTED_UNITS.add("cm");
+ SUPPORTED_UNITS.add("millimetres");
+ SUPPORTED_UNITS.add("millimeters");
+ SUPPORTED_UNITS.add("mm");
+ SUPPORTED_UNITS.add("miles");
+ SUPPORTED_UNITS.add("mi");
+ SUPPORTED_UNITS.add("degrees");
+ SUPPORTED_UNITS.add("de");
+ }
+
+ public static double dist2Degrees(double dist, String units) {
+ double degrees = dist;
+
+ if (units.equals("kilometers") || units.equals("kilometres") || units.equals("km"))
+ return DistanceUtils.dist2Degrees(dist,
+ DistanceUtils.EARTH_MEAN_RADIUS_KM);
+
+ else if (units.equals("meters") || units.equals("metres") || units.equals("m"))
+ return DistanceUtils.dist2Degrees(dist / 1000,
+ DistanceUtils.EARTH_MEAN_RADIUS_KM);
+
+ else if (units.equals("centimeters") || units.equals("centimetres") || units.equals("cm"))
+ return DistanceUtils.dist2Degrees(dist / (1000 * 100),
+ DistanceUtils.EARTH_MEAN_RADIUS_KM) ;
+
+ else if ( units.equals("millimeters") || units.equals("millimetres") || units.equals("mm") ||
+ units.equals("milimeters") || units.equals("milimetres") ) // Common spelling mistake.
+ return DistanceUtils.dist2Degrees(dist / (1000 * 1000),
+ DistanceUtils.EARTH_MEAN_RADIUS_KM) ;
+
+ else if (units.equals("miles") || units.equals("mi"))
+ return DistanceUtils.dist2Degrees(dist,
+ DistanceUtils.EARTH_MEAN_RADIUS_MI);
+
+ else if (units.equals("degrees") || units.equals("de"))
+ return degrees;
+
+ throw new IllegalArgumentException("unknow distance units: "+ units);
+ }
+
+ public static boolean isSupportedUnits(String units){
+ return SUPPORTED_UNITS.contains(units);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialDatasetFactory.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialDatasetFactory.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialDatasetFactory.java
index 9d0c8d5..1c919f6 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialDatasetFactory.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialDatasetFactory.java
@@ -1,105 +1,105 @@
-/*
- * 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 org.apache.jena.query.spatial;
-
-import org.apache.jena.query.Dataset ;
-import org.apache.jena.query.DatasetFactory ;
-import org.apache.jena.query.spatial.assembler.SpatialVocab;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
-import org.apache.jena.sparql.util.Context ;
-import org.apache.jena.system.JenaSystem ;
-import org.apache.lucene.store.Directory;
-import org.apache.solr.client.solrj.SolrServer;
-
-public class SpatialDatasetFactory
-{
- static { JenaSystem.init(); }
-
- /** Use an assembler file to build a dataset with spatial search capabilities */
- public static Dataset create(String assemblerFile)
- {
- return (Dataset)AssemblerUtils.build(assemblerFile, SpatialVocab.spatialDataset) ;
- }
-
- /** Create a text-indexed dataset */
- public static Dataset create(Dataset base, SpatialIndex textIndex)
- {
- DatasetGraph dsg = base.asDatasetGraph() ;
- dsg = create(dsg, textIndex) ;
- return DatasetFactory.wrap(dsg) ;
- }
-
-
- /** Create a text-indexed dataset */
- public static DatasetGraph create(DatasetGraph dsg, SpatialIndex spatialIndex)
- {
- SpatialDocProducer producer = new SpatialDocProducerTriples(spatialIndex) ;
- DatasetGraph dsgt = new DatasetGraphSpatial(dsg, spatialIndex, producer) ;
- // Also set on dsg
- Context c = dsgt.getContext() ;
-
- dsgt.getContext().set(SpatialQuery.spatialIndex, spatialIndex) ;
- return dsgt ;
-
- }
-
- /** Create a Lucene TextIndex */
- public static SpatialIndex createLuceneIndex(Directory directory, EntityDefinition entMap)
- {
- SpatialIndex index = new SpatialIndexLucene(directory, entMap) ;
- return index ;
- }
-
- /** Create a text-indexed dataset, using Lucene */
- public static Dataset createLucene(Dataset base, Directory directory, EntityDefinition entMap)
- {
- SpatialIndex index = createLuceneIndex(directory, entMap) ;
- return create(base, index) ;
- }
-
- /** Create a text-indexed dataset, using Lucene */
- public static DatasetGraph createLucene(DatasetGraph base, Directory directory, EntityDefinition entMap)
- {
- SpatialIndex index = createLuceneIndex(directory, entMap) ;
- return create(base, index) ;
- }
-
- /** Create a Solr TextIndex */
- public static SpatialIndex createSolrIndex(SolrServer server, EntityDefinition entMap)
- {
- SpatialIndex index = new SpatialIndexSolr(server, entMap) ;
- return index ;
- }
-
- /** Create a text-indexed dataset, using Solr */
- public static Dataset createSolrIndex(Dataset base, SolrServer server, EntityDefinition entMap)
- {
- SpatialIndex index = createSolrIndex(server, entMap) ;
- return create(base, index) ;
- }
-
- /** Create a text-indexed dataset, using Solr */
- public static DatasetGraph createSolrIndex(DatasetGraph base, SolrServer server, EntityDefinition entMap)
- {
- SpatialIndex index = createSolrIndex(server, entMap) ;
- return create(base, index) ;
- }
-}
-
+/*
+ * 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 org.apache.jena.query.spatial;
+
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.DatasetFactory ;
+import org.apache.jena.query.spatial.assembler.SpatialVocab;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
+import org.apache.jena.sparql.util.Context ;
+import org.apache.jena.system.JenaSystem ;
+import org.apache.lucene.store.Directory;
+import org.apache.solr.client.solrj.SolrServer;
+
+public class SpatialDatasetFactory
+{
+ static { JenaSystem.init(); }
+
+ /** Use an assembler file to build a dataset with spatial search capabilities */
+ public static Dataset create(String assemblerFile)
+ {
+ return (Dataset)AssemblerUtils.build(assemblerFile, SpatialVocab.spatialDataset) ;
+ }
+
+ /** Create a text-indexed dataset */
+ public static Dataset create(Dataset base, SpatialIndex textIndex)
+ {
+ DatasetGraph dsg = base.asDatasetGraph() ;
+ dsg = create(dsg, textIndex) ;
+ return DatasetFactory.wrap(dsg) ;
+ }
+
+
+ /** Create a text-indexed dataset */
+ public static DatasetGraph create(DatasetGraph dsg, SpatialIndex spatialIndex)
+ {
+ SpatialDocProducer producer = new SpatialDocProducerTriples(spatialIndex) ;
+ DatasetGraph dsgt = new DatasetGraphSpatial(dsg, spatialIndex, producer) ;
+ // Also set on dsg
+ Context c = dsgt.getContext() ;
+
+ dsgt.getContext().set(SpatialQuery.spatialIndex, spatialIndex) ;
+ return dsgt ;
+
+ }
+
+ /** Create a Lucene TextIndex */
+ public static SpatialIndex createLuceneIndex(Directory directory, EntityDefinition entMap)
+ {
+ SpatialIndex index = new SpatialIndexLucene(directory, entMap) ;
+ return index ;
+ }
+
+ /** Create a text-indexed dataset, using Lucene */
+ public static Dataset createLucene(Dataset base, Directory directory, EntityDefinition entMap)
+ {
+ SpatialIndex index = createLuceneIndex(directory, entMap) ;
+ return create(base, index) ;
+ }
+
+ /** Create a text-indexed dataset, using Lucene */
+ public static DatasetGraph createLucene(DatasetGraph base, Directory directory, EntityDefinition entMap)
+ {
+ SpatialIndex index = createLuceneIndex(directory, entMap) ;
+ return create(base, index) ;
+ }
+
+ /** Create a Solr TextIndex */
+ public static SpatialIndex createSolrIndex(SolrServer server, EntityDefinition entMap)
+ {
+ SpatialIndex index = new SpatialIndexSolr(server, entMap) ;
+ return index ;
+ }
+
+ /** Create a text-indexed dataset, using Solr */
+ public static Dataset createSolrIndex(Dataset base, SolrServer server, EntityDefinition entMap)
+ {
+ SpatialIndex index = createSolrIndex(server, entMap) ;
+ return create(base, index) ;
+ }
+
+ /** Create a text-indexed dataset, using Solr */
+ public static DatasetGraph createSolrIndex(DatasetGraph base, SolrServer server, EntityDefinition entMap)
+ {
+ SpatialIndex index = createSolrIndex(server, entMap) ;
+ return create(base, index) ;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexContext.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexContext.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexContext.java
index 5d25d19..36a6801 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexContext.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexContext.java
@@ -1,103 +1,103 @@
-/*
- * 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 org.apache.jena.query.spatial;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.graph.Node ;
-
-import com.spatial4j.core.shape.Shape;
-
-public class SpatialIndexContext {
-
- private final EntityDefinition defn;
- private final SpatialIndex indexer;
- private final Map<String, Set<SpatialPredicatePairValue>> spatialPredicatePairValues;
-
- public SpatialIndexContext(SpatialIndex indexer) {
- super();
- this.defn = indexer.getDocDef();
- this.indexer = indexer;
- this.spatialPredicatePairValues = new HashMap<String, Set<SpatialPredicatePairValue>>();
- }
-
- public void index(Node g, Node s, Node p, Node o) {
-
- if (!o.isLiteral()) {
- return;
- }
-
- String x = SpatialQueryFuncs.subjectToString(s) ;
- Log.info(getClass(), "Subject: "+x) ;
-
- if (defn.isSpatialPredicate(p) && SpatialValueUtil.isDecimal(o)) {
-
- boolean isLat = defn.isLatitudePredicate(p);
-
- SpatialPredicatePair pair = defn.getSpatialPredicatePair(p);
- Set<SpatialPredicatePairValue> pairValues = spatialPredicatePairValues
- .get(x);
- if (pairValues == null) {
- pairValues = new HashSet<SpatialPredicatePairValue>();
- spatialPredicatePairValues.put(x, pairValues);
- }
-
- Iterator<SpatialPredicatePairValue> it = pairValues.iterator();
- SpatialPredicatePairValue toRemove = null;
-
- while (it.hasNext()) {
- SpatialPredicatePairValue pairValue = it.next();
- if (pairValue.getPair().equals(pair)) {
- Double theOtherValue = pairValue.getTheOtherValue(p);
- if (theOtherValue != null) {
- if (isLat) {
- indexer.add(x, SpatialQuery.ctx.makePoint(
- theOtherValue,
- Double.parseDouble(o.getLiteralLexicalForm())));
- } else {
- indexer.add(x, SpatialQuery.ctx.makePoint(Double.parseDouble(o.getLiteralLexicalForm()),
- theOtherValue));
- }
- toRemove = pairValue;
- }
- break;
- }
- }
- if (toRemove != null) {
- pairValues.remove(toRemove);
- return;
- }
-
- SpatialPredicatePairValue toAdd = new SpatialPredicatePairValue(
- pair);
- toAdd.setValue(p, Double.parseDouble(o.getLiteralLexicalForm()));
- pairValues.add(toAdd);
-
- } else if (defn.isWKTPredicate(p) && SpatialValueUtil.isWKTLiteral(o.getLiteral())) {
- @SuppressWarnings("deprecation")
- Shape shape = SpatialQuery.ctx.readShape(o.getLiteralLexicalForm());
- indexer.add(x, shape);
- }
- }
-}
+/*
+ * 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 org.apache.jena.query.spatial;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.graph.Node ;
+
+import com.spatial4j.core.shape.Shape;
+
+public class SpatialIndexContext {
+
+ private final EntityDefinition defn;
+ private final SpatialIndex indexer;
+ private final Map<String, Set<SpatialPredicatePairValue>> spatialPredicatePairValues;
+
+ public SpatialIndexContext(SpatialIndex indexer) {
+ super();
+ this.defn = indexer.getDocDef();
+ this.indexer = indexer;
+ this.spatialPredicatePairValues = new HashMap<String, Set<SpatialPredicatePairValue>>();
+ }
+
+ public void index(Node g, Node s, Node p, Node o) {
+
+ if (!o.isLiteral()) {
+ return;
+ }
+
+ String x = SpatialQueryFuncs.subjectToString(s) ;
+ Log.info(getClass(), "Subject: "+x) ;
+
+ if (defn.isSpatialPredicate(p) && SpatialValueUtil.isDecimal(o)) {
+
+ boolean isLat = defn.isLatitudePredicate(p);
+
+ SpatialPredicatePair pair = defn.getSpatialPredicatePair(p);
+ Set<SpatialPredicatePairValue> pairValues = spatialPredicatePairValues
+ .get(x);
+ if (pairValues == null) {
+ pairValues = new HashSet<SpatialPredicatePairValue>();
+ spatialPredicatePairValues.put(x, pairValues);
+ }
+
+ Iterator<SpatialPredicatePairValue> it = pairValues.iterator();
+ SpatialPredicatePairValue toRemove = null;
+
+ while (it.hasNext()) {
+ SpatialPredicatePairValue pairValue = it.next();
+ if (pairValue.getPair().equals(pair)) {
+ Double theOtherValue = pairValue.getTheOtherValue(p);
+ if (theOtherValue != null) {
+ if (isLat) {
+ indexer.add(x, SpatialQuery.ctx.makePoint(
+ theOtherValue,
+ Double.parseDouble(o.getLiteralLexicalForm())));
+ } else {
+ indexer.add(x, SpatialQuery.ctx.makePoint(Double.parseDouble(o.getLiteralLexicalForm()),
+ theOtherValue));
+ }
+ toRemove = pairValue;
+ }
+ break;
+ }
+ }
+ if (toRemove != null) {
+ pairValues.remove(toRemove);
+ return;
+ }
+
+ SpatialPredicatePairValue toAdd = new SpatialPredicatePairValue(
+ pair);
+ toAdd.setValue(p, Double.parseDouble(o.getLiteralLexicalForm()));
+ pairValues.add(toAdd);
+
+ } else if (defn.isWKTPredicate(p) && SpatialValueUtil.isWKTLiteral(o.getLiteral())) {
+ @SuppressWarnings("deprecation")
+ Shape shape = SpatialQuery.ctx.readShape(o.getLiteralLexicalForm());
+ indexer.add(x, shape);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialPredicatePair.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialPredicatePair.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialPredicatePair.java
index 2f88e1c..eedc212 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialPredicatePair.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialPredicatePair.java
@@ -1,74 +1,74 @@
-/*
- * 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 org.apache.jena.query.spatial;
-
-import org.apache.jena.graph.Node ;
-
-public class SpatialPredicatePair {
-
- private Node latitudePredicate;
- private Node longitudePredicate;
-
- public SpatialPredicatePair(Node latitudePredicate, Node longitudePredicate) {
- super();
- this.latitudePredicate = latitudePredicate;
- this.longitudePredicate = longitudePredicate;
- }
-
- public Node getLatitudePredicate() {
- return latitudePredicate;
- }
-
- public Node getLongitudePredicate() {
- return longitudePredicate;
- }
-
- @Override
- public int hashCode() {
- return latitudePredicate.hashCode() * 7 + longitudePredicate.hashCode()
- * 13;
- }
-
- @Override
- public boolean equals(Object otherObject) {
- // a quick test to see if the objects are identical
- if (this == otherObject)
- return true;
-
- // must return false if the explicit parameter is null
- if (otherObject == null)
- return false;
-
- // if the classes don't match, they can't be equal
- if (getClass() != otherObject.getClass())
- return false;
-
- // now we know otherObject is a non-null Employee
- SpatialPredicatePair other = (SpatialPredicatePair) otherObject;
-
- // test whether the fields have identical values
- return latitudePredicate.equals(other.latitudePredicate)
- && longitudePredicate == other.longitudePredicate;
- }
-
- @Override
- public String toString(){
- return "[ " + latitudePredicate.toString() + ", " + longitudePredicate.toString() + " ]";
- }
-}
+/*
+ * 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 org.apache.jena.query.spatial;
+
+import org.apache.jena.graph.Node ;
+
+public class SpatialPredicatePair {
+
+ private Node latitudePredicate;
+ private Node longitudePredicate;
+
+ public SpatialPredicatePair(Node latitudePredicate, Node longitudePredicate) {
+ super();
+ this.latitudePredicate = latitudePredicate;
+ this.longitudePredicate = longitudePredicate;
+ }
+
+ public Node getLatitudePredicate() {
+ return latitudePredicate;
+ }
+
+ public Node getLongitudePredicate() {
+ return longitudePredicate;
+ }
+
+ @Override
+ public int hashCode() {
+ return latitudePredicate.hashCode() * 7 + longitudePredicate.hashCode()
+ * 13;
+ }
+
+ @Override
+ public boolean equals(Object otherObject) {
+ // a quick test to see if the objects are identical
+ if (this == otherObject)
+ return true;
+
+ // must return false if the explicit parameter is null
+ if (otherObject == null)
+ return false;
+
+ // if the classes don't match, they can't be equal
+ if (getClass() != otherObject.getClass())
+ return false;
+
+ // now we know otherObject is a non-null Employee
+ SpatialPredicatePair other = (SpatialPredicatePair) otherObject;
+
+ // test whether the fields have identical values
+ return latitudePredicate.equals(other.latitudePredicate)
+ && longitudePredicate == other.longitudePredicate;
+ }
+
+ @Override
+ public String toString(){
+ return "[ " + latitudePredicate.toString() + ", " + longitudePredicate.toString() + " ]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialPredicatePairValue.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialPredicatePairValue.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialPredicatePairValue.java
index b8e1285..9288757 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialPredicatePairValue.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialPredicatePairValue.java
@@ -1,109 +1,109 @@
-/*
- * 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 org.apache.jena.query.spatial;
-
-import org.apache.jena.graph.Node ;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SpatialPredicatePairValue {
-
- private static Logger log = LoggerFactory
- .getLogger(SpatialPredicatePairValue.class);
-
- public SpatialPredicatePairValue(SpatialPredicatePair pair) {
- this.pair = pair;
- }
-
- private SpatialPredicatePair pair;
- private Double latitudeValue;
- private Double longitudeValue;
-
- public Double getLatitudeValue() {
- return latitudeValue;
- }
-
- public Double getLongitudeValue() {
- return longitudeValue;
- }
-
- public SpatialPredicatePair getPair() {
- return pair;
- }
-
- public void setValue(Node predicate, Double value) {
- if (predicate.equals(pair.getLatitudePredicate())) {
- this.latitudeValue = value;
- } else if (predicate.equals(pair.getLongitudePredicate())) {
- this.longitudeValue = value;
- } else {
- log.warn("Try to set value to a SpatialPredicatePairValue with no such predicate: "
- + predicate + " :: " + value);
- }
-
- }
-
- public Double getTheOtherValue(Node predicate) {
- if (pair.getLatitudePredicate().equals(predicate)) {
- return this.getLongitudeValue();
- } else if (predicate.equals(pair.getLongitudePredicate())) {
- return this.getLatitudeValue();
- } else {
- log.warn("Try to get value to a SpatialPredicatePairValue with no such predicate: "
- + predicate);
- return null;
- }
- }
-
- @Override
- public int hashCode() {
- int latitudeHashCode = latitudeValue == null ? 0 : latitudeValue
- .hashCode() * 17;
- int longitudeHashCode = longitudeValue == null ? 0 : longitudeValue
- .hashCode() * 19;
- return pair.hashCode() * 11 + latitudeHashCode + longitudeHashCode;
- }
-
- @Override
- public boolean equals(Object otherObject) {
- // a quick test to see if the objects are identical
- if (this == otherObject)
- return true;
-
- // must return false if the explicit parameter is null
- if (otherObject == null)
- return false;
-
- // if the classes don't match, they can't be equal
- if (getClass() != otherObject.getClass())
- return false;
-
- // now we know otherObject is a non-null Employee
- SpatialPredicatePairValue other = (SpatialPredicatePairValue) otherObject;
-
- boolean latitudeValueEquals = this.latitudeValue == null ? other.latitudeValue == null
- : this.latitudeValue.equals(other.latitudeValue);
- boolean longitudeValueEquals = this.longitudeValue == null ? other.longitudeValue == null
- : this.longitudeValue.equals(other.longitudeValue);
-
- // test whether the fields have identical values
- return pair.equals(other.pair) && latitudeValueEquals
- && longitudeValueEquals;
- }
-}
+/*
+ * 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 org.apache.jena.query.spatial;
+
+import org.apache.jena.graph.Node ;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SpatialPredicatePairValue {
+
+ private static Logger log = LoggerFactory
+ .getLogger(SpatialPredicatePairValue.class);
+
+ public SpatialPredicatePairValue(SpatialPredicatePair pair) {
+ this.pair = pair;
+ }
+
+ private SpatialPredicatePair pair;
+ private Double latitudeValue;
+ private Double longitudeValue;
+
+ public Double getLatitudeValue() {
+ return latitudeValue;
+ }
+
+ public Double getLongitudeValue() {
+ return longitudeValue;
+ }
+
+ public SpatialPredicatePair getPair() {
+ return pair;
+ }
+
+ public void setValue(Node predicate, Double value) {
+ if (predicate.equals(pair.getLatitudePredicate())) {
+ this.latitudeValue = value;
+ } else if (predicate.equals(pair.getLongitudePredicate())) {
+ this.longitudeValue = value;
+ } else {
+ log.warn("Try to set value to a SpatialPredicatePairValue with no such predicate: "
+ + predicate + " :: " + value);
+ }
+
+ }
+
+ public Double getTheOtherValue(Node predicate) {
+ if (pair.getLatitudePredicate().equals(predicate)) {
+ return this.getLongitudeValue();
+ } else if (predicate.equals(pair.getLongitudePredicate())) {
+ return this.getLatitudeValue();
+ } else {
+ log.warn("Try to get value to a SpatialPredicatePairValue with no such predicate: "
+ + predicate);
+ return null;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ int latitudeHashCode = latitudeValue == null ? 0 : latitudeValue
+ .hashCode() * 17;
+ int longitudeHashCode = longitudeValue == null ? 0 : longitudeValue
+ .hashCode() * 19;
+ return pair.hashCode() * 11 + latitudeHashCode + longitudeHashCode;
+ }
+
+ @Override
+ public boolean equals(Object otherObject) {
+ // a quick test to see if the objects are identical
+ if (this == otherObject)
+ return true;
+
+ // must return false if the explicit parameter is null
+ if (otherObject == null)
+ return false;
+
+ // if the classes don't match, they can't be equal
+ if (getClass() != otherObject.getClass())
+ return false;
+
+ // now we know otherObject is a non-null Employee
+ SpatialPredicatePairValue other = (SpatialPredicatePairValue) otherObject;
+
+ boolean latitudeValueEquals = this.latitudeValue == null ? other.latitudeValue == null
+ : this.latitudeValue.equals(other.latitudeValue);
+ boolean longitudeValueEquals = this.longitudeValue == null ? other.longitudeValue == null
+ : this.longitudeValue.equals(other.longitudeValue);
+
+ // test whether the fields have identical values
+ return pair.equals(other.pair) && latitudeValueEquals
+ && longitudeValueEquals;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialValueUtil.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialValueUtil.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialValueUtil.java
index 3996f36..e30d8ee 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialValueUtil.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialValueUtil.java
@@ -1,60 +1,60 @@
-/*
- * 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 org.apache.jena.query.spatial;
-
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.impl.LiteralLabel ;
-import org.apache.jena.sparql.util.NodeUtils ;
-
-public class SpatialValueUtil {
-
- /** Does the LiteralLabel look like a decimal?
- * (Maybe a string - if so, OK if it parses as a decimal)
- */
- public static boolean isDecimal(Node n) {
- if ( NodeUtils.isSimpleString(n) || NodeUtils.isLangString(n) ) {
- try {
- Double.parseDouble(n.getLiteralLexicalForm()) ;
- return true;
- } catch (NumberFormatException e) {
- return false;
- }
- }
-
- RDFDatatype dtype = n.getLiteralDatatype();
- if ((dtype.equals(XSDDatatype.XSDfloat))
- || (dtype.equals(XSDDatatype.XSDdecimal))
- || (dtype.equals(XSDDatatype.XSDdouble) || (dtype
- .equals(XSDDatatype.XSDinteger))))
- return true;
- return false;
- }
-
- public static boolean isWKTLiteral(LiteralLabel literal) {
- RDFDatatype dtype = literal.getDatatype();
- if (dtype == null)
- return false;
- if (dtype.getURI().equals(
- EntityDefinition.geosparql_wktLiteral.getURI()))
- return true;
- return false;
- }
-}
+/*
+ * 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 org.apache.jena.query.spatial;
+
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.impl.LiteralLabel ;
+import org.apache.jena.sparql.util.NodeUtils ;
+
+public class SpatialValueUtil {
+
+ /** Does the LiteralLabel look like a decimal?
+ * (Maybe a string - if so, OK if it parses as a decimal)
+ */
+ public static boolean isDecimal(Node n) {
+ if ( NodeUtils.isSimpleString(n) || NodeUtils.isLangString(n) ) {
+ try {
+ Double.parseDouble(n.getLiteralLexicalForm()) ;
+ return true;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ RDFDatatype dtype = n.getLiteralDatatype();
+ if ((dtype.equals(XSDDatatype.XSDfloat))
+ || (dtype.equals(XSDDatatype.XSDdecimal))
+ || (dtype.equals(XSDDatatype.XSDdouble) || (dtype
+ .equals(XSDDatatype.XSDinteger))))
+ return true;
+ return false;
+ }
+
+ public static boolean isWKTLiteral(LiteralLabel literal) {
+ RDFDatatype dtype = literal.getDatatype();
+ if (dtype == null)
+ return false;
+ if (dtype.getURI().equals(
+ EntityDefinition.geosparql_wktLiteral.getURI()))
+ return true;
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/DirectionWithPointPFBase.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/DirectionWithPointPFBase.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/DirectionWithPointPFBase.java
index 2f49963..29bb81f 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/DirectionWithPointPFBase.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/DirectionWithPointPFBase.java
@@ -1,146 +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 org.apache.jena.query.spatial.pfunction;
-
-import java.util.List;
-
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.impl.LiteralLabel ;
-import org.apache.jena.query.QueryBuildException ;
-import org.apache.jena.query.spatial.SpatialIndexException;
-import org.apache.jena.query.spatial.SpatialValueUtil;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.pfunction.PropFuncArg ;
-import org.apache.jena.sparql.util.NodeFactoryExtra ;
-import org.apache.lucene.spatial.query.SpatialOperation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class DirectionWithPointPFBase extends SpatialOperationPFBase {
-
- private static Logger log = LoggerFactory.getLogger(DirectionWithPointPFBase.class);
-
- public DirectionWithPointPFBase() {
-
- }
-
- @Override
- public void build(PropFuncArg argSubject, Node predicate,
- PropFuncArg argObject, ExecutionContext execCxt) {
- super.build(argSubject, predicate, argObject, execCxt);
-
- if (!argSubject.isNode())
- throw new QueryBuildException("Subject is not a single node: "
- + argSubject);
-
- if (argObject.isList()) {
- List<Node> list = argObject.getArgList();
- if (list.size() < 2)
- throw new QueryBuildException("Not enough arguments in list");
-
- if (list.size() > 3)
- throw new QueryBuildException("Too many arguments in list : "
- + list);
- }
- }
-
-
- /** Deconstruct the node or list object argument and make a SpatialMatch */
- @Override
- protected SpatialMatch objectToStruct(PropFuncArg argObject) {
- if (argObject.isNode()) {
- log.warn("Object not a List: " + argObject);
- return null;
- }
-
- List<Node> list = argObject.getArgList();
-
- if (list.size() < 2 || list.size() > 3)
- throw new SpatialIndexException("Change in object list size");
-
- int idx = 0;
-
- Node x = list.get(idx);
- if (!x.isLiteral()) {
- log.warn("Latitude is not a literal " + list);
- return null;
- }
- if (!SpatialValueUtil.isDecimal(x)) {
- log.warn("Latitude is not a decimal " + list);
- return null;
- }
- Double latitude = Double.parseDouble(x.getLiteralLexicalForm());
-
- idx++;
-
- x = list.get(idx);
- if (!x.isLiteral()) {
- log.warn("Longitude is not a literal " + list);
- return null;
- }
- if (!SpatialValueUtil.isDecimal(x)) {
- log.warn("Longitude is not a decimal " + list);
- return null;
- }
- Double longitude = Double.parseDouble(x.getLiteralLexicalForm());
-
- idx++;
-
- int limit =-1;
-
- if (idx < list.size()) {
- x = list.get(idx);
-
- if (!x.isLiteral()) {
- log.warn("Limit is not a literal " + list);
- return null;
- }
-
- LiteralLabel lit = x.getLiteral();
-
- if (!XSDDatatype.XSDinteger.isValidLiteral(lit)) {
- log.warn("Limit is not an integer " + list);
- return null;
- }
-
- int v = NodeFactoryExtra.nodeToInt(x);
- limit = (v < 0) ? -1 : v;
-
- idx++;
- if (idx < list.size()) {
- log.warn("Limit is not the last parameter " + list);
- return null;
- }
- }
-
- SpatialMatch match = this.getSpatialMatch(latitude, longitude, limit);
- if (log.isDebugEnabled())
- log.debug("Trying SpatialMatch: " + match.toString());
- return match;
- }
-
- protected abstract SpatialMatch getSpatialMatch(Double latitude, Double longitude, int limit);
-
- @Override
- protected SpatialOperation getSpatialOperation() {
- return SpatialOperation.IsWithin;
- }
-
-}
+/*
+ * 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 org.apache.jena.query.spatial.pfunction;
+
+import java.util.List;
+
+import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.impl.LiteralLabel ;
+import org.apache.jena.query.QueryBuildException ;
+import org.apache.jena.query.spatial.SpatialIndexException;
+import org.apache.jena.query.spatial.SpatialValueUtil;
+import org.apache.jena.sparql.engine.ExecutionContext ;
+import org.apache.jena.sparql.pfunction.PropFuncArg ;
+import org.apache.jena.sparql.util.NodeFactoryExtra ;
+import org.apache.lucene.spatial.query.SpatialOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class DirectionWithPointPFBase extends SpatialOperationPFBase {
+
+ private static Logger log = LoggerFactory.getLogger(DirectionWithPointPFBase.class);
+
+ public DirectionWithPointPFBase() {
+
+ }
+
+ @Override
+ public void build(PropFuncArg argSubject, Node predicate,
+ PropFuncArg argObject, ExecutionContext execCxt) {
+ super.build(argSubject, predicate, argObject, execCxt);
+
+ if (!argSubject.isNode())
+ throw new QueryBuildException("Subject is not a single node: "
+ + argSubject);
+
+ if (argObject.isList()) {
+ List<Node> list = argObject.getArgList();
+ if (list.size() < 2)
+ throw new QueryBuildException("Not enough arguments in list");
+
+ if (list.size() > 3)
+ throw new QueryBuildException("Too many arguments in list : "
+ + list);
+ }
+ }
+
+
+ /** Deconstruct the node or list object argument and make a SpatialMatch */
+ @Override
+ protected SpatialMatch objectToStruct(PropFuncArg argObject) {
+ if (argObject.isNode()) {
+ log.warn("Object not a List: " + argObject);
+ return null;
+ }
+
+ List<Node> list = argObject.getArgList();
+
+ if (list.size() < 2 || list.size() > 3)
+ throw new SpatialIndexException("Change in object list size");
+
+ int idx = 0;
+
+ Node x = list.get(idx);
+ if (!x.isLiteral()) {
+ log.warn("Latitude is not a literal " + list);
+ return null;
+ }
+ if (!SpatialValueUtil.isDecimal(x)) {
+ log.warn("Latitude is not a decimal " + list);
+ return null;
+ }
+ Double latitude = Double.parseDouble(x.getLiteralLexicalForm());
+
+ idx++;
+
+ x = list.get(idx);
+ if (!x.isLiteral()) {
+ log.warn("Longitude is not a literal " + list);
+ return null;
+ }
+ if (!SpatialValueUtil.isDecimal(x)) {
+ log.warn("Longitude is not a decimal " + list);
+ return null;
+ }
+ Double longitude = Double.parseDouble(x.getLiteralLexicalForm());
+
+ idx++;
+
+ int limit =-1;
+
+ if (idx < list.size()) {
+ x = list.get(idx);
+
+ if (!x.isLiteral()) {
+ log.warn("Limit is not a literal " + list);
+ return null;
+ }
+
+ LiteralLabel lit = x.getLiteral();
+
+ if (!XSDDatatype.XSDinteger.isValidLiteral(lit)) {
+ log.warn("Limit is not an integer " + list);
+ return null;
+ }
+
+ int v = NodeFactoryExtra.nodeToInt(x);
+ limit = (v < 0) ? -1 : v;
+
+ idx++;
+ if (idx < list.size()) {
+ log.warn("Limit is not the last parameter " + list);
+ return null;
+ }
+ }
+
+ SpatialMatch match = this.getSpatialMatch(latitude, longitude, limit);
+ if (log.isDebugEnabled())
+ log.debug("Trying SpatialMatch: " + match.toString());
+ return match;
+ }
+
+ protected abstract SpatialMatch getSpatialMatch(Double latitude, Double longitude, int limit);
+
+ @Override
+ protected SpatialOperation getSpatialOperation() {
+ return SpatialOperation.IsWithin;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialMatch.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialMatch.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialMatch.java
index 10832ed..0d8275c 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialMatch.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialMatch.java
@@ -1,67 +1,67 @@
-/*
- * 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 org.apache.jena.query.spatial.pfunction;
-
-import org.apache.jena.query.spatial.DistanceUnitsUtils;
-import org.apache.jena.query.spatial.SpatialQuery;
-import org.apache.lucene.spatial.query.SpatialOperation;
-
-import com.spatial4j.core.shape.Shape;
-
-public class SpatialMatch {
-
- private final Shape shape;
- private final int limit;
- private final SpatialOperation operation;
-
- public SpatialMatch(Double latitude, Double longitude, Double radius,
- String units, int limit, SpatialOperation operation) {
-
- double degrees = DistanceUnitsUtils.dist2Degrees(radius, units);
- this.shape = SpatialQuery.ctx.makeCircle(longitude, latitude, degrees);
- //System.out.println( SpatialQuery.ctx.toString(shape) );
- this.limit = limit;
- this.operation = operation;
- }
-
- public SpatialMatch(Double latitude1, Double longitude1, Double latitude2,
- Double longitude2, int limit, SpatialOperation operation) {
- this.shape = SpatialQuery.ctx.makeRectangle(longitude1, longitude2, latitude1, latitude2);
- this.limit = limit;
- this.operation = operation;
- }
-
- public Shape getShape() {
- return shape;
- }
-
- public int getLimit() {
- return limit;
- }
-
- public SpatialOperation getSpatialOperation() {
- return operation;
- }
-
- @Override
- public String toString() {
- return "(" + shape + " " + limit + " " + operation + ")";
- }
-
-}
+/*
+ * 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 org.apache.jena.query.spatial.pfunction;
+
+import org.apache.jena.query.spatial.DistanceUnitsUtils;
+import org.apache.jena.query.spatial.SpatialQuery;
+import org.apache.lucene.spatial.query.SpatialOperation;
+
+import com.spatial4j.core.shape.Shape;
+
+public class SpatialMatch {
+
+ private final Shape shape;
+ private final int limit;
+ private final SpatialOperation operation;
+
+ public SpatialMatch(Double latitude, Double longitude, Double radius,
+ String units, int limit, SpatialOperation operation) {
+
+ double degrees = DistanceUnitsUtils.dist2Degrees(radius, units);
+ this.shape = SpatialQuery.ctx.makeCircle(longitude, latitude, degrees);
+ //System.out.println( SpatialQuery.ctx.toString(shape) );
+ this.limit = limit;
+ this.operation = operation;
+ }
+
+ public SpatialMatch(Double latitude1, Double longitude1, Double latitude2,
+ Double longitude2, int limit, SpatialOperation operation) {
+ this.shape = SpatialQuery.ctx.makeRectangle(longitude1, longitude2, latitude1, latitude2);
+ this.limit = limit;
+ this.operation = operation;
+ }
+
+ public Shape getShape() {
+ return shape;
+ }
+
+ public int getLimit() {
+ return limit;
+ }
+
+ public SpatialOperation getSpatialOperation() {
+ return operation;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + shape + " " + limit + " " + operation + ")";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java
index 2f8b638..82d7b4f 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java
@@ -1,163 +1,163 @@
-/*
- * 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 org.apache.jena.query.spatial.pfunction;
-
-import java.util.List ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.lib.InternalErrorException ;
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.query.spatial.DatasetGraphSpatial ;
-import org.apache.jena.query.spatial.SpatialIndex ;
-import org.apache.jena.query.spatial.SpatialQuery ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.sparql.core.Substitute ;
-import org.apache.jena.sparql.core.Var ;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.engine.iterator.QueryIterExtendByVar ;
-import org.apache.jena.sparql.engine.iterator.QueryIterSlice ;
-import org.apache.jena.sparql.pfunction.PropFuncArg ;
-import org.apache.jena.sparql.pfunction.PropertyFunctionBase ;
-import org.apache.jena.sparql.util.IterLib ;
-import org.apache.lucene.spatial.query.SpatialOperation ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
-
-public abstract class SpatialOperationPFBase extends PropertyFunctionBase {
-
- private static Logger log = LoggerFactory.getLogger(SpatialOperationPFBase.class);
-
- protected SpatialIndex server = null;
- private boolean warningIssued = false;
-
- public SpatialOperationPFBase() {
- }
-
- @Override
- public void build(PropFuncArg argSubject, Node predicate,
- PropFuncArg argObject, ExecutionContext execCxt) {
- super.build(argSubject, predicate, argObject, execCxt);
- DatasetGraph dsg = execCxt.getDataset();
- server = chooseTextIndex(dsg);
- }
-
- protected SpatialIndex chooseTextIndex(DatasetGraph dsg) {
- Object obj = dsg.getContext().get(SpatialQuery.spatialIndex);
-
- if (obj != null) {
- try {
- return (SpatialIndex) obj;
- } catch (ClassCastException ex) {
- Log.warn(SpatialOperationWithCircleBase.class, "Context setting '"
- + SpatialQuery.spatialIndex + "'is not a SpatialIndex");
- }
- }
-
- if (dsg instanceof DatasetGraphSpatial) {
- DatasetGraphSpatial x = (DatasetGraphSpatial) dsg;
- return x.getSpatialIndex();
- }
- Log.warn(
- SpatialOperationWithCircleBase.class,
- "Failed to find the spatial index : tried context and as a spatial-enabled dataset");
- return null;
- }
-
- @Override
- public QueryIterator exec(Binding binding, PropFuncArg argSubject,
- Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
- if (server == null) {
- if (!warningIssued) {
- Log.warn(getClass(), "No spatial index - no spatial search performed");
- warningIssued = true;
- }
- // Not a text dataset - no-op
- return IterLib.result(binding, execCxt);
- }
-
- DatasetGraph dsg = execCxt.getDataset();
-
- argSubject = Substitute.substitute(argSubject, binding) ;
- argObject = Substitute.substitute(argObject, binding) ;
-
- if (!argSubject.isNode())
- throw new InternalErrorException("Subject is not a node (it was earlier!)");
-
- Node s = argSubject.getArg();
-
- if (s.isLiteral())
- // Does not match
- return IterLib.noResults(execCxt);
-
- SpatialMatch match = objectToStruct(argObject);
-
- if (match == null) {
- // can't match
- return IterLib.noResults(execCxt);
- }
-
- // ----
-
- QueryIterator qIter = (Var.isVar(s)) ? variableSubject(binding, s,
- match, execCxt) : concreteSubject(binding, s, match, execCxt);
- if (match.getLimit() >= 0)
- qIter = new QueryIterSlice(qIter, 0, match.getLimit(), execCxt);
- return qIter;
- }
-
- private QueryIterator variableSubject(Binding binding, Node s,
- SpatialMatch match, ExecutionContext execCxt) {
-
- Var v = Var.alloc(s);
- List<Node> r = query(match);
- // Make distinct. Note interaction with limit is imperfect
- r = Iter.iter(r).distinct().toList();
- QueryIterator qIter = new QueryIterExtendByVar(binding, v,
- r.iterator(), execCxt);
- return qIter;
- }
-
- private QueryIterator concreteSubject(Binding binding, Node s,
- SpatialMatch match, ExecutionContext execCxt) {
- if (!s.isURI()) {
- log.warn("Subject not a URI: " + s);
- return IterLib.noResults(execCxt);
- }
-
- List<Node> x = query(match);
- if (x == null || !x.contains(s))
- return IterLib.noResults(execCxt);
- else
- return IterLib.result(binding, execCxt);
- }
-
- private List<Node> query(SpatialMatch match) {
-
- return server.query(match.getShape(), match.getLimit(),
- match.getSpatialOperation());
- }
-
- /** Deconstruct the node or list object argument and make a SpatialMatch */
- protected abstract SpatialMatch objectToStruct(PropFuncArg argObject);
-
- protected abstract SpatialOperation getSpatialOperation();
-}
+/*
+ * 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 org.apache.jena.query.spatial.pfunction;
+
+import java.util.List ;
+
+import org.apache.jena.atlas.iterator.Iter ;
+import org.apache.jena.atlas.lib.InternalErrorException ;
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.query.spatial.DatasetGraphSpatial ;
+import org.apache.jena.query.spatial.SpatialIndex ;
+import org.apache.jena.query.spatial.SpatialQuery ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.core.Substitute ;
+import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.sparql.engine.ExecutionContext ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.engine.iterator.QueryIterExtendByVar ;
+import org.apache.jena.sparql.engine.iterator.QueryIterSlice ;
+import org.apache.jena.sparql.pfunction.PropFuncArg ;
+import org.apache.jena.sparql.pfunction.PropertyFunctionBase ;
+import org.apache.jena.sparql.util.IterLib ;
+import org.apache.lucene.spatial.query.SpatialOperation ;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+public abstract class SpatialOperationPFBase extends PropertyFunctionBase {
+
+ private static Logger log = LoggerFactory.getLogger(SpatialOperationPFBase.class);
+
+ protected SpatialIndex server = null;
+ private boolean warningIssued = false;
+
+ public SpatialOperationPFBase() {
+ }
+
+ @Override
+ public void build(PropFuncArg argSubject, Node predicate,
+ PropFuncArg argObject, ExecutionContext execCxt) {
+ super.build(argSubject, predicate, argObject, execCxt);
+ DatasetGraph dsg = execCxt.getDataset();
+ server = chooseTextIndex(dsg);
+ }
+
+ protected SpatialIndex chooseTextIndex(DatasetGraph dsg) {
+ Object obj = dsg.getContext().get(SpatialQuery.spatialIndex);
+
+ if (obj != null) {
+ try {
+ return (SpatialIndex) obj;
+ } catch (ClassCastException ex) {
+ Log.warn(SpatialOperationWithCircleBase.class, "Context setting '"
+ + SpatialQuery.spatialIndex + "'is not a SpatialIndex");
+ }
+ }
+
+ if (dsg instanceof DatasetGraphSpatial) {
+ DatasetGraphSpatial x = (DatasetGraphSpatial) dsg;
+ return x.getSpatialIndex();
+ }
+ Log.warn(
+ SpatialOperationWithCircleBase.class,
+ "Failed to find the spatial index : tried context and as a spatial-enabled dataset");
+ return null;
+ }
+
+ @Override
+ public QueryIterator exec(Binding binding, PropFuncArg argSubject,
+ Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
+ if (server == null) {
+ if (!warningIssued) {
+ Log.warn(getClass(), "No spatial index - no spatial search performed");
+ warningIssued = true;
+ }
+ // Not a text dataset - no-op
+ return IterLib.result(binding, execCxt);
+ }
+
+ DatasetGraph dsg = execCxt.getDataset();
+
+ argSubject = Substitute.substitute(argSubject, binding) ;
+ argObject = Substitute.substitute(argObject, binding) ;
+
+ if (!argSubject.isNode())
+ throw new InternalErrorException("Subject is not a node (it was earlier!)");
+
+ Node s = argSubject.getArg();
+
+ if (s.isLiteral())
+ // Does not match
+ return IterLib.noResults(execCxt);
+
+ SpatialMatch match = objectToStruct(argObject);
+
+ if (match == null) {
+ // can't match
+ return IterLib.noResults(execCxt);
+ }
+
+ // ----
+
+ QueryIterator qIter = (Var.isVar(s)) ? variableSubject(binding, s,
+ match, execCxt) : concreteSubject(binding, s, match, execCxt);
+ if (match.getLimit() >= 0)
+ qIter = new QueryIterSlice(qIter, 0, match.getLimit(), execCxt);
+ return qIter;
+ }
+
+ private QueryIterator variableSubject(Binding binding, Node s,
+ SpatialMatch match, ExecutionContext execCxt) {
+
+ Var v = Var.alloc(s);
+ List<Node> r = query(match);
+ // Make distinct. Note interaction with limit is imperfect
+ r = Iter.iter(r).distinct().toList();
+ QueryIterator qIter = new QueryIterExtendByVar(binding, v,
+ r.iterator(), execCxt);
+ return qIter;
+ }
+
+ private QueryIterator concreteSubject(Binding binding, Node s,
+ SpatialMatch match, ExecutionContext execCxt) {
+ if (!s.isURI()) {
+ log.warn("Subject not a URI: " + s);
+ return IterLib.noResults(execCxt);
+ }
+
+ List<Node> x = query(match);
+ if (x == null || !x.contains(s))
+ return IterLib.noResults(execCxt);
+ else
+ return IterLib.result(binding, execCxt);
+ }
+
+ private List<Node> query(SpatialMatch match) {
+
+ return server.query(match.getShape(), match.getLimit(),
+ match.getSpatialOperation());
+ }
+
+ /** Deconstruct the node or list object argument and make a SpatialMatch */
+ protected abstract SpatialMatch objectToStruct(PropFuncArg argObject);
+
+ protected abstract SpatialOperation getSpatialOperation();
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationWithBoxPFBase.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationWithBoxPFBase.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationWithBoxPFBase.java
index ee44773..e200134 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationWithBoxPFBase.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationWithBoxPFBase.java
@@ -1,164 +1,164 @@
-/*
- * 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 org.apache.jena.query.spatial.pfunction;
-
-import java.util.List;
-
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.impl.LiteralLabel ;
-import org.apache.jena.query.QueryBuildException ;
-import org.apache.jena.query.spatial.SpatialIndexException;
-import org.apache.jena.query.spatial.SpatialValueUtil;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.pfunction.PropFuncArg ;
-import org.apache.jena.sparql.util.NodeFactoryExtra ;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class SpatialOperationWithBoxPFBase extends SpatialOperationPFBase {
- private static Logger log = LoggerFactory.getLogger(SpatialOperationWithCircleBase.class);
-
- public SpatialOperationWithBoxPFBase() {
- }
-
- @Override
- public void build(PropFuncArg argSubject, Node predicate,
- PropFuncArg argObject, ExecutionContext execCxt) {
- super.build(argSubject, predicate, argObject, execCxt);
-
- if (!argSubject.isNode())
- throw new QueryBuildException("Subject is not a single node: "
- + argSubject);
-
- if (argObject.isList()) {
- List<Node> list = argObject.getArgList();
- if (list.size() < 4)
- throw new QueryBuildException("Not enough arguments in list");
-
- if (list.size() > 5)
- throw new QueryBuildException("Too many arguments in list : "
- + list);
- }
- }
-
- /** Deconstruct the node or list object argument and make a SpatialMatch */
- @Override
- protected SpatialMatch objectToStruct(PropFuncArg argObject) {
-
- if (argObject.isNode()) {
- log.warn("Object not a List: " + argObject);
- return null;
- }
-
- List<Node> list = argObject.getArgList();
-
- if (list.size() < 4 || list.size() > 5)
- throw new SpatialIndexException("Change in object list size");
-
- int idx = 0;
-
- Node x = list.get(idx);
- if (!x.isLiteral()) {
- log.warn("Latitude 1 is not a literal " + list);
- return null;
- }
- if (!SpatialValueUtil.isDecimal(x)) {
- log.warn("Latitude 1 is not a decimal " + list);
- return null;
- }
- Double latitude1 = Double.parseDouble(x.getLiteralLexicalForm());
-
- idx++;
-
- x = list.get(idx);
- if (!x.isLiteral()) {
- log.warn("Longitude 1 is not a literal " + list);
- return null;
- }
- if (!SpatialValueUtil.isDecimal(x)) {
- log.warn("Longitude 1 is not a decimal " + list);
- return null;
- }
- Double longtitude1 = Double.parseDouble(x.getLiteralLexicalForm());
-
- idx++;
-
- x = list.get(idx);
- if (!x.isLiteral()) {
- log.warn("Latitude 2 is not a literal " + list);
- return null;
- }
- if (!SpatialValueUtil.isDecimal(x)) {
- log.warn("Latitude 2 is not a decimal " + list);
- return null;
- }
- Double latitude2 = Double.parseDouble(x.getLiteralLexicalForm());
-
- idx++;
-
- x = list.get(idx);
- if (!x.isLiteral()) {
- log.warn("Longitude 2 is not a literal " + list);
- return null;
- }
- if (!SpatialValueUtil.isDecimal(x)) {
- log.warn("Longitude 2 is not a decimal " + list);
- return null;
- }
- Double longtitude2 = Double.parseDouble(x.getLiteralLexicalForm());
-
- idx++;
- int limit =-1;
-
- if (idx < list.size()) {
- x = list.get(idx);
-
- if (!x.isLiteral()) {
- log.warn("Limit is not a literal " + list);
- return null;
- }
-
- LiteralLabel lit = x.getLiteral();
-
- if (!XSDDatatype.XSDinteger.isValidLiteral(lit)) {
- log.warn("Limit is not an integer " + list);
- return null;
- }
-
- int v = NodeFactoryExtra.nodeToInt(x);
- limit = (v < 0) ? -1 : v;
-
- idx++;
- if (idx < list.size()) {
- log.warn("Limit is not the last parameter " + list);
- return null;
- }
- }
-
- SpatialMatch match = new SpatialMatch(latitude1, longtitude1,
- latitude2, longtitude2, limit, getSpatialOperation());
-
- if (log.isDebugEnabled())
- log.debug("Trying SpatialMatch: " + match.toString());
- return match;
- }
-
-
-}
+/*
+ * 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 org.apache.jena.query.spatial.pfunction;
+
+import java.util.List;
+
+import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.impl.LiteralLabel ;
+import org.apache.jena.query.QueryBuildException ;
+import org.apache.jena.query.spatial.SpatialIndexException;
+import org.apache.jena.query.spatial.SpatialValueUtil;
+import org.apache.jena.sparql.engine.ExecutionContext ;
+import org.apache.jena.sparql.pfunction.PropFuncArg ;
+import org.apache.jena.sparql.util.NodeFactoryExtra ;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class SpatialOperationWithBoxPFBase extends SpatialOperationPFBase {
+ private static Logger log = LoggerFactory.getLogger(SpatialOperationWithCircleBase.class);
+
+ public SpatialOperationWithBoxPFBase() {
+ }
+
+ @Override
+ public void build(PropFuncArg argSubject, Node predicate,
+ PropFuncArg argObject, ExecutionContext execCxt) {
+ super.build(argSubject, predicate, argObject, execCxt);
+
+ if (!argSubject.isNode())
+ throw new QueryBuildException("Subject is not a single node: "
+ + argSubject);
+
+ if (argObject.isList()) {
+ List<Node> list = argObject.getArgList();
+ if (list.size() < 4)
+ throw new QueryBuildException("Not enough arguments in list");
+
+ if (list.size() > 5)
+ throw new QueryBuildException("Too many arguments in list : "
+ + list);
+ }
+ }
+
+ /** Deconstruct the node or list object argument and make a SpatialMatch */
+ @Override
+ protected SpatialMatch objectToStruct(PropFuncArg argObject) {
+
+ if (argObject.isNode()) {
+ log.warn("Object not a List: " + argObject);
+ return null;
+ }
+
+ List<Node> list = argObject.getArgList();
+
+ if (list.size() < 4 || list.size() > 5)
+ throw new SpatialIndexException("Change in object list size");
+
+ int idx = 0;
+
+ Node x = list.get(idx);
+ if (!x.isLiteral()) {
+ log.warn("Latitude 1 is not a literal " + list);
+ return null;
+ }
+ if (!SpatialValueUtil.isDecimal(x)) {
+ log.warn("Latitude 1 is not a decimal " + list);
+ return null;
+ }
+ Double latitude1 = Double.parseDouble(x.getLiteralLexicalForm());
+
+ idx++;
+
+ x = list.get(idx);
+ if (!x.isLiteral()) {
+ log.warn("Longitude 1 is not a literal " + list);
+ return null;
+ }
+ if (!SpatialValueUtil.isDecimal(x)) {
+ log.warn("Longitude 1 is not a decimal " + list);
+ return null;
+ }
+ Double longtitude1 = Double.parseDouble(x.getLiteralLexicalForm());
+
+ idx++;
+
+ x = list.get(idx);
+ if (!x.isLiteral()) {
+ log.warn("Latitude 2 is not a literal " + list);
+ return null;
+ }
+ if (!SpatialValueUtil.isDecimal(x)) {
+ log.warn("Latitude 2 is not a decimal " + list);
+ return null;
+ }
+ Double latitude2 = Double.parseDouble(x.getLiteralLexicalForm());
+
+ idx++;
+
+ x = list.get(idx);
+ if (!x.isLiteral()) {
+ log.warn("Longitude 2 is not a literal " + list);
+ return null;
+ }
+ if (!SpatialValueUtil.isDecimal(x)) {
+ log.warn("Longitude 2 is not a decimal " + list);
+ return null;
+ }
+ Double longtitude2 = Double.parseDouble(x.getLiteralLexicalForm());
+
+ idx++;
+ int limit =-1;
+
+ if (idx < list.size()) {
+ x = list.get(idx);
+
+ if (!x.isLiteral()) {
+ log.warn("Limit is not a literal " + list);
+ return null;
+ }
+
+ LiteralLabel lit = x.getLiteral();
+
+ if (!XSDDatatype.XSDinteger.isValidLiteral(lit)) {
+ log.warn("Limit is not an integer " + list);
+ return null;
+ }
+
+ int v = NodeFactoryExtra.nodeToInt(x);
+ limit = (v < 0) ? -1 : v;
+
+ idx++;
+ if (idx < list.size()) {
+ log.warn("Limit is not the last parameter " + list);
+ return null;
+ }
+ }
+
+ SpatialMatch match = new SpatialMatch(latitude1, longtitude1,
+ latitude2, longtitude2, limit, getSpatialOperation());
+
+ if (log.isDebugEnabled())
+ log.debug("Trying SpatialMatch: " + match.toString());
+ return match;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/d6ae87fd/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/library/EastPF.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/library/EastPF.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/library/EastPF.java
index 96e5519..6c40cfa 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/library/EastPF.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/library/EastPF.java
@@ -1,44 +1,44 @@
-/*
- * 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 org.apache.jena.query.spatial.pfunction.library;
-
-import org.apache.jena.query.spatial.SpatialQuery;
-import org.apache.jena.query.spatial.pfunction.DirectionWithPointPFBase;
-import org.apache.jena.query.spatial.pfunction.SpatialMatch;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class EastPF extends DirectionWithPointPFBase {
-
- private static Logger log = LoggerFactory.getLogger(EastPF.class);
-
- public EastPF() {
- // TODO Auto-generated constructor stub
- }
-
- /** Deconstruct the node or list object argument and make a SpatialMatch */
- @Override
- protected SpatialMatch getSpatialMatch(Double latitude, Double longitude, int limit) {
- SpatialMatch match = new SpatialMatch(SpatialQuery.ctx.getWorldBounds().getMinY(),
- longitude, SpatialQuery.ctx.getWorldBounds().getMaxY(), SpatialQuery.ctx.getWorldBounds()
- .getMaxX(), limit, getSpatialOperation());
- return match;
- }
-
-}
+/*
+ * 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 org.apache.jena.query.spatial.pfunction.library;
+
+import org.apache.jena.query.spatial.SpatialQuery;
+import org.apache.jena.query.spatial.pfunction.DirectionWithPointPFBase;
+import org.apache.jena.query.spatial.pfunction.SpatialMatch;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EastPF extends DirectionWithPointPFBase {
+
+ private static Logger log = LoggerFactory.getLogger(EastPF.class);
+
+ public EastPF() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /** Deconstruct the node or list object argument and make a SpatialMatch */
+ @Override
+ protected SpatialMatch getSpatialMatch(Double latitude, Double longitude, int limit) {
+ SpatialMatch match = new SpatialMatch(SpatialQuery.ctx.getWorldBounds().getMinY(),
+ longitude, SpatialQuery.ctx.getWorldBounds().getMaxY(), SpatialQuery.ctx.getWorldBounds()
+ .getMaxX(), limit, getSpatialOperation());
+ return match;
+ }
+
+}