Select only the first object from sparql query

前端 未结 1 1386
名媛妹妹
名媛妹妹 2021-01-04 18:03

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

相关标签:
1条回答
  • 2021-01-04 19:01

    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
    
    0 讨论(0)
提交回复
热议问题