java - jena.query.ResultSet: hasNext() evaluates false but should contain something -



java - jena.query.ResultSet: hasNext() evaluates false but should contain something -

i seek query dbpedia 3.9 datasets on virtuoso (local, 7.0.0). query works fine on sparql endpoint, when using jena, resultset virtuoso query execution not contain nil (hasnext() false). had here , here, still have pb.

below code using. have thought of what's wrong?

thanks.

import virtuoso.jena.driver.virtgraph; import virtuoso.jena.driver.virtuosoqueryexecution; import virtuoso.jena.driver.virtuosoqueryexecutionfactory; import com.hp.hpl.jena.query.querysolution; import com.hp.hpl.jena.query.resultset; import com.hp.hpl.jena.rdf.model.rdfnode; import com.hp.hpl.jena.rdf.model.resource; public static void testdbpedialex(resource dbpedia) { string query = " prefix lexvo: <http://lexvo.org/ontology#> \n" + " prefix rdf: <http://www.w3.org/2000/01/rdf-schema#> \n\n" + " select ?lexlabel { \n" + " <http://dbpedia.org/resource/fernando_alonso> lexvo:label ?lexlabel . \n" + " <http://dbpedia.org/resource/fernando_alonso> rdf:label ?label . \n" + " filter (?lexlabel != ?label) . } "; virtgraph graph = new virtgraph ("http://dbpedia.org/", "jdbc:virtuoso://localhost:1111", "dba", "dba"); virtuosoqueryexecution vqlex = virtuosoqueryexecutionfactory.create(query, graph); resultset rlex = virtuosoconnection.executevirtuosoquery(vqlex); if(rlex != null) { while (rlex.hasnext()) { querysolution result = rlex.nextsolution(); system.out.println(result.get("lexlabel")); i++; } } }

finally found solution pb, here come more details.

with next sparql query want labels of given resource (whatever), defined via properties rdfs:label , lexvo:label. first 1 applies on triples (dbpedia label dataset), sec on quads (dbpedia spotlight lexicalization dataset).

prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix lexvo: <http://lexvo.org/ontology#> select ?lexlabel { <http://dbpedia.org/resource/fernando_alonso> lexvo:label ?lexlabel . <http://dbpedia.org/resource/fernando_alonso> rdfs:label ?label filter langmatches(lang(?label), "en") filter langmatches(lang(?lexlabel), "en") filter ( ?lexlabel != ?label ) }

on local sparql endpoint (virtuoso.ini) default graph not specified. graph iri on sparql endpoint hence empty, , query works under these conditions.

using virtuoso jena provider, virtgraph defined graph http://dbpedia.org, , in case query not give result. indeed, same happens when specifying http://dbpedia.org in graph iri field of sparql endpoint, error of not checking this.

finally, retrieve results via jena (i.e. using virtgraph http://dbpedia.org), query should specify graph's dataset when needed:

select ?lexlabel { graph ?g {<http://dbpedia.org/resource/fernando_alonso> lexvo:label ?lexlabel . } <http://dbpedia.org/resource/fernando_alonso> rdfs:label ?label . filter (langmatches(lang(?label), "en")) filter (langmatches(lang(?lexlabel), "en")) filter (?lexlabel != ?label) . }

which gives next labels: "alonso"@en, "fernando"@en , "alo"@en.

java sparql jena virtuoso

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -