User:Every-leaf-that-trembles/sandbox
Jump to navigation
Jump to search
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
This is the user sandbox of Every-leaf-that-trembles. A user sandbox is a subpage of the user's user page. It serves as a testing spot and page development space for the user and is not an encyclopedia article, or data item. For a sandbox of your own, create it here. Other sandboxes: Main sandbox | Tutorial sandbox 1, 2, 3, 4, 5 |
Babel user information | ||||
---|---|---|---|---|
| ||||
Users by language |
Query #1: List all items Q1, that are instances/subclasses of item Q2
[edit]- 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". }
}
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
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
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)
Query #4: List WWF Ecoregions that have are marked as such with P31
[edit]- 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)
Query #5: List National Parks in Ukraine, with Ukrainian labels, and images
[edit]- 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
Query #6: Experimenting with Qualifiers
[edit]- 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". }
}
Query #7: Experimenting with Qualifiers
[edit]- 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". }
}
Query #8: Experimenting with Qualifiers [NOT MINE; THIS IS FROM THE EXAMPLES PAGE]
[edit]- Properties grouped by their parent property
- 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". }
}
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". }
}
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
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". }
}
Query #12: The emergency #'s in each country, and who they call
[edit]- 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
Query #13: All articles with pictures within X [kilometers] of a location
[edit]- 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
Query #14: All cities in US that had a population > 30,000 in 2010
[edit]- 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
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
Query #16: Use WikiData Query Form to Query DBPedia
[edit]SELECT ?x
WHERE {
SERVICE <http://dbpedia.org/sparql> {
?x rdfs:label "Paris"@en .
}
}
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) Grouping 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) 🔍 | 80.81% (80) 🔍 |
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) 🔍 |
France (Q142) | 34 | 94.12% (32) 🔍 | 97.06% (33) 🔍 | 32.35% (11) 🔍 | 70.59% (24) 🔍 |
Colombia (Q739) | 28 | 96.43% (27) 🔍 | 57.14% (16) 🔍 | 0% (0) 🔍 | 46.43% (13) 🔍 |
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) | 896 | 97.43% (873) 🔍 | 83.71% (750) 🔍 | 13.17% (118) 🔍 | 76.9% (689) 🔍 |