SPARQL Examples: Difference between revisions

From Riga Literata
Jump to navigation Jump to search
(Created page with "=== PREFIXES === ''in Wikidata prefixes don't need to be specified explicitly in SPARQL queries''. However, in our Wikibase.cloud instance, prefixes must be explicitly stated, as [https://kbtestwikibase.wikibase.cloud/wiki/Project:SPARQL/examples#Federated_querying:_mixing_data_from_this_Wikibase_with_data_from_Wikidata this example] shows. Please note and mind the distinction between PREFIX kbwdt, kbwd, wdt and wd.<BR> <sparql list="1" tryit="1"> PREFIX rlwd: <https://...")
 
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== PREFIXES ===
== All persons with all properties ==
''in Wikidata prefixes don't need to be specified explicitly in SPARQL queries''. However, in our Wikibase.cloud instance, prefixes must be explicitly stated, as [https://kbtestwikibase.wikibase.cloud/wiki/Project:SPARQL/examples#Federated_querying:_mixing_data_from_this_Wikibase_with_data_from_Wikidata this example] shows. Please note and mind the distinction between PREFIX kbwdt, kbwd, wdt and  wd.<BR>
<sparql tryit="1">
<sparql list="1" tryit="1">
PREFIX rlwd: <https://riga-literata.wikibase.cloud/entity/>
PREFIX rlwd: <https://riga-literata.wikibase.cloud/entity/>
PREFIX rlwdt: <https://riga-literata.wikibase.cloud/prop/direct/>
PREFIX rlwdt: <https://riga-literata.wikibase.cloud/prop/direct/>


SELECT ?item ?itemLabel
SELECT ?person ?personLabel
WHERE  
(GROUP_CONCAT(DISTINCT ?genderLabel; SEPARATOR="; ") AS ?gender)
{
(GROUP_CONCAT(DISTINCT ?birthdate; SEPARATOR="; ") AS ?birthdates)
   ?item rlwdt:P1 rlwd:Q6.
(GROUP_CONCAT(DISTINCT ?birthplaceLabel; SEPARATOR="; ") AS ?birthplace)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]". }
(GROUP_CONCAT(DISTINCT ?deathdate; SEPARATOR="; ") AS ?deathdates)
}
(GROUP_CONCAT(DISTINCT ?deathplaceLabel; SEPARATOR="; ") AS ?deathplace)
(GROUP_CONCAT(DISTINCT ?worklocationLabel; SEPARATOR="; ") AS ?worklocation)
(GROUP_CONCAT(DISTINCT ?wdq; SEPARATOR="; ") AS ?wdq_id)
(GROUP_CONCAT(DISTINCT ?viaf; SEPARATOR="; ") AS ?viaf_id)
(GROUP_CONCAT(DISTINCT ?lnc10; SEPARATOR="; ") AS ?lnc10_id)
WHERE {
 
   ?person rlwdt:P1 rlwd:Q6 ;
          OPTIONAL { ?person rlwdt:P15 ?gender.}
          OPTIONAL { ?person rlwdt:P18 ?birthdate.}
          OPTIONAL { ?person rlwdt:P20 ?birthplace.}
          OPTIONAL { ?person rlwdt:P19 ?deathdate.}
          OPTIONAL { ?person rlwdt:P21 ?deathplace.}
          OPTIONAL { ?person rlwdt:P31 ?worklocation.}
          OPTIONAL { ?person rlwdt:P6 ?wdq.}
          OPTIONAL { ?person rlwdt:P30 ?viaf.}
          OPTIONAL { ?person rlwdt:P4 ?lnc10.}
 
  SERVICE wikibase:label {  
    bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]" .
    ?person rdfs:label ?personLabel .
    ?gender rdfs:label ?genderLabel .
    ?birthplace rdfs:label ?birthplaceLabel .
    ?deathplace rdfs:label ?deathplaceLabel .
    ?worklocation rdfs:label ?worklocationLabel .
  }
 
}  
GROUP BY ?person ?personLabel
ORDER BY ?personLabel
</sparql>
</sparql>

Latest revision as of 08:29, 9 February 2023

All persons with all properties

PREFIX rlwd: <https://riga-literata.wikibase.cloud/entity/>
PREFIX rlwdt: <https://riga-literata.wikibase.cloud/prop/direct/>

SELECT ?person ?personLabel
(GROUP_CONCAT(DISTINCT ?genderLabel; SEPARATOR="; ") AS ?gender)
(GROUP_CONCAT(DISTINCT ?birthdate; SEPARATOR="; ") AS ?birthdates)
(GROUP_CONCAT(DISTINCT ?birthplaceLabel; SEPARATOR="; ") AS ?birthplace)
(GROUP_CONCAT(DISTINCT ?deathdate; SEPARATOR="; ") AS ?deathdates)
(GROUP_CONCAT(DISTINCT ?deathplaceLabel; SEPARATOR="; ") AS ?deathplace)
(GROUP_CONCAT(DISTINCT ?worklocationLabel; SEPARATOR="; ") AS ?worklocation)
(GROUP_CONCAT(DISTINCT ?wdq; SEPARATOR="; ") AS ?wdq_id)
(GROUP_CONCAT(DISTINCT ?viaf; SEPARATOR="; ") AS ?viaf_id)
(GROUP_CONCAT(DISTINCT ?lnc10; SEPARATOR="; ") AS ?lnc10_id)
WHERE {

  ?person rlwdt:P1 rlwd:Q6 ;
          OPTIONAL { ?person rlwdt:P15 ?gender.}
          OPTIONAL { ?person rlwdt:P18 ?birthdate.}
          OPTIONAL { ?person rlwdt:P20 ?birthplace.}
          OPTIONAL { ?person rlwdt:P19 ?deathdate.}
          OPTIONAL { ?person rlwdt:P21 ?deathplace.}
          OPTIONAL { ?person rlwdt:P31 ?worklocation.}
          OPTIONAL { ?person rlwdt:P6 ?wdq.}
          OPTIONAL { ?person rlwdt:P30 ?viaf.}
          OPTIONAL { ?person rlwdt:P4 ?lnc10.}
  
  SERVICE wikibase:label { 
    bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]" .
    ?person rdfs:label ?personLabel .
    ?gender rdfs:label ?genderLabel .
    ?birthplace rdfs:label ?birthplaceLabel .
    ?deathplace rdfs:label ?deathplaceLabel .
    ?worklocation rdfs:label ?worklocationLabel .
  }

} 
GROUP BY ?person ?personLabel
ORDER BY ?personLabel

Try it!