Reputation: 481
I was recently asked to connect a customers music database application to wikipedia. He wants to update his database of artists with discographies and each album with its tracks and singles. He insists on using wikipedia.
I have given some time into study of wikimedia api, but I am not that familiar with the Wikipedia structure and so far haven't been able to create a set of queries that would get me what I want. In the customers database each artists has an identificator string from Wikidata (something like Q123) - I believe this could be my starting point - using wikidata to get to the right wikipedia page. But from there, I am lost.
Is there someone with good knowledge of wikipedia api who would be willing to give me directions on how to get this specific sort of information?
Upvotes: 0
Views: 1324
Reputation: 1631
Right now, queries on Wikidata is being built, so it is not yet possible through the official API. However, there is a tool called Wikidata Query (documentation) which can do stuff like this.
Here is an example, using this query: CLAIM[31:(TREE[482994][][279])] AND CLAIM[175:392]
. It looks for objects having property 31 (instance of) with a value of anything in the tree of 279 (subgroup) starting on 482994 (album) AND has property 175 (performer) with value 392 (Bob Dylan). It returns the Wikidata IDs of the albums, which you in turn can look up the label for on the Wikidata API. You just have to change the value for the performer to get the answer for any artist.
UPDATE: The tool above is deprecated, but now the official tool is available. This is the SPARQL code for the same results:
SELECT ?album WHERE {
?album wdt:P31/wdt:P279* wd:Q482994 ;
wdt:P175 wd:Q392 .
}
Short link to that query: https://w.wiki/6tL
And if you want to add the label of the album it is possible directly in the query:
SELECT ?album ?albumLabel WHERE {
?album wdt:P31/wdt:P279* wd:Q482994 ;
wdt:P175 wd:Q392 .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Short link to that query: https://w.wiki/6tM
Upvotes: 2