0

I am not very used to SPARQL, but I managed to write my own query for books and their genres, authors and their dates of birth and death at https://query.wikidata.org

SELECT
?title ?titleLabel 
(GROUP_CONCAT(DISTINCT(?authorLabel); separator="//") as ?authors)
(GROUP_CONCAT(DISTINCT(?dateborn); separator="//") as ?date_born)
(GROUP_CONCAT(DISTINCT(?datedeath); separator="//") as ?date_death)
(GROUP_CONCAT(DISTINCT(?datepub); separator="//") as ?date_pub)
(GROUP_CONCAT(DISTINCT(?genre_titleLabel); separator="//") as ?genre_title)
WHERE
{
?title wdt:P31 wd:Q571 .
?title wdt:P50 ?author . 
?title wdt:P577 ?date_pub .
?author wdt:P569 ?date_born .
?author wdt:P570 ?date_death .
?title wdt:P136 ?genre_title .
BIND(CONCAT(STR(DAY(?date_pub)),"-",STR(MONTH(?date_pub)),"-",STR(YEAR(?date_pub))) AS ?datepub )
BIND(CONCAT(STR(DAY(?date_born)),"-",STR(MONTH(?date_born)),"-",STR(YEAR(?date_born))) AS ?dateborn )
BIND(CONCAT(STR(DAY(?date_death)),"-",STR(MONTH(?date_death)),"-",STR(YEAR(?date_death))) AS ?datedeath ) 
FILTER (?date_born > "1900-01-01T00:00:00Z"^^xsd:dateTime) .
FILTER (?date_born < "1905-12-31T23:59:59Z"^^xsd:dateTime)
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
?title rdfs:label ?titleLabel .
?author rdfs:label ?authorLabel .
?date_pub rdfs:label ?date_pubLabel .
?date_born rdfs:label ?date_bornLabel .
?date_death rdfs:label ?date_deathLabel .
?genre_title rdfs:label ?genre_titleLabel .
}
}
GROUP BY ?title ?titleLabel

It works and I get all the genres in the same field. The only way I could get this was with

(GROUP_CONCAT(DISTINCT(

for genres and dates. But If you loook in the results there are records with more than one date. And I want to get only the first date, and not all the stored dates in the database for this record, but I can't.

For example, If I ask for

?dateborn 

instead of

(GROUP_CONCAT(DISTINCT(?dateborn); separator="//") as ?date_born)

I get an error. Do you know where is my mistake?

Greets

N.

logi-kal
  • 7,107
  • 6
  • 31
  • 43
  • `SAMPLE` is the function which returns an arbitrary value. For example, `(SAMPLE(?dateborn) as ?date_born)` instead of `(GROUP_CONCAT(DISTINCT(?dateborn); separator="//") as ?date_born)` – UninformedUser Feb 01 '17 at 13:28
  • Thank you very much, that works! –  Feb 01 '17 at 14:04

0 Answers0