I'm new to SPARQL and RDF. Bascially I have to design federated SPARQL 1.1 query over Wikidata and Dbpedia.
Here's my simple query. This will select the films starring Leonardo Di Caprio.
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?film WHERE {
{
SELECT ?film WHERE {
?film wdt:P161 wd:Q38111.
}
}
UNION
{
SELECT ?film WHERE {
?film rdf:type dbo:Film .
?film dbo:starring dbr:Leonardo_DiCaprio .
}
}
}
I have to construct a graph on that. Can anyone help me on this type of query? I'm testing it on Apache Jena.
In SPARQL,
SELECT
queries will give you an answer formalized as a table.To get triples, you need to use a
CONSTRUCT
query and therefore create a graph on them.With the response of the
CONSTRUCT
query, you simply need to add the Statement to the Graph.