0

I'm trying to create a local model using some information from wikidata, I started with simple queries to test the Jena interface but I found a problem, my queries doesn't show the same results when I use the endpoint www.query.wikidata.org/sparql and the Jena interface, If I run some parts of the query, it works but when I add complexity (qualifiers or statements) it doesn't work,

I don't know what is the cause and there is no error warnings in the terminal when i run the code, I don't know where to look, i don't know if it's maybe a configuration problem with the packages or there is something I miss to install, I will aprecciate if you can help me,

Thanks!

Model m = ModelFactory.createDefaultModel();

m.setNsPrefix("rdf", RDF.getURI());
m.setNsPrefix("rdfs", RDFS.getURI());
m.setNsPrefix("xsd", XSD.getURI());
m.setNsPrefix("wd", "http://www.wikidata.org/entity/"); 
m.setNsPrefix("wdt", "http://www.wikidata.org/prop/direct/"); 
m.setNsPrefix("p", "http://www.wikidata.org/prop/"); 
m.setNsPrefix("pq", "http://www.wikidata.org/prop/qualifier"); 
m.setNsPrefix("ps", "http://www.wikidata.org/prop/statement"); 

String sparqlService = "http://query.wikidata.org/sparql";

String prolog2 = "PREFIX rdf: <" + RDF.getURI() + ">";
String prolog3 = "PREFIX rdfs: <" + RDFS.getURI() + ">";
String prolog4 = "PREFIX wd: <" + m.getNsPrefixURI("wd") + ">";
String prolog5 = "PREFIX wdt: <" + m.getNsPrefixURI("wdt") + ">";
String prolog6 = "PREFIX p: <" + m.getNsPrefixURI("p") + ">";
String prolog7 = "PREFIX ps: <" + m.getNsPrefixURI("ps") + ">";
String prolog8 = "PREFIX pq: <" + m.getNsPrefixURI("pq") + ">";

String rdq = prolog2 + NL + prolog3 + NL + prolog4 + NL + prolog5 + NL + prolog6 + NL + prolog7 + NL + prolog8
                + "SELECT ?player ?from  WHERE { ?player wdt:P54 wd:Q47774 ;"
                + "p:P54 ?stat . ?stat ps:P54 wd:Q47774 ; pq:P580 ?from }";

if I run just "SELECT ?player WHERE { ?player wdt:P54 wd:Q47774 }" this part that works fine but in the moment I run the query complet as I show in the code it returns nothing, but in the web endpoint the query runs perfectly.



Query query = QueryFactory.create(rdq);
QueryExecution qexec = QueryExecutionFactory.sparqlService(sparqlService, query);
query.serialize(new IndentedWriter(System.out, true));
System.out.println();


ResultSet rs = qexec.execSelect();
ResultSetFormatter.out(System.out, rs, query)


  • 2
    "http://www.wikidata.org/prop/qualifier" and"http://www.wikidata.org/prop/statement" need a "/" on the end. `m.setNsPrefix("pq", "http://www.wikidata.org/prop/qualifier/");` and `m.setNsPrefix("ps", "http://www.wikidata.org/prop/statement/");` – AndyS Apr 06 '21 at 17:01
  • Thank you a lot, really, Thanks!!! – Cristhian Casierra Apr 07 '21 at 18:31

0 Answers0