Hi Andy, Sorry for the late reply.
>>> The code has several things that are not from jena. Where is the data >>> being loaded into the spatial index? Check the Lucene directory has >>> actually grown. After I execute the code I get three files into the '/home/martin/spatial_index' folder: -rw-r--r-- 1 martin martin 53 Mar 21 10:40 segments_1 -rw-r--r-- 1 martin martin 36 Mar 21 10:40 segments.gen -rw-r--r-- 1 martin martin 0 Mar 21 10:40 write.lock The files are small, but the data that I have contains not too many triples- as it is set up just for the testing of this feature. Best Regards Martin ________________________________________ From: Andy Seaborne <[email protected]> Sent: Sunday, March 13, 2016 7:37 PM To: [email protected] Subject: Re: Geospatial SPARQL queries with Jena Hi there, The code has several things that are not from jena. Where is the data being loaded into the spatial index? Check the Lucene directory has actually grown. > Dataset baseDataset = DatasetFactory.create(m); > try { > Directory dir = FSDirectory.open( new File("/home/martin/spatial_index")); > Dataset spatialDataset = SpatialDatasetFactory.createLucene(baseDataset, dir, entDef); just associating the baseDataset with a Directory does not cause automatic indexing - loading into spatialDataset should cause The lucene directory to change. Andy On 11/03/16 14:11, Martin Vachovski wrote: > Hi All, > > > I am new to this group. > > I've being trying to start with geospatial SPARQL queries with Jena, but so > far no luck. > > > I have a simple Jena model which among other data contains the following: > > > <rdf:RDF > xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" > xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" > xmlns:ssn="http://purl.oclc.org/NET/ssnx/ssn#" > xmlns:xsd="http://www.w3.org/2001/XMLSchema#"> > > > <ssn:ObservationValue > rdf:about="http://af3.info/ObservationValues/GasCO/1450439142"> > <geo:location> > <geo:Point > rdf:about="http://af3.info/locations/GasCO/1450439142"> > <geo:lat > rdf:datatype="http://www.w3.org/2001/XMLSchema#float" > >35.4</geo:lat> > <geo:long > rdf:datatype="http://www.w3.org/2001/XMLSchema#float" > >32</geo:long> > </geo:Point> > </geo:location> > <!-- some more data here --> > </ssn:ObservationValue> > > > </rdf:RDF> > > > So I am trying to extract the geo:Point resource using the following Jena > code: > > > > private static void geoQuery() > { > InitJenaSpatial jenaSpatial = new InitJenaSpatial(); > jenaSpatial.start(); > try { > String queryStr = > "PREFIX spatial: <http://jena.apache.org/spatial#> " + > "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + > "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> " + > "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " + > "PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>" + > "SELECT ?loc " + > "WHERE {?loc spatial:nearby(35.4 32 1000 'km' )}"; > > // the object m contains the Jena model with the data > Model m = SemanticSensorModel.getIntance().getJenaModel(); > EntityDefinition entDef = new EntityDefinition("ssn:ObservationValue", > "geo:location"); > // EntityDefinition entDef = new > EntityDefinition("<http://af3.info/ObservationValues/GasCO/1450439142>", > // "<http://af3.info/locations/GasCO/1450439142>"); > // EntityDefinition entDef = new > EntityDefinition("<http://purl.oclc.org/NET/ssnx/ssn#ObservationValue>", > // "<http://www.w3.org/2003/01/geo/wgs84_pos#location>"); > Dataset baseDataset = DatasetFactory.create(m); > try { > Directory dir = FSDirectory.open( new File("/home/martin/spatial_index")); > Dataset spatialDataset = SpatialDatasetFactory.createLucene(baseDataset, dir, > entDef); > Query query = QueryFactory.create(queryStr) ; > QueryExecution qexec = QueryExecutionFactory.create(query, spatialDataset); > ResultSet results = qexec.execSelect() ; > for ( ; results.hasNext() ; ) > { > QuerySolution soln = results.nextSolution() ; > System.out.println(soln.get("loc").toString()); > } > } catch (IOException e) { e.printStackTrace(); } > } > catch(Exception e ) { System.out.println(e.getMessage()); } > jenaSpatial.stop(); > } > } > > The above code doesn't throw any exceptions or errors, but the result object > is always empty. > I suspect that my problem is with the construction of EntityDefinition entDef > but I haven't > been able to find anything relevant in the Apache Jena's online > documentation- it contains plain Javadocs. > > Sorry for the long source code- I've tried to keep it as short as possible. > Any help would be much appreciated > > Best Regards > Martin > >
