Java + Jena + Rdf : need help writing the correct sparql Query -
i have rdf file 1 (test.rdf
):
<?xml version="1.0"?> <rdf:rdf xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:vocab="http://www.datiopen.it/rdf/resource/vocab/" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:db="http://www.datiopen.it/rdf/resource/" xmlns:xsd="http://www.w3.org/2001/xmlschema#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:map="http://www.datiopen.it/rdf/resource/#" xmlns:dcterms="http://purl.org/dc/terms/" xml:base="http://www.datiopen.it/rdf/resource/" > <rdf:description rdf:about="http://www.w3.org/2000/01/rdf-schema#label"> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici"> <rdfs:label>trentino-alto adige - beni architettonici ed artistici</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#class"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_do_serialuid"> <rdfs:label>serial id</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_gid"> <rdfs:label>gid</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_comune"> <rdfs:label>comune</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_provincia"> <rdfs:label>provincia</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_regione"> <rdfs:label>regione</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_loc_no"> <rdfs:label>località</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_imm_no"> <rdfs:label>nome</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_via_no"> <rdfs:label>indirizzo</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_immuso_no"> <rdfs:label>uso</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_immtpl_no"> <rdfs:label>tipo</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_data_agg"> <rdfs:label>data aggiornamento</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_tp_tutela"> <rdfs:label>tipo tutela</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_imm_cd"> <rdfs:label>codice immobile</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_prov_cd"> <rdfs:label>codice provincia</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_cmp_cd"> <rdfs:label>codice cmp</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_com_cd"> <rdfs:label>codice comune</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_fraz_cd"> <rdfs:label>codice frazione</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_immtpl_cd"> <rdfs:label>codice tipo immobile</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_immuso_cd"> <rdfs:label>codice uso immobile</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_imm_prt_cd"> <rdfs:label>codice immobile prt</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_prt"> <rdfs:label>prt</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_cd_tutela"> <rdfs:label>codice tutela</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_categoria"> <rdfs:label>categoria</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_selez"> <rdfs:label>selezione</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_label_2ad"> <rdfs:label>etichetta_2ad</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_label"> <rdfs:label>etichetta</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_glatitude"> <rdfs:label>do_y</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="vocab/view_tbeni_architettonici_glongitude"> <rdfs:label>do_x</rdfs:label> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#property"/> </rdf:description> <rdf:description rdf:about="view_tbeni_architettonici/1"> <rdfs:label>view_tbeni_architettonici #1</rdfs:label> <vocab:view_tbeni_architettonici_do_serialuid rdf:datatype="http://www.w3.org/2001/xmlschema#integer">1</vocab:view_tbeni_architettonici_do_serialuid> <dcterms:coverage rdf:resource="http://spcdata.digitpa.gov.it/comune/h517" /> <vocab:view_tbeni_architettonici_loc_no></vocab:view_tbeni_architettonici_loc_no> <vocab:view_tbeni_architettonici_imm_no>chiesa di s. antonio abate</vocab:view_tbeni_architettonici_imm_no> <vocab:view_tbeni_architettonici_via_no></vocab:view_tbeni_architettonici_via_no> <vocab:view_tbeni_architettonici_immuso_no>chiesa</vocab:view_tbeni_architettonici_immuso_no> <vocab:view_tbeni_architettonici_immtpl_no>chiesa</vocab:view_tbeni_architettonici_immtpl_no> <vocab:view_tbeni_architettonici_data_agg>10/04/2001</vocab:view_tbeni_architettonici_data_agg> <vocab:view_tbeni_architettonici_tp_tutela>dichiarato di interesse culturale ai sensi del d.lgs. 22/01/2004 n. 42</vocab:view_tbeni_architettonici_tp_tutela> <vocab:view_tbeni_architettonici_imm_cd>155.0004</vocab:view_tbeni_architettonici_imm_cd> <vocab:view_tbeni_architettonici_prov_cd>22</vocab:view_tbeni_architettonici_prov_cd> <vocab:view_tbeni_architettonici_cmp_cd>6</vocab:view_tbeni_architettonici_cmp_cd> <vocab:view_tbeni_architettonici_com_cd>155</vocab:view_tbeni_architettonici_com_cd> <vocab:view_tbeni_architettonici_fraz_cd>0</vocab:view_tbeni_architettonici_fraz_cd> <vocab:view_tbeni_architettonici_immtpl_cd>18</vocab:view_tbeni_architettonici_immtpl_cd> <vocab:view_tbeni_architettonici_immuso_cd>7</vocab:view_tbeni_architettonici_immuso_cd> <vocab:view_tbeni_architettonici_imm_prt_cd>2</vocab:view_tbeni_architettonici_imm_prt_cd> <vocab:view_tbeni_architettonici_prt>ecclesiastica</vocab:view_tbeni_architettonici_prt> <vocab:view_tbeni_architettonici_cd_tutela>1.00000000000</vocab:view_tbeni_architettonici_cd_tutela> <vocab:view_tbeni_architettonici_categoria>beni religiosi</vocab:view_tbeni_architettonici_categoria> <vocab:view_tbeni_architettonici_selez>1</vocab:view_tbeni_architettonici_selez> <vocab:view_tbeni_architettonici_label_2ad>t244</vocab:view_tbeni_architettonici_label_2ad> <vocab:view_tbeni_architettonici_label>t245</vocab:view_tbeni_architettonici_label> <vocab:view_tbeni_architettonici_glatitude>46.3958455087868</vocab:view_tbeni_architettonici_glatitude> <vocab:view_tbeni_architettonici_glongitude>11.1224323995498</vocab:view_tbeni_architettonici_glongitude> <rdf:type rdf:resource="vocab/view_tbeni_architettonici"/> </rdf:description> <rdf:description rdf:about="view_tbeni_architettonici/2"> <rdfs:label>view_tbeni_architettonici #2</rdfs:label> <vocab:view_tbeni_architettonici_do_serialuid rdf:datatype="http://www.w3.org/2001/xmlschema#integer">2</vocab:view_tbeni_architettonici_do_serialuid> <dcterms:coverage rdf:resource="http://spcdata.digitpa.gov.it/comune/h517" /> <vocab:view_tbeni_architettonici_loc_no></vocab:view_tbeni_architettonici_loc_no> <vocab:view_tbeni_architettonici_imm_no>maso s. bartolomeo</vocab:view_tbeni_architettonici_imm_no> <vocab:view_tbeni_architettonici_via_no></vocab:view_tbeni_architettonici_via_no> <vocab:view_tbeni_architettonici_immuso_no>abitazione</vocab:view_tbeni_architettonici_immuso_no> <vocab:view_tbeni_architettonici_immtpl_no>maso</vocab:view_tbeni_architettonici_immtpl_no> <vocab:view_tbeni_architettonici_data_agg>10/04/2001</vocab:view_tbeni_architettonici_data_agg> <vocab:view_tbeni_architettonici_tp_tutela>dichiarato di interesse culturale ai sensi del d.lgs. 22/01/2004 n. 42</vocab:view_tbeni_architettonici_tp_tutela> <vocab:view_tbeni_architettonici_imm_cd>155.0001</vocab:view_tbeni_architettonici_imm_cd> <vocab:view_tbeni_architettonici_prov_cd>22</vocab:view_tbeni_architettonici_prov_cd> <vocab:view_tbeni_architettonici_cmp_cd>6</vocab:view_tbeni_architettonici_cmp_cd> <vocab:view_tbeni_architettonici_com_cd>155</vocab:view_tbeni_architettonici_com_cd> <vocab:view_tbeni_architettonici_fraz_cd>0</vocab:view_tbeni_architettonici_fraz_cd> <vocab:view_tbeni_architettonici_immtpl_cd>26</vocab:view_tbeni_architettonici_immtpl_cd> <vocab:view_tbeni_architettonici_immuso_cd>1</vocab:view_tbeni_architettonici_immuso_cd> <vocab:view_tbeni_architettonici_imm_prt_cd>3</vocab:view_tbeni_architettonici_imm_prt_cd> <vocab:view_tbeni_architettonici_prt>privata</vocab:view_tbeni_architettonici_prt> <vocab:view_tbeni_architettonici_cd_tutela>1.00000000000</vocab:view_tbeni_architettonici_cd_tutela> <vocab:view_tbeni_architettonici_categoria>manufatti insediativi</vocab:view_tbeni_architettonici_categoria> <vocab:view_tbeni_architettonici_selez>0</vocab:view_tbeni_architettonici_selez> <vocab:view_tbeni_architettonici_label_2ad></vocab:view_tbeni_architettonici_label_2ad> <vocab:view_tbeni_architettonici_label></vocab:view_tbeni_architettonici_label> <vocab:view_tbeni_architettonici_glatitude>46.39434215468</vocab:view_tbeni_architettonici_glatitude> <vocab:view_tbeni_architettonici_glongitude>11.1090853812521</vocab:view_tbeni_architettonici_glongitude> <rdf:type rdf:resource="vocab/view_tbeni_architettonici"/> </rdf:description> ..... ..... ..... <rdf:description rdf:about="view_tbeni_architettonici/1835"> <rdfs:label>view_tbeni_architettonici #1835</rdfs:label> <vocab:view_tbeni_architettonici_do_serialuid rdf:datatype="http://www.w3.org/2001/xmlschema#integer">1835</vocab:view_tbeni_architettonici_do_serialuid> <dcterms:coverage rdf:resource="http://spcdata.digitpa.gov.it/comune/h506" /> <vocab:view_tbeni_architettonici_loc_no></vocab:view_tbeni_architettonici_loc_no> <vocab:view_tbeni_architettonici_imm_no>eremo e chiesa di s. biagio</vocab:view_tbeni_architettonici_imm_no> <vocab:view_tbeni_architettonici_via_no></vocab:view_tbeni_architettonici_via_no> <vocab:view_tbeni_architettonici_immuso_no></vocab:view_tbeni_architettonici_immuso_no> <vocab:view_tbeni_architettonici_immtpl_no>eremo</vocab:view_tbeni_architettonici_immtpl_no> <vocab:view_tbeni_architettonici_data_agg>10/04/2001</vocab:view_tbeni_architettonici_data_agg> <vocab:view_tbeni_architettonici_tp_tutela>dichiarato di interesse culturale ai sensi del d.lgs. 22/01/2004 n. 42</vocab:view_tbeni_architettonici_tp_tutela> <vocab:view_tbeni_architettonici_imm_cd>154.0001</vocab:view_tbeni_architettonici_imm_cd> <vocab:view_tbeni_architettonici_prov_cd>22</vocab:view_tbeni_architettonici_prov_cd> <vocab:view_tbeni_architettonici_cmp_cd>6</vocab:view_tbeni_architettonici_cmp_cd> <vocab:view_tbeni_architettonici_com_cd>154</vocab:view_tbeni_architettonici_com_cd> <vocab:view_tbeni_architettonici_fraz_cd>0</vocab:view_tbeni_architettonici_fraz_cd> <vocab:view_tbeni_architettonici_immtpl_cd>68</vocab:view_tbeni_architettonici_immtpl_cd> <vocab:view_tbeni_architettonici_immuso_cd>0</vocab:view_tbeni_architettonici_immuso_cd> <vocab:view_tbeni_architettonici_imm_prt_cd>3</vocab:view_tbeni_architettonici_imm_prt_cd> <vocab:view_tbeni_architettonici_prt>privata</vocab:view_tbeni_architettonici_prt> <vocab:view_tbeni_architettonici_cd_tutela>1.00000000000</vocab:view_tbeni_architettonici_cd_tutela> <vocab:view_tbeni_architettonici_categoria>beni religiosi</vocab:view_tbeni_architettonici_categoria> <vocab:view_tbeni_architettonici_selez>1</vocab:view_tbeni_architettonici_selez> <vocab:view_tbeni_architettonici_label_2ad>t243</vocab:view_tbeni_architettonici_label_2ad> <vocab:view_tbeni_architettonici_label>t244</vocab:view_tbeni_architettonici_label> <vocab:view_tbeni_architettonici_glatitude>46.3921621030441</vocab:view_tbeni_architettonici_glatitude> <vocab:view_tbeni_architettonici_glongitude>11.0775100584678</vocab:view_tbeni_architettonici_glongitude> <rdf:type rdf:resource="vocab/view_tbeni_architettonici"/> </rdf:description> </rdf:rdf>
how can extract rows have lat/lon coordinates between given range? use java , jena build query following schema code:
model m = filemanager.get().loadmodel( config.ontobasepath + "test.rdf" ); string querystring = "prefix db: <http://www.datiopen.it/catalogsparql/resource/> " + "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + "prefix owl: <http://www.w3.org/2002/07/owl#> " + "prefix map: <http://www.datiopen.it/catalogsparql/resource/#> " + "prefix xsd: <http://www.w3.org/2001/xmlschema#> " + "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "prefix vocab: <http://www.datiopen.it/catalogsparql/resource/vocab/> " + "select ?subject ?lat ?lon " + "where { " + "?subject rdfs:label ?label . " + "?subject vocab:view_tbeni_architettonici_glatitude ?lat . " + "?subject vocab:view_tbeni_architettonici_glongitude ?lon . " + "filter( xsd:float(?lat) - 46.39584550 <= 0.05 && 46.39584550 - xsd:float(?lat) <= 0.05 " + " && xsd:float(?long) - 11.12243239 <= 0.05 && 11.12243239 - xsd:float(?long) <= 0.05 ) " + "} " ; query query = queryfactory.create(querystring); // execute query , obtain results queryexecution qe = queryexecutionfactory.create(query, m); try { resultset results = qe.execselect(); while (results.hasnext()) { querysolution qs = results.nextsolution(); literal name = qs.getliteral("x"); system.out.println(name); } } catch (exception e){ e.printstacktrace(); } { qe.close(); }
but i'm not able obtain expected results. empty result set. can me write correct query?
your vocab
prefix looks should same in data , query, it's not. in data, have:
xmlns:vocab="http://www.datiopen.it/rdf/resource/vocab/"
but in query have
prefix vocab: <http://www.datiopen.it/catalogsparql/resource/vocab/>
there few prefixes this. data (converted turtle the
@prefix db: <http://www.datiopen.it/rdf/resource/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix xsd: <http://www.w3.org/2001/xmlschema#> . @prefix map: <http://www.datiopen.it/rdf/resource/#> . @prefix vocab: <http://www.datiopen.it/rdf/resource/vocab/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix dcterms: <http://purl.org/dc/terms/> .
and query has these:
prefix db: <http://www.datiopen.it/catalogsparql/resource/> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix owl: <http://www.w3.org/2002/07/owl#> prefix xsd: <http://www.w3.org/2001/xmlschema#> prefix map: <http://www.datiopen.it/catalogsparql/resource/#> prefix vocab: <http://www.datiopen.it/catalogsparql/resource/vocab/> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
the prefixes db
, map
, , vocab
not match, you're querying quite different what's in data.
Comments
Post a Comment