Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DBpedia SPARQL - getting image and resource link of other artists?

Tags:

sparql

dbpedia

Given a musical artist, I am trying to find other musical artists who have the most common "associatedActs of" with a particular artist. I have the following query for Eminem and it works fine

SELECT ?c (COUNT(*) AS ?count) WHERE {
{
?b <http://dbpedia.org/property/associatedActs> <http://dbpedia.org/resource/Eminem>.
?b <http://dbpedia.org/property/associatedActs> ?
}
}group by ?c order by desc(?count) LIMIT 10

But I would like to get back the picture of the artist as well as their dbpedia resource link (?c) adding. Trying this

SELECT ?c (COUNT(*) AS ?count) WHERE {
{
?b <http://dbpedia.org/property/associatedActs> <http://dbpedia.org/resource/Eminem>.
?b <http://dbpedia.org/property/associatedActs> ?c.
?c <http://dbpedia.org/ontology/thumbnail> ?i
}
}group by ?c order by desc(?count) LIMIT 10

gives me an error "Variable ?i is used in the result set outside aggregate and not mentioned in GROUP BY clause". If i groupby by i it works fine but I can't get ?c back.

So how can I get the picture and the resource link other matching artists?

like image 576
user972616 Avatar asked Mar 27 '12 12:03

user972616


2 Answers

Use sub-queries:

SELECT ?c ?i ?count WHERE { {SELECT ?c (COUNT(*) AS ?count) WHERE {
{
?b <http://dbpedia.org/property/associatedActs> <http://dbpedia.org/resource/Eminem>.
?b <http://dbpedia.org/property/associatedActs> ?c .

}
} group by ?c order by desc(?count) LIMIT 10} . ?c <http://dbpedia.org/ontology/thumbnail> ?i }

you can find the result here.

like image 172
ip. Avatar answered Nov 16 '22 02:11

ip.


Just like in SQL, you can use GROUP BY with multiple variables.

This seems to work:

SELECT ?c (COUNT(*) AS ?count) ?i WHERE {

?b <http://dbpedia.org/property/associatedActs> <http://dbpedia.org/resource/Eminem>.
?b <http://dbpedia.org/property/associatedActs> ?c.
?c <http://dbpedia.org/ontology/thumbnail> ?i

} GROUP BY ?c ?i ORDER BY desc(?count) LIMIT 10

See the results here.

like image 41
Ben Companjen Avatar answered Nov 16 '22 03:11

Ben Companjen