java - Cannot run particular SPARQL query using Apache Jena -
i'm trying run following query using apache jena
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix vrank:<http://purl.org/voc/vrank#> prefix dbp-ont:<http://dbpedia.org/ontology/> prefix dbp-prop:<http://dbpedia.org/property/> select distinct (sample(?slabel) ?sublabel) (sample (?plabel) ?predlabel) (sample(?olabel) ?oblabel) ?v <http://dbpedia.org/> <http://people.aifb.kit.edu/ath/#dbpedia_pagerank> { { <http://dbpedia.org/resource/yao_ming> ?p ?o. filter regex(str(?o),"http://dbpedia.org/resource","i"). filter (?p != dbp-ont:wikipagewikilink && ?p != <http://purl.org/dc/terms/subject> && ?p != dbp-prop:wikipageusestemplate && ?p != rdfs:seealso && ?p != <http://www.w3.org/2002/07/owl#differentfrom> && ?p != <http://dbpedia.org/ontology/wikipagedisambiguates> && ?p != <http://dbpedia.org/ontology/wikipageredirects> ). optional {?o rdfs:label ?olabel. filter langmatches( lang(?olabel), "en" ). }. optional {?p rdfs:label ?plabel. filter langmatches( lang(?plabel), "en" ).}. optional {<http://dbpedia.org/resource/yao_ming> rdfs:label ?slabel. filter langmatches( lang(?slabel), "en" ).}. optional {?o vrank:hasrank ?r. ?r vrank:rankvalue ?v}. } union { ?s ?p <http://dbpedia.org/resource/yao_ming>. filter regex(str(?s),"http://dbpedia.org/resource","i"). filter (?p != dbp-ont:wikipagewikilink && ?p != <http://purl.org/dc/terms/subject> && ?p != dbp-prop:wikipageusestemplate && ?p != rdfs:seealso && ?p != <http://www.w3.org/2002/07/owl#differentfrom> && ?p != <http://dbpedia.org/ontology/wikipagedisambiguates> && ?p != <http://dbpedia.org/ontology/wikipageredirects> ). optional {?s rdfs:label ?slabel. filter langmatches( lang(?slabel), "en" ). }. optional {?p rdfs:label ?plabel. filter langmatches( lang(?plabel), "en" ).}. optional {<http://dbpedia.org/resource/yao_ming> rdfs:label ?olabel. filter langmatches( lang(?olabel), "en" ).}. optional {?s vrank:hasrank ?r. ?r vrank:rankvalue ?v}. } } group ?v order desc (?v)
this query taken linksum project. runs fine(results) on dbpedia sparql endpoint no rows returned jena.
this code
import org.apache.jena.query.queryexecutionfactory; import org.apache.jena.query.querysolution; import org.apache.jena.query.resultset; import org.apache.jena.query.resultsetfactory; import org.apache.jena.sparql.engine.http.queryenginehttp; string query = "..."; // mentioned query string dbpedia_sparql_service = "http://dbpedia.org/sparql/"; queryenginehttp qexec = (queryenginehttp) queryexecutionfactory.sparqlservice(dbpedia_sparql_service , query); resultset resultset = null; try { resultset = qexec.execselect(); resultset = resultsetfactory.copyresults(resultset); } catch (exception e) { // report exception } { qexec.close(); } string sublabel = "sublabel"; string predlabel = "predlabel"; string oblabel = "oblabel"; string vrank = "v"; if (resultset != null) { while (resultset.hasnext()) { querysolution result = resultset.next(); if (result != null) { system.out.println(sublabel); system.out.println(predlabel); system.out.println(oblabel); system.out.println(vrank); } } }
i have run several queries using same code 1 fails return results.
dbpedia requires ?default-graph-uri=http%3a%2f%2fdbpedia.org
in servce url or alternatively qexec.adddefaultgraph("http://dbpedia.org");
sometimes. seems case here when using from
in query.
Comments
Post a Comment