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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With