I would like to get Daft Punk's discography from dbpedia, and for each album I would like to show: 1) The title 2) The release year 3) The wikipedia page, so I wrote this query:
PREFIX d: <http://dbpedia.org/ontology/>
PREFIX prop: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX : <http://dbpedia.org/resource/>
SELECT DISTINCT str(?name) YEAR(?relDate) AS ?relYear ?wiki WHERE {
?album a d:Album .
?album foaf:name ?name .
?album d:artist :Daft_Punk .
?album foaf:isPrimaryTopicOf ?wiki .
?album d:releaseDate ?relDate .
}
ORDER BY ?relDate
Which works, except for the fact that there is one album (Alive 2007) which has 2 different release years (as you can see here), but I would like to show only the earliest of the two. How should I edit my query to make this album appear only once with the first date? Thanks for your answers.
"PREFIX", however (without the "@"), is the SPARQL instruction for a declaration of a namespace prefix. It allows you to write prefixed names in queries instead of having to use full URIs everywhere. So it's a syntax convenience mechanism for shorter, easier to read (and write) queries.
OPTIONAL is a binary operator that combines two graph patterns. The optional pattern is any group pattern and may involve any SPARQL pattern types. If the group matches, the solution is extended, if not, the original solution is given (q-opt3. rq).
BIND. SPARQL's BIND function allows us to assign a value to a variable.
You could use the MIN
aggregate to extract the minimum value of the release year, when the result has been grouped using the GROUP BY
feature of SPARQL 1.1.
For example, something like this:
PREFIX d: <http://dbpedia.org/ontology/>
PREFIX prop: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX : <http://dbpedia.org/resource/>
SELECT str(?name) MIN(YEAR(?relDate)) AS ?relYear ?wiki
WHERE {
?album a d:Album .
?album foaf:name ?name .
?album d:artist :Daft_Punk .
?album foaf:isPrimaryTopicOf ?wiki .
?album d:releaseDate ?relDate .
}
GROUP BY ?name ?wiki
ORDER BY ?relYear
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