Hi everyone, I present you my apologies in advance for the long text. I searched for a while before asking to the mailing list how to instantiate a SpatialDataset, but I still fail my attempts of doing it.
Here is my problem : I have some RDF data with some that are localized geographically. Here come an extract of RDF(N-TRIPLES) data that I have : __________________________________________________________________________________________________________________ <http://www.thesis_project.org#1-2014-04> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://weblab.ow2.org/wookie#Anti-social_behaviour>. <http://www.thesis_project.org#1-2014-04> <http://weblab.ow2.org/wookie#takesPlaceAt> <http://www.thesis_project.org#E01000914>. <http://www.thesis_project.org#E01000914> <http://www.w3.org/2003/01/geo/wgs84_pos#lat> "51.518632"^^<http://www.w3.org/2001/XMLSchema#float>. <http://www.thesis_project.org#E01000914> <http://www.w3.org/2003/01/geo/wgs84_pos#long> "-0.114954"^^<http://www.w3.org/2001/XMLSchema#float>. __________________________________________________________________________________________________________________ I would like to use query such as : __________________________________________________________________________________________________________________ #SELECT event in a radius of 100m of 51.3N,-0.75W PREFIX spatial: <http://jena.apache.org/spatial#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX wookie: <http://weblab.ow2.org/wookie#> SELECT ?event { ?event wookie:takesPlaceAt ?place . ?place spatial:query (51.51 -0.115 100 'm') . } __________________________________________________________________________________________________________________ I write the following code using the spatial query page as source of inspiration ( http://jena.apache.org/documentation/query/spatial-query.html ) __________________________________________________________________________________________________________________ //imports have been skipped. public class Main { public static void main(String[] argv) throws FileNotFoundException, IOException { String path ="path to a ntriple file"; Model eventInstance = ModelFactory.createDefaultModel(); RDFDataMgr.read(eventInstance, new FileInputStream(path), Lang.NTRIPLES); Dataset spatialDataset = DatasetFactory.assemble("config.ttl", "<http://www.thesis_project.org#spatial_dataset>");//#1 spatialDataset.addNamedModel(null, eventInstance);//#2 EntityDefinition entDef = new EntityDefinition("entityField", "geoField");//#3 RAMDirectory directory = new RAMDirectory();//#4 SpatialIndex textIndex = SpatialDatasetFactory.createLuceneIndex(directory, entDef);//#5 //FAIL HERE final Dataset spatialDataset = SpatialDatasetFactory.create(spatialDataset, textIndex);//#5 String string = "PREFIX spatial: <http://jena.apache.org/spatial#>" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" + "PREFIX wookie: < <http://weblab.ow2.org/wookie#> "+ "SELECT ?event" + " {" + " ?event wookie:takesPlaceAt ?place"+ " ?place spatial:query (51.3 -0.75 100 'm') ." + " }"; spatialDataset.begin(ReadWrite.READ); final QueryExecution queryExec = QueryExecutionFactory.create(string, spatialDataset); final ResultSet resultSet = queryExec.execSelect(); while (resultSet.hasNext()) { System.out.println(resultSet.next().getResource("event")); } spatialDataset.end(); } } __________________________________________________________________________________________________________________ And I use the following config.ttl file : __________________________________________________________________________________________________________________ ## A config based on the example furnished with the tutorial at http://jena.apache.org/documentation/query/spatial-query.html @prefix : <http://www.thesis_project.org#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> . @prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> . @prefix spatial: <http://jena.apache.org/spatial#> . @prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#> # TDB [] ja:loadClass "com.hp.hpl.jena.tdb.TDB" . tdb:DatasetTDB rdfs:subClassOf ja:RDFDataset . tdb:GraphTDB rdfs:subClassOf ja:Model . # Spatial [] ja:loadClass "org.apache.jena.query.spatial.SpatialQuery" . spatial:SpatialtDataset rdfs:subClassOf ja:RDFDataset . spatial:SpatialIndexLucene rdfs:subClassOf spatial:SpatialIndex . ## --------------------------------------------------------------- :spatial_dataset rdf:type spatial:SpatialDataset ; spatial:dataset <#dataset> ; spatial:index <#indexLucene> ; . <#dataset> rdf:type tdb:DatasetTDB ; tdb:location "--mem--" ; tdb:unionDefaultGraph true ; . <#indexLucene> a spatial:SpatialIndexLucene ; #spatial:directory <file:Lucene> ; spatial:directory "mem" ; spatial:definition <#definition> ; . <#definition> a spatial:EntityDefinition ; spatial:entityField "uri" ; spatial:geoField "geo" ; # custom geo predicates for 1) Latitude/Longitude Format spatial:hasSpatialPredicatePairs ([ spatial:latitude wgs:lat ; spatial:longitude wgs:long ]) ; . __________________________________________________________________________________________________________________ I really don't understand what I'm missing. As far as I understood, the process consist in : - create an index model ( here the standard one that use wsg84 lat/long properties of resources )[#3] - define a binding between model attributes and RDF properties using the configuration file [#1] - build a dataset that contains resources compliant with the index previously defined (loading my RDF data into a Model) + the binding[#2] - give a storage space for the spatial index ( a "in memory" one in my case)[#4] - fill the index the entity of the dataset[#5] But This code fail with the following error : Exception in thread "main" com.hp.hpl.jena.assembler.exceptions.NoSpecificTypeException: the root <http://www.thesis_project.org#spatial_dataset> has no most specific type that is a subclass of ja:Object at com.hp.hpl.jena.assembler.assemblers.AssemblerGroup$PlainAssemblerGroup.open(AssemblerGroup.java:113) at com.hp.hpl.jena.assembler.assemblers.AssemblerGroup$ExpandingAssemblerGroup.open(AssemblerGroup.java:81) at com.hp.hpl.jena.assembler.assemblers.AssemblerBase.open(AssemblerBase.java:52) at com.hp.hpl.jena.assembler.assemblers.AssemblerBase.open(AssemblerBase.java:48) at com.hp.hpl.jena.query.DatasetFactory.assemble(DatasetFactory.java:267) at com.hp.hpl.jena.query.DatasetFactory.assemble(DatasetFactory.java:242) at Main.main(Main.java:30) I don't understand this error. Could someone explain me what is wrong in this "minimal" use case ? Sincerely, VAISSE-LESTEVEN Arthur.
