User:Every-leaf-that-trembles/sandbox

From Wikidata
Jump to navigation Jump to search


Babel user information
en-N This user has a native understanding of English.
de-1 Dieser Benutzer beherrscht Deutsch auf grundlegendem Niveau.
ru-0 Этот участник не владеет русским языком (или понимает его с трудом).
Users by language

query

Query #1: List all items Q1, that are instances/subclasses of item Q2

[edit]
  1. in this example, all knives
SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P31/wdt:P279* wd:Q32489 .          # <-- CHANGE HERE for different predicate
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

Query #1: List districts of Russia, by federal subject, with pictures

[edit]
#Query to list districts of Russia, by federal subject (here, 'region', and whether they have pictures or not
PREFIX schema: <http://schema.org/>	# remember to add this
SELECT DISTINCT ?region ?regionLabel ?dist ?distLabel ?wplink ?pic # ?coord 
WHERE {
      ?dist wdt:P31 wd:Q2198484	.	      # district - is a - Russian district
      ?region wdt:P131 wd:Q159 .        # region - is in administrative district of - Russia
      ?dist wdt:P131 ?region .           # district - is located in the administrative territory of - a region
      BIND (wd:Q2753 AS ?region) .       # Limits results to Ryazan Oblast (Q2753)
      # OPTIONAL {?dist wdt:P625 ?coord }   # district - has geographic coordinates of - ?coord (if added column for items that exist)
      OPTIONAL {?dist wdt:P18 ?pic } .        # add a column for pics (p18) if there is one in WD   (toggle w/next line) 
      #MINUS {?dist wdt:P18 ?pic} .           # use this instead of previous line to see items with NO PIC
      OPTIONAL {
         ?wplink schema:about ?dist .   # WP link - is about - ?dist
         ?wplink schema:inLanguage "en" .
         ?wplink schema:isPartOf <https://en.wikipedia.org/> .
      }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ASC(?regionLabel) ?distLabel
Try it!

Query #2: List the Districts of Russia that DO NOT HAVE a photo in WikiData

[edit]
#Query to list districts of Russia, by federal subject (here, 'region', and whether they have pictures or not
PREFIX schema: <http://schema.org/>	# remember to add this
SELECT DISTINCT ?region ?regionLabel ?dist ?distLabel ?wplink ?pic # ?coord 
WHERE {
      ?dist wdt:P31 wd:Q2198484	.	      # district - is a - Russian district
      ?region wdt:P131 wd:Q159 .        # region - is in administrative district of - Russia
      ?dist wdt:P131 ?region .           # district - is located in the administrative territory of - a region
      #BIND (wd:Q1749 AS ?region) .       # <------ CHANGE THIS TO SEE A DIFFERENT OBLAST/KRAI/etc.
      # OPTIONAL {?dist wdt:P625 ?coord }   # district - has geographic coordinates of - ?coord (if added column for items that exist)
      #OPTIONAL {?dist wdt:P18 ?pic } .        # add a column for pics (p18) if there is one in WD   (toggle w/next line) 
      MINUS {?dist wdt:P18 ?pic} .           # use this instead of previous line to see items with NO PIC
      OPTIONAL {
         ?wplink schema:about ?dist .   # WP link - is about - ?dist
         ?wplink schema:inLanguage "en" .
         ?wplink schema:isPartOf <https://en.wikipedia.org/> .
      }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ASC(?regionLabel) ?distLabel
Try it!

Query #3: List the Federal Subjects (Oblasts, Krais, etc) of the Russian Federation

[edit]
#Query to list oblasts and republics of Russia
PREFIX schema: <http://schema.org/>	# remember to add this
SELECT DISTINCT ?region ?regionLabel ?wplink
WHERE {
      {?region wdt:P31 wd:Q835714} UNION {?region wdt:P31 wd:Q41162} UNION {?region wdt:P31 wd:Q831740} union {?region wdt:P31 wd:Q184122} 
           UNION {?region wdt:P31 wd:Q183342} . 
                    # region - is an instance of an oblast, republic, or krai of - Russia
      ?region wdt:P131 wd:Q159 .        # region - is in administrative district of - Russia
      # BIND (wd:Q2753 AS ?region) .       # Limits results to Ryazan Oblast (Q2753)
      # OPTIONAL {?dist wdt:P625 ?coord }   # district - has geographic coordinates of - ?coord (if added column for items that exist)
      # OPTIONAL {?dist wdt:P18 ?pic } .        # add a column for pics (p18) if there is one in WD   (toggle w/next line) 
      #MINUS {?dist wdt:P18 ?pic} .           # use this instead of previous line to see items with NO PIC
      OPTIONAL {
         ?wplink schema:about ?region .   # WP link - is about - ?region
         ?wplink schema:inLanguage "en" .
         ?wplink schema:isPartOf <https://en.wikipedia.org/> .
      }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ASC(?regionLabel)
Try it!

Query #4: List WWF Ecoregions that have are marked as such with P31

[edit]
  1. Query to list WWF Ecoregions
SELECT DISTINCT ?x ?y ?xLabel ?map ?pic ?wplink 
WHERE {
  ?x wdt:P31 wd:Q6617741 .     
  ?x wdt:P17 wd:Q148 .
  # OPTIONAL { ?x wdt:P1294 ?y }.
  ?x wdt:P1294 ?y .
  # MINUS { ?x wdt:P1294 ?y }.
  # FILTER ( regex(?y, "AT", "i")) .
  OPTIONAL {?x wdt:P18 ?pic} .
  OPTIONAL {?x wdt:P242 ?map} .
  OPTIONAL  {
         ?wplink schema:about ?x .   # WP link - is about - ?ecoreg
         ?wplink schema:inLanguage "en" .
         ?wplink schema:isPartOf <https://en.wikipedia.org/> .
  }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ASC(?xLabel)
Try it!

Query #5: List National Parks in Ukraine, with Ukrainian labels, and images

[edit]
  1. List information useful for building a page about Ukraine National Parks
SELECT ?np ?npLabelEN ?npLabelUK ?coord ?pic ?ccat
WHERE 
{
  ?np wdt:P31/wdt:P279* wd:Q1296040 .          # <-- CHANGE HERE for different predicate
  OPTIONAL { ?np wdt:P625 ?coord .}
  OPTIONAL { ?np wdt:P18 ?pic .}
  OPTIONAL { ?np wdt:P373 ?ccat .}
  ?np rdfs:label ?npLabelUK filter (lang(?npLabelUK) = "uk") .
  OPTIONAL {
    ?np rdfs:label ?npLabelEN filter (lang(?npLabelEN) = "en")
  }
}
ORDER BY ?npLabelEN
Try it!

Query #6: Experimenting with Qualifiers

[edit]
  1. Mona Lisa tests from Tutorial
SELECT ?statement1
WHERE 
{
wd:Q12418 p:P186 ?statement1.    # Mona Lisa: material used: ?statement1
?statement1 ps:P186 wd:Q291034.  # 
?statement1 pq:P518 wd:Q861259.  # qualifier: applies to part: painting surface

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

Query #7: Experimenting with Qualifiers

[edit]
  1. Revenue of a country, by year
Select ?x ?xLabel ?revamt ?revunitLabel ?year WHERE {
  BIND(wd:Q1349918 AS ?x).
  ?x p:P2139 ?y .
  ?y psv:P2139 ?revnode .
  ?revnode wikibase:quantityAmount ?revamt .
  ?revnode wikibase:quantityUnit ?revunit .
  ?y pq:P585 ?year .
  FILTER(YEAR(?year) = 2017).   
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

Query #8: Experimenting with Qualifiers [NOT MINE; THIS IS FROM THE EXAMPLES PAGE]

[edit]
  1. Properties grouped by their parent property
  2. TODO: should display links and numeric ids
#defaultView:Tree
SELECT ?property2 ?property2Label ?property1 ?property1Label WHERE {
  ?property1 rdf:type wikibase:Property. #not replaceable with wikibase:Item, wikibase:Statement, wikibase:Reference at WDQS
                                         #https://www.mediawiki.org/wiki/Wikibase/Indexing/RDF_Dump_Format#WDQS_data_differences
  ?property1 wdt:P1647 ?property2.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

Query #9: Units of measure

[edit]
SELECT DISTINCT ?s ?label ?pLabel WHERE {
  ?s wdt:P31/wdt:P279* wd:Q47574 .
  ?s wdt:P31 ?p .
  MINUS {?s wdt:P31 wd:Q8142 .}
  OPTIONAL {?s rdfs:label ?label filter (lang(?label) = "en").}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

Query #10: Properties and values

[edit]
# items with property Pxxxx, its object, ordered by # of sitelinks
SELECT ?item ?itemLabel ?value ?sl
{
  {
       SELECT *
       {
          ?item wdt:P461 ?value ; wikibase:sitelinks ?sl
       }
       ORDER BY DESC(?sl) 
       LIMIT 2000
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?sl) ?item
Try it!

Query #11: Paintings by Renior in the Metropolitan Museum of Art

[edit]
#defaultView:ImageGrid
SELECT DISTINCT ?s ?sLabel ?image WHERE {
   ?s wdt:P195 wd:Q160236 .
   ?s wdt:P170 wd:Q39931 .
   ?s wdt:P18 ?image .
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

Query #12: The emergency #'s in each country, and who they call

[edit]
  1. An example of use of statement qualifiers, in this case P366 'use'.
SELECT DISTINCT ?countryLabel ?numLabel ?useLabel WHERE {
  {?country wdt:P31 wd:Q6256} 
  UNION {?country wdt:P31 wd:Q3624078} .
  ?country p:P2852 ?number .
  ?number ps:P2852 ?num .
  ?number pq:P366 ?use .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?countryLabel
Try it!

Query #13: All articles with pictures within X [kilometers] of a location

[edit]
  1. Example of searching for pictures near a particular location
SELECT ?place ?placeLabel ?pic ?location ?instanceLabel
WHERE
{
  wd:Q462042 wdt:P625 ?loc .         # <-- Change the Q-Code to a geographic entiry
  SERVICE wikibase:around {
      ?place wdt:P625 ?location .
      bd:serviceParam wikibase:center ?loc .
      bd:serviceParam wikibase:radius "100" .    # <--  Specify a distance 
  }
  OPTIONAL {  	?place wdt:P31 ?instance  }
  #OPTIONAL {?place wdt:P18 ?pic}                # toggle comment character to see all links in radius
  ?place wdt:P18 ?pic
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
  BIND(geof:distance(?loc, ?location) as ?dist)
} ORDER BY ?dist
Try it!

Query #14: All cities in US that had a population > 30,000 in 2010

[edit]
  1. Query to list US Cities and some info about them.
PREFIX schema: <http://schema.org/>	# remember to add this
SELECT DISTINCT ?city ?cityLabel ?state ?stateLabel ?county ?countyLabel ?pop2010 ?cityfips ?countyfips ?wplink  
WHERE {
      ?city wdt:P31 wd:Q1093829	.	      # dicity - is a - US City
      ?city wdt:P131 ?county .           # district - is located in the administrative territory of - a region
      ?county wdt:P131 ?state . 
      ?city wdt:P1082 ?pop2010 .
      OPTIONAL {?city wdt:P774 ?cityfips .}
      OPTIONAL {?county wdt:P882 ?countyfips .}
      FILTER (?pop2010 > 30000) .
      OPTIONAL {
         ?wplink schema:about ?city .   # WP link - is about - ?dist
         ?wplink schema:inLanguage "en" .
         ?wplink schema:isPartOf <https://en.wikipedia.org/> .
      }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ASC(?cityLabel) ?countyLabel
Try it!

Query #15: List of Economics Journals

[edit]
SELECT ?academic_journal ?academic_journalLabel ?article ?country ?countryLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?academic_journal wdt:P31 wd:Q737498.
  ?academic_journal wdt:P921 wd:Q8134.
  ?academic_journal wdt:P495 ?country.
  ?article schema:about ?academic_journal.
  ?article schema:isPartOf <https://en.wikipedia.org/>.
}
ORDER BY ASC(?countryLabel)
LIMIT 100
Try it!

Query #16: Use WikiData Query Form to Query DBPedia

[edit]
SELECT ?x
WHERE {
  SERVICE <http://dbpedia.org/sparql> {
    ?x rdfs:label "Paris"@en .
  }
}
Try it!

Properties for the class <public university>
properties most often connecting to public university (Q875538)
TopList: query
TopListDeep: query

all entities | count | all groupings | without grouping property | below threshold (20) | Querying about WWF ecoregion (Q6617741)  View with Reasonator View with SQIDGrouping by country (P17)
Top groupings (Minimum 20 items) Top Properties (used at least 0 times per grouping)
Name Count WWF ecoregion code (P1294) image (P18) part of (P361) locator map image (P242)
United States of America (Q30) 99 96.97% (96) 🔍 88.89% (88) 🔍 14.14% (14) 🔍 81.82% (81) 🔍
Mexico (Q96) 57 98.25% (56) 🔍 82.46% (47) 🔍 1.75% (1) 🔍 78.95% (45) 🔍
Brazil (Q155) 54 98.15% (53) 🔍 100.0% (54) 🔍 11.11% (6) 🔍 98.15% (53) 🔍
People's Republic of China (Q148) 51 100.0% (51) 🔍 90.2% (46) 🔍 21.57% (11) 🔍 100.0% (51) 🔍
Russia (Q159) 45 100.0% (45) 🔍 68.89% (31) 🔍 24.44% (11) 🔍 66.67% (30) 🔍
India (Q668) 44 100.0% (44) 🔍 93.18% (41) 🔍 2.27% (1) 🔍 84.09% (37) 🔍
Australia (Q408) 44 97.73% (43) 🔍 86.36% (38) 🔍 4.55% (2) 🔍 88.64% (39) 🔍
Canada (Q16) 42 97.62% (41) 🔍 88.1% (37) 🔍 4.76% (2) 🔍 85.71% (36) 🔍
Indonesia (Q252) 38 97.37% (37) 🔍 71.05% (27) 🔍 2.63% (1) 🔍 60.53% (23) 🔍
Colombia (Q739) 28 96.43% (27) 🔍 57.14% (16) 🔍 0% (0) 🔍 46.43% (13) 🔍
France (Q142) 27 92.59% (25) 🔍 96.3% (26) 🔍 33.33% (9) 🔍 62.96% (17) 🔍
South Africa (Q258) 20 95.0% (19) 🔍 75.0% (15) 🔍 15.0% (3) 🔍 70.0% (14) 🔍
Venezuela (Q717) 20 95.0% (19) 🔍 60.0% (12) 🔍 0% (0) 🔍 55.0% (11) 🔍
Totals (all items) 897 97.44% (874) 🔍 83.28% (747) 🔍 13.27% (119) 🔍 77.03% (691) 🔍