Open main menu

Every-leaf-that-trembles

Joined 12 October 2014

Just getting started. Every-leaf-that-trembles (talk) 00:27, 28 January 2016 (UTC)

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

Contents

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

  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 picturesEdit

#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 WikiDataEdit

#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 FederationEdit

#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 P31Edit

# Query to list WWF Ecoregions
SELECT DISTINCT ?x ?y ?pic ?wplink 
WHERE {
  ?x wdt:P31 wd:Q6617741 .     
  OPTIONAL { ?x wdt:P1294 ?y }.
  OPTIONAL {?x wdt:P18 ?pic } .
  # ?x wdt:P18 ?pic .
  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(?y)

Try it!

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

  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 QualifiersEdit

  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 QualifiersEdit

  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 measureEdit

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 valuesEdit

# 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 ArtEdit

#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!