SPARQL- CASE STUDIES

1. The task is to list all albums produced by hip-hop producer Timbaland and the artists who made those albums

SOLUTION


In other to retrieve this information, we need to analyse the necessary entities here:
The general dataset is Music. If you search for Timbaland in dbpedia search, then you locate the predicate ‘producer’ , value for this is Timbaland.
The producer predicate is denoted as dbo:producer . now when you locate the prefix uri, you will notice that dbo has the url http://dbpedia.org/ontology/.
You also notice the albums beside the producer, a click on any of the names of these albums will take you to another page where the album is described. Within this page you can also notice the artist. The artist has a clickable link; hence it is another subject, when you click on it, it will take you to its description page and you can locate the label for the artist. The label has uri as http://www.w3.org/2000/01/rdf-schema# .
Timbaland is a resource, a person and falls under the uri http://dbpedia.org/resource

a.       Define all prefixes to be used
b.      Define your query
Query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://dbpedia.org/resource/>
PREFIX o:<http://dbpedia.org/ontology/>
SELECT ?albumLabel ?artistLabel where {
?music  o:producer :Timbaland .
?music rdfs:label ?albumLabel .
?music o:artist ?artist .
?artistLabel rdfs:label ?artistLabel .
}




2. 
Retrieve the members of the All Progressives Congress and their Occupation, if any member does not have occupation due to varieties in properties and ontology, and then retrieve the office or description of such member

SOLUTION


PREFIX o:<http://dbpedia.org/ontology/>
PREFIX :<http://dbpedia.org/resource/>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX dct:<http://purl.org/dc/terms/>

select ?party_member ?occupation where {
?mem o:party :All_Progressives_Congress .
?mem rdfs:label ?party_member .
?mem o:occupation ?occupation .
OPTIONAL{
?mem dct:description ?occupation . }
OPTIONAL {
?mem o:office ?occupation . }
}

 

Remember we used the dbpedia.org/snorql Sparql engine to run the above queries. 
Enjoy Sparkling the Web

 


 

Comments

Popular posts from this blog

Working with GraphQl API for Mobile App Development using Flutter Part 1