User:Pepe piton/Queries

From Wikidata
Jump to navigation Jump to search

This is a list of queries that I find useful.

All items by a specific author[edit]

# All items by a specific author
SELECT ?work ?workLabel
WHERE
{
  ?work wdt:P50 wd:Q53553931.  # All items whose author is Rolando Astarita                      
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ASC(?workLabel)  # Show in alphabetical order
Try it!

All items by a specific author (more complete)[edit]

SELECT DISTINCT ?item ?itemLabel ?itemDescription ( COUNT ( DISTINCT ?wikisource ) as ?wikisourceFullWork ) ( COUNT ( DISTINCT ?iaID ) as ?iaDownloads ) ( COUNT ( DISTINCT ?download ) as ?otherDownloads ) 
WHERE 
{  
  { SELECT DISTINCT ?item 
   WHERE
     { 
       VALUES ?languages { "en" "es" }.                                                                                                           
       ?item ( wdt:P170 | wdt:P50 | wdt:P57 | wdt:P58 | wdt:P84 | wdt:P86 | wdt:P87 | wdt:P110 | wdt:P676 | wdt:P943 ) wd:Q734054 . 
       ?item rdfs:label ?itemLabel .
       FILTER ( lang ( ?itemLabel ) = ?languages ) . 
       MINUS { 
         VALUES ?typeOfItem { wd:Q3658341 wd:Q187931 wd:Q3375722 } 
         ?item wdt:P31 ?typeOfItem . } 
     } 
  }   
  OPTIONAL { ?item wdt:P724 ?iaID . }
  OPTIONAL { ?item wdt:P953 ?download . }
  OPTIONAL {
  ?wikisource schema:about ?item .
  ?wikisource schema:isPartOf <https://en.wikisource.org/> . }  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en, es" . }
} 
GROUP BY ?item ?itemLabel ?itemDescription
ORDER BY ASC ( ?itemLabel )
Try it!

Enslaved people[edit]

# List of enslaved people with date and place of birth
SELECT ?enslavedPerson ?enslavedPersonLabel ?dateOfBirth ?placeOfBirth ?placeOfBirthLabel
WHERE
{
  ?enslavedPerson wdt:P31 wd:Q5;  # Instance of human being...
                  wdt:P3716 wd:Q12773225.  # ...whose social status is "slave"
  OPTIONAL {
  ?enslavedPerson wdt:P569 ?dateOfBirth ;  # Look for date of birth...
                  wdt:P19 ?placeOfBirth.  # ...and place of birth
  }           
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?dateOfBirth)  # Show by descending date of birth
# ORDER BY ASC(?esclavoLabel)  # Uncomment if you want to show the query by name of the person in alphabetical order
Try it!

Women without image from a particular country[edit]

# Women without image, from a particular country, ordered by the number of Wikimedia projects in which they appear
SELECT ?woman ?womanLabel ?linkcount
WHERE
{
  ?woman wdt:P31 wd:Q5 ;   # Instance of human being...
         wdt:P21 wd:Q6581072 .  # ...whose sex or gender is female.
  ?woman wikibase:sitelinks ?linkcount .  # Count the number of sitelinks to different Wikipedias and other projects.
  { ?woman wdt:P19/wdt:P131* wd:Q77 . }  # The woman was born in Uruguay or in a place located in the administrative territorial entity of Uruguay...
  UNION  # ...or...
  { ?woman wdt:P27 wd:Q77 . }  # ...her country of citizenship is Uruguay.
  MINUS {
  ?woman wdt:P18 ?image  # Exclude if she has an image in her Wikidata item.
  } 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?woman ?womanLabel ?linkcount  # Group to avoid duplicate results.
ORDER BY DESC(?linkcount)  # Order by descending number of sitelinks. More sitelinks suggest more relevance.
Try it!

Copyright duration by country[edit]

# Copyright duration by country
SELECT ?country ?countryLabel ?setOfCountries ?setOfCountriesLabel
WHERE {  
  ?setOfCountries wdt:P279 wd:Q108698760 . # Look for sets of countries (grouped by copyright duration) that are a subclass of countries with a post mortem auctoris copyright.        
  ?setOfCountries wdt:P1001 ?country. # Find each country inside each set of countries.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ASC(?countryLabel)  # Show all countries in alphabetical order with their copyright duration.
Try it!

Authors who died 100 or more years ago and status of copyright is not set[edit]

# Authors from a country who died 100 or more years ago and expired copyright status is not set
SELECT DISTINCT ?item ?itemLabel ( GROUP_CONCAT(DISTINCT ?occupationLabel; SEPARATOR=", ") AS ?occupations )  # Concatenate occupations
WHERE {  
    ?item wdt:P31 wd:Q5 .            # Instance of human being...
  VALUES  ?occupation { wd:Q36180 wd:Q1028181 wd:Q1281618 wd:Q49757 wd:Q1930187 wd:Q639669 wd:Q36834 }.  # List of occupations
  ?item wdt:P106 ?occupation .  # The person has those occupations
  { ?item wdt:P19/wdt:P131* wd:Q77 . }  # The person was born in Uruguay or in a place located in the administrative territorial entity of Uruguay...
  UNION                                 # ...or...
  { ?item wdt:P27 wd:Q77 . }            # ...their country of citizenship is Uruguay.
  ?item wdt:P570 ?death .               # The person died...
  FILTER ( ?death < "1924-01-01"^^xsd:dateTime )  # ...before a certain date.
  MINUS { ?item wdt:P7763 ?copyrightStatus. }  # The item of the person has not a certain property.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". 
                          ?item rdfs:label ?itemLabel.               # Necessary to concatenate occupations
                          ?occupation rdfs:label ?occupationLabel.   # Necessary to concatenate occupations
                         }
}
GROUP BY ?item ?itemLabel  # Group results for the same person.
Try it!

Copyright term(s) of a country[edit]

# Copyright term(s) of a country
SELECT DISTINCT ?item ?itemLabel ( GROUP_CONCAT ( DISTINCT ?partLabel; SEPARATOR=", ") AS ?appliesToParts )  # Concatenate types of works
WHERE { 
  {?item wdt:P279 wd:Q108698760 . }  # Look for group of countries with post mortem auctoris copyright...
  UNION  # ...or...
  { ?item wdt:P279 wd:Q108701480 . }  # ...group of countries with copyright based on publication date.
  ?item p:P1001 ?countryStatement . 
  ?countryStatement ps:P1001 wd:Q241 .  # Select a specific country.
  OPTIONAL { ?countryStatement pq:P518 ?part . }  # Get the types of works to which the copyright term applies.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . 
                          ?item rdfs:label ?itemLabel .  # Necessary to concatenate types of works.
                          ?part rdfs:label ?partLabel .  # Necessary to concatenate types of works.
                         } 
} 
GROUP BY ?item ?itemLabel
Try it!

All statements from people of Uruguayan nationality[edit]

CONSTRUCT { ?item ?predicate ?object } 
WHERE { 
  ?item wdt:P31 wd:Q5 .  # Human beings...
  ?item wdt:P27 wd:Q77 .  # ...of Uruguayan nationality.
  OPTIONAL {?item ?predicate ?object} }  # Get all statements.
Try it!