User:Ash Crow/SPARQL
Names
editRoman emperors with a modern-style first name or family name
editThe following query uses these:
- Items: human (Q5) , Roman emperor (Q842606)
- Properties: instance of (P31) , position held (P39) , family name (P734) , given name (P735)
# Roman emperors with a modern-style first name or family name SELECT ?item ?itemLabel ?nameLabel WHERE { ?item wdt:P31 wd:Q5 . ?item wdt:P39 wd:Q842606 . ?item wdt:P734|wdt:P735 ?name . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } }
Dates
editDates avec la déclaration "Calendrier grégorien avant 1584" et une précision inférieure ou égale à l'année
editThe following query uses these:
- Items: proleptic Gregorian calendar (Q1985727) , statement with Gregorian date earlier than 1584 (Q26961029)
- Properties: instance of (P31)
SELECT DISTINCT ?statement ?date ?precision_label { ?statement ?date_prop ?date_node . ?date_node wikibase:timePrecision ?precision ; wikibase:timeValue ?date . ?date_node wikibase:timeCalendarModel wd:Q1985727 . FILTER (YEAR(?date) < 1584) . FILTER (?precision <= 9 ) . ?statement pq:P31 wd:Q26961029 . VALUES (?precision ?precision_label) { (0 "milliard d’années") (1 "centaine de million d’années") (2 "dizaine de millions d’années") (3 "million d’années") (4 "centaine de millénaires") (5 "dizaine de millénaires") (6 "millénaire") (7 "siècle") (8 "décennie") (9 "année") (10 "mois") (11 "jour") (12 "heure") (13 "minute") (14 "seconde") } }
Dates with precision Year or higher before 10000 BCE
editThe following query uses these:
SELECT DISTINCT ?item ?statement ?date ?precision_label {
?statement ?date_prop ?date_node .
?date_node wikibase:timePrecision ?precision ;
wikibase:timeValue ?date .
FILTER (YEAR(?date) < -10000) .
FILTER (?precision >= 9 ) .
VALUES (?precision ?precision_label) {
(0 "milliard d’années")
(1 "centaine de million d’années")
(2 "dizaine de millions d’années")
(3 "million d’années")
(4 "centaine de millénaires")
(5 "dizaine de millénaires")
(6 "millénaire")
(7 "siècle")
(8 "décennie")
(9 "année")
(10 "mois")
(11 "jour")
(12 "heure")
(13 "minute")
(14 "seconde")
}
# Exclude Property statements
?item ?p ?statement .
?item wikibase:statements ?s .
FILTER(STRSTARTS(STR(?item), "http://www.wikidata.org/entity/Q")) .
} ORDER BY ?precision YEAR(?date)
Trying to locate all battles fought in the Middle ages in Europe
editBattles of the Middle Ages in Europe
editThe following query uses these:
- Items: battle (Q178561) , siege (Q188055) , Europe (Q46)
- Properties: instance of (P31) , subclass of (P279) , part of (P361) , image (P18) , country (P17) , location (P276) , located in/on physical feature (P706) , located in the administrative territorial entity (P131) , continent (P30) , coordinate location (P625) , point in time (P585) , start time (P580) , end time (P582)
Features: map (Q24515275)
#defaultView:Map
SELECT DISTINCT
?item
(SAMPLE(?item_label) AS ?battle)
(SAMPLE(?place_label) AS ?place_label)
(SAMPLE(?partOf_label) AS ?partOf_label)
(SAMPLE(?year) AS ?year)
(SAMPLE(?image) AS ?image)
(SAMPLE(?century) AS ?layer)
(SAMPLE(?coords) AS ?coords)
WHERE {
{
?item wdt:P31/wdt:P279* wd:Q178561 .
} UNION {
?item wdt:P31/wdt:P279* wd:Q188055 .
}
OPTIONAL {
?item rdfs:label ?item_label .
FILTER(LANG(?item_label) IN ('fr', 'en')) .
}
OPTIONAL {
?item wdt:P361 ?partOf .
?partOf rdfs:label ?partOf_label .
FILTER(LANG(?partOf_label) IN ('fr', 'en')) .
}
OPTIONAL { ?item wdt:P18 ?image . }
# Place
?item (wdt:P17|wdt:P276|wdt:P706|wdt:P131)*/wdt:P30 wd:Q46 .
?item wdt:P276 ?place .
OPTIONAL {
?place rdfs:label ?place_label .
FILTER(LANG(?place_label) IN ('fr', 'en')) .
}
# Coords
OPTIONAL { ?item wdt:P625 ?coordsItem . }
OPTIONAL { ?place wdt:P625 ?coordsPlace . }
BIND(COALESCE(?coordsItem, ?coordsPlace) AS ?coords)
# Date
?item (wdt:P585|wdt:P580|wdt:P582) ?date .
BIND(YEAR(?date) AS ?year) .
FILTER(?year >= 476) .
FILTER(?year <= 1492) .
BIND(FLOOR((?year - 1)/100)+1 AS ?century) .
} GROUP BY ?item ORDER BY ?year ?battle
Battles between 476 and 1492 with a date but no place
editThe following query uses these:
- Properties: instance of (P31) , subclass of (P279) , point in time (P585) , start time (P580) , end time (P582) , location (P276) , coordinate location (P625)
# Battles between 476 and 1492 with a date but no place SELECT DISTINCT ?item ?itemLabel ?placeLabel ?date ?coords WHERE { ?item wdt:P31/wdt:P279* wd:Q178561 . # A battle or a subclass of it MINUS { ?item wdt:P31 wd:Q26913948 . } # but not a legendary one # OPTIONAL { ?item (wdt:P585|wdt:P580|wdt:P582) ?date . } OPTIONAL { ?item wdt:P585 ?basicDate . } OPTIONAL { ?item wdt:P580 ?startDate . } OPTIONAL { ?item wdt:P582 ?endDate . } BIND(COALESCE(?basicDate, ?startDate, ?endDate) AS ?date) FILTER(BOUND(?date)) FILTER (YEAR(?date) >= 476) . FILTER (YEAR(?date) <= 1492) . FILTER NOT EXISTS { ?item wdt:P276 ?place . } OPTIONAL { ?item wdt:P625 ?coords . } # OPTIONAL { ?place wdt:P625 ?coordsPlace . } # BIND(COALESCE(?coordsItem, ?coordsPlace) AS ?coords) SERVICE wikibase:label { bd:serviceParam wikibase:language "fr,en" } } ORDER BY ?date
Battles in Europe with a place but no date
editThe following query uses these:
- Properties: instance of (P31) , subclass of (P279) , country (P17) , location (P276) , located in/on physical feature (P706) , located in the administrative territorial entity (P131) , continent (P30) , coordinate location (P625) , point in time (P585) , start time (P580) , end time (P582)
# Battles in Europe with a place but no date SELECT DISTINCT ?item ?itemLabel (SAMPLE(?place_label) AS ?place_label) (SAMPLE(?coords) AS ?coords) WHERE { ?item wdt:P31/wdt:P279* wd:Q178561 . MINUS { ?item wdt:P31 wd:Q26913948 . } # Place ?item (wdt:P17|wdt:P276|wdt:P706|wdt:P131)*/wdt:P30 wd:Q46 . ?item wdt:P276 ?place . OPTIONAL { ?place rdfs:label ?place_label . FILTER(LANG(?place_label) IN ("en", "fr")) . } # Coords OPTIONAL { ?item wdt:P625 ?coordsItem . } OPTIONAL { ?place wdt:P625 ?coordsPlace . } BIND(COALESCE(?coordsItem, ?coordsPlace) AS ?coords) FILTER NOT EXISTS { ?item (wdt:P585|wdt:P580|wdt:P582) ?date . } SERVICE wikibase:label { bd:serviceParam wikibase:language "fr,en" } } GROUP BY ?item ?itemLabel ORDER BY ?coords
Battles within a certain radius of a certain point without place and/or date
editThe following query uses these:
- Items: battle (Q178561) , geographical midpoint of Europe (Q1133467) , Westerngrund (Q509320) , Athens (Q1524) , Tbilisi (Q994) , Ankara (Q3640)
- Properties: instance of (P31) , coordinate location (P625) , location (P276) , point in time (P585) , start time (P580) , end time (P582)
# Battles within a certain radius of a certain point without place and/or date SELECT DISTINCT ?item (SAMPLE(?itemLabel) AS ?itemLabel) (SAMPLE(?place) AS ?place) (SAMPLE(?placeLabel) AS ?placeLabel) (SAMPLE(?date) AS ?date) (SAMPLE(?coords) AS ?coords) WHERE { ?item wdt:P31 wd:Q178561 . # wd:Q1133467 wdt:P625 ?MidPointCoords . # European Midpoint, including the european part of Russia. # wd:Q509320 wdt:P625 ?MidPointCoords . # EU Midpoint wd:Q1524 wdt:P625 ?MidPointCoords . # Athens # wd:Q994 wdt:P625 ?MidPointCoords . # Tbilissi # wd:Q3640 wdt:P625 ?MidPointCoords . # Ankara # Done : Paris, Isle of Man, Oslo, Finland, Madrid, Rome, EU Midpoint, Varsovie, Berlin, Yalta SERVICE wikibase:around { ?item wdt:P625 ?coords . bd:serviceParam wikibase:center ?MidPointCoords . bd:serviceParam wikibase:radius "600" . } OPTIONAL { ?item wdt:P276 ?place . OPTIONAL { ?place rdfs:label ?placeLabel . FILTER(LANG(?placeLabel) IN ("fr","en")) . } } OPTIONAL { ?item (wdt:P585|wdt:P580|wdt:P582) ?date . } FILTER(!BOUND(?place) || !BOUND(?date) ) . OPTIONAL { ?item rdfs:label ?itemLabelFr . FILTER(LANG(?itemLabelFr) = "fr") . } OPTIONAL { ?item rdfs:label ?itemLabelEn . FILTER(LANG(?itemLabelEn) = "en") . } OPTIONAL { ?item rdfs:label ?itemLabelEs . FILTER(LANG(?itemLabelEs) = "es") . } OPTIONAL { ?item rdfs:label ?itemLabelCa . FILTER(LANG(?itemLabelCa) = "ca") . } OPTIONAL { ?item rdfs:label ?itemLabelDe . FILTER(LANG(?itemLabelDe) = "de") . } OPTIONAL { ?item rdfs:label ?itemLabelIt . FILTER(LANG(?itemLabelIt) = "it") . } BIND(COALESCE(?itemLabelFr, ?itemLabelEn, ?itemLabelEs, ?itemLabelCa, ?itemLabelDe, ?itemLabelIt) AS ?itemLabel) . } GROUP BY ?item ORDER BY ?coords
Battles within a sitelink to the French Wikipedia without place and/or date
editThe following query uses these:
- Items: battle (Q178561)
- Properties: instance of (P31) , subclass of (P279) , location (P276) , point in time (P585) , start time (P580) , end time (P582) , coordinate location (P625)
# Battles within a sitelink to the French Wikipedia without place and/or date SELECT ?item ?itemLabel (SAMPLE(?place) AS ?place) (SAMPLE(?placeLabel) AS ?placeLabel) (SAMPLE(?date) AS ?date) (SAMPLE(?coord) AS ?coord) (SAMPLE(?article) AS ?article) WHERE { ?item wdt:P31/wdt:P279* wd:Q178561 . ?article schema:about ?item ; schema:isPartOf <https://fr.wikipedia.org/> . OPTIONAL { ?item wdt:P276 ?place . OPTIONAL { ?place rdfs:label ?placeLabel . FILTER(LANG(?placeLabel) IN ("fr","en")) . } } OPTIONAL { ?item (wdt:P585|wdt:P580|wdt:P582) ?date . } OPTIONAL { ?item wdt:P625 ?coord . } FILTER(!BOUND(?place) || !BOUND(?date) ) . SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" } } GROUP BY ?item ?itemLabel
All battles with time and date
editThe following query uses these:
- Items: battle (Q178561) , siege (Q188055)
- Properties: instance of (P31) , subclass of (P279) , part of (P361) , image (P18) , location (P276) , coordinate location (P625) , point in time (P585) , start time (P580) , end time (P582)
Features: map (Q24515275)
#defaultView:Map
SELECT DISTINCT
?item
(SAMPLE(?item_label) AS ?battle)
(SAMPLE(?place_label) AS ?place_label)
(SAMPLE(?partOf_label) AS ?partOf_label)
(SAMPLE(?year) AS ?year)
(SAMPLE(?image) AS ?image)
(SAMPLE(?layer) AS ?layer)
(SAMPLE(?coords) AS ?coords)
(SAMPLE(?rgb) AS ?rgb)
WHERE {
{
?item wdt:P31/wdt:P279* wd:Q178561 .
} UNION {
?item wdt:P31/wdt:P279* wd:Q188055 .
}
OPTIONAL {
?item rdfs:label ?item_label .
FILTER(LANG(?item_label) IN ('fr', 'en')) .
}
OPTIONAL {
?item wdt:P361 ?partOf .
?partOf rdfs:label ?partOf_label .
FILTER(LANG(?partOf_label) IN ('fr', 'en')) .
}
OPTIONAL { ?item wdt:P18 ?image . }
# Place
?item wdt:P276 ?place .
OPTIONAL {
?place rdfs:label ?place_label .
FILTER(LANG(?place_label) IN ('fr', 'en')) .
}
# Coords
OPTIONAL { ?item wdt:P625 ?coordsItem . }
OPTIONAL { ?place wdt:P625 ?coordsPlace . }
BIND(COALESCE(?coordsItem, ?coordsPlace) AS ?coords)
# Date
?item (wdt:P585|wdt:P580|wdt:P582) ?date .
BIND(YEAR(?date) AS ?year) .
# Layer
VALUES (?layer ?min ?max ?rgb) {
("Prehistory" -100000 -3500 "0078BF")
("Ancien History -3500 → 500" -3500 500 "DDD700")
("Middle Ages 500 → 1500" -500 1500 "5BD500")
("Early Modern Period 1500 → 1750" 1500 1750 "00CE23")
("Mid Modern Period 1750 → 1914" 1750 1914 "00C699")
("Contemporary Period 1914 → present" 1914 3500 "0078BF")
}
FILTER (?min <= ?year && ?year < ?max)
} GROUP BY ?item ORDER BY ?year ?battle
Personnalités passant dans le domaine public en 2017
editThe following query uses these:
- Items: human (Q5) , creator (Q2500638)
- Properties: instance of (P31) , occupation (P106) , subclass of (P279) , date of death (P570)
# Auteurs morts en 1946 SELECT ?person (SAMPLE(?person_label) AS ?person_label) #SAMPLE prend une valeur au hasard s'il y en a plusieurs noms ou plusieurs dates de décès (GROUP_CONCAT(DISTINCT ?occupation_label ; separator = ", ") AS ?occupations) # GROUP_CONCAT va concaténer toutes les professions (SAMPLE(?dateofDeath) AS ?dateofDeath) (SAMPLE(?sitelinks) AS ?sitelinks) WHERE { ?person wdt:P31 wd:Q5 . # On cherche un être humain # On affiche le libellé de la personne si on l'a en français ou en anglais # En option comme ça la personne ressort quand même dans les résultats OPTIONAL { ?person rdfs:label ?person_label . FILTER(LANG(?person_label) IN ("fr", "en")) . } ?person wdt:P106 ?occupation . # Cette personne a une occupation... ?occupation wdt:P31*/wdt:P279* wd:Q2500638 . # ...qui est est une sous-classe de créateur # On récupère le libellé de la profession en français et en anglais OPTIONAL { ?occupation rdfs:label ?occupation_label_fr . FILTER(LANG(?occupation_label_fr) = "fr") . } OPTIONAL { ?occupation rdfs:label ?occupation_label_en . FILTER(LANG(?occupation_label_fr) = "en") . } BIND("Profession sans label" AS ?unidentifed_occupation) . # On prend le libellé de la profession en français en priorité, en anglais sinon. BIND(COALESCE(?occupation_label_fr, ?occupation_label_en, ?unidentifed_occupation) AS ?occupation_label) . ?person wdt:P570 ?dateofDeath . # Cet être humain a une date de mort... FILTER(YEAR(?dateofDeath) = 1946) . # dont l'année est 1946. # Nombre de liens ?person wikibase:sitelinks ?sitelinks . # Le service ci-dessous permet d'afficher les libellés des éléments en français si possible, # sinon en anglais. # SERVICE wikibase:label { bd:serviceParam wikibase:language "fr,en" } } GROUP BY ?person ORDER BY DESC(?sitelinks) #on regroupe par personne et on trie par date de décès
États-Unis
editCommunautés non-incorporées par comté et État
editThe following query uses these:
- Items: unincorporated community in the United States (Q17343829) , county of the United States (Q47168) , U.S. state (Q35657)
- Properties: instance of (P31) , located in the administrative territorial entity (P131) , subclass of (P279)
SELECT ?item ?itemLabel ?itemDescription ?county ?countyLabel ?state ?stateLabel WHERE { ?item wdt:P31 wd:Q17343829 . ?item wdt:P131* ?county . ?county wdt:P31/wdt:P279* wd:Q47168 . ?item wdt:P131* ?state . ?state wdt:P31 wd:Q35657 . SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" } }
Descriptions les plus courantes
editThe following query uses these:
- Items: unincorporated community in the United States (Q17343829) , county of the United States (Q47168) , U.S. state (Q35657)
- Properties: instance of (P31) , located in the administrative territorial entity (P131) , subclass of (P279)
SELECT ?itemDescription (COUNT(?item) AS ?count) WHERE { ?item wdt:P31 wd:Q17343829 . ?item wdt:P131* ?county . ?county wdt:P31/wdt:P279* wd:Q47168 . ?item wdt:P131* ?state . ?state wdt:P31 wd:Q35657 . SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" } } GROUP BY ?itemDescription ORDER BY DESC(?count)