I’m currently trying to familiarize myself with the topic of SPARQL queries for an AI project. Unfortunately, all queries to Wikidata work without any problems. However, queries to dbpedia generally do not produce any results.
Have there been any syntax changes between the printing of my textbook and now?
Here is an example of a Java test program that doesn’t work. Also all the usual editors, such as
OpenLink Virtuoso SPARQL Query Editor does not provide any results.
import org.apache.jena.query.*;
import org.apache.jena.rdf.model.Literal;
public class DBpediaQuery {
public static void main(String[] args) {
// Die DBpedia-SPARQL-Endpunkt-URL
String sparqlEndpoint = "http://dbpedia.org/sparql";
// Die SPARQL-Abfrage, um das Geburtsdatum abzurufen
String sparqlQuery = "PREFIX dbo: <http://dbpedia.org/ontology/> "
+ "SELECT ?birthdate "
+ "WHERE { "
+ " <http://dbpedia.org/resource/Michel_Ney> dbo:birthDate ?birthdate . "
+ "}";
Query query = QueryFactory.create(sparqlQuery);
QueryExecution queryExecution = QueryExecutionFactory.sparqlService(sparqlEndpoint, query);
try {
ResultSet results = queryExecution.execSelect();
while (results.hasNext()) {
QuerySolution solution = results.nextSolution();
Literal birthDateLiteral = solution.getLiteral("birthdate");
if (birthDateLiteral != null) {
String birthDate = birthDateLiteral.getLexicalForm();
System.out.println("Geburtsdatum von Michel Ney: " + birthDate);
} else {
System.out.println("Geburtsdatum nicht gefunden.");
}
}
} finally {
queryExecution.close();
}
}
}