User:Realworldobject/QueryExamples
Jump to navigation
Jump to search
Query Examples
[edit]Top 10 female given names (ranked by the number of language Wikipedia pages)
[edit]The following query uses these:
- Properties: instance of (P31)
# Top 10 female given names (ranked by the number of language Wikipedia pages) SELECT ?femaleName ?femaleNameLabel ?sitelinks WHERE { ?femaleName wdt:P31 wd:Q11879590 ; # female given name wikibase:sitelinks ?sitelinks . SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY DESC(?sitelinks) LIMIT 10
All works by a given author
[edit]The following query uses these:
- Items: Ernest Hemingway (Q23434)
- Properties: author (P50)
, publication date (P577)
, language of work or name (P407)
, title (P1476)
, instance of (P31)
# items authored by Ernest Hemingway (Q23434) SELECT ?work ?workLabel ?title ?languageLabel ?pubdate (GROUP_CONCAT(?typeLabel;SEPARATOR=", ") AS ?types) WHERE { ?work wdt:P50 wd:Q23434. OPTIONAL {?work wdt:P577 ?pubdate} OPTIONAL {?work wdt:P407 ?language} OPTIONAL {?work wdt:P1476 ?title} OPTIONAL { ?work wdt:P31 ?type . ?type rdfs:label ?typeLabel . FILTER(LANG(?typeLabel)="en") } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } GROUP BY ?work ?workLabel ?title ?pubdate ?languageLabel ORDER BY ?workLabel
Concepts related to a broader concept, according to an external source's POV
[edit]The following query uses these:
- Properties: broader concept (P4900)
SELECT DISTINCT ?item ?itemLabel ?p ?propLabel ?broaderItem ?broaderItemLabel ?numBroaderQuals WHERE { { SELECT ?item (COUNT(DISTINCT ?stmt) AS ?numBroaderQuals) WHERE { ?item ?p ?stmt . ?stmt pq:P4900 ?broaderItem . ?prop wikibase:claim ?p . } GROUP BY ?item ORDER BY DESC(?numBroaderQuals) } ?item ?p ?stmt . ?stmt pq:P4900 ?broaderItem . ?prop wikibase:claim ?p . SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY DESC(?numBroaderQuals) ?item
Harry Potter books that were made into films
[edit]The following query uses these:
- Items: film (Q11424)
, book (Q571)
, Harry Potter (Q8337)
- Properties: instance of (P31)
, subclass of (P279)
, based on (P144)
, publication date (P577)
, part of the series (P179)
SELECT DISTINCT ?novel ?novelLabel (YEAR(?bookPubDate) AS ?novelYear) ?film ?filmLabel (YEAR(?filmPubDate) AS ?filmYear) WHERE { ?film wdt:P31/wdt:P279* wd:Q11424; wdt:P144 ?novel; wdt:P577 ?filmPubDate . ?novel wdt:P31/wdt:P279* wd:Q571; wdt:P577 ?bookPubDate ; wdt:P179 wd:Q8337 . SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY ?bookYear ?filmYear
Constraint violation counts
[edit]The following query uses these:
- Properties: property constraint (P2302)
# Constraints with violations SELECT ?propLabel ?constraintLabel ?numViolations WHERE { { SELECT DISTINCT ?prop ?constraint (COUNT(?stmt) AS ?numViolations) WHERE { ?stmt wikibase:hasViolationForConstraint ?constraintStmt . ?prop p:P2302 ?constraintStmt . ?constraintStmt ps:P2302 ?constraint . } GROUP BY ?prop ?constraint } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY DESC(?numViolations)
Items with multiple VIAF identifiers
[edit]The following query uses these:
- Properties: VIAF ID (P214)
# VIAF single value constraint violation SELECT ?item ?itemLabel (GROUP_CONCAT(?viafID;SEPARATOR=" | ") AS ?viafIDs) WHERE { ?item p:P214 [ wikibase:hasViolationForConstraint wds:P214-F98CC03E-A180-4F15-B3C9-5C6097F40A57; psn:P214 ?viafID ] . SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } GROUP BY ?item ?itemLabel ORDER BY DESC(COUNT(DISTINCT ?viafID))
Distinct Values constraint violations
[edit]The following query uses these:
- Properties: VIAF ID (P214)
#Violations of the distinct value constraint for VIAF ids SELECT ?viafID (COUNT(DISTINCT ?item) AS ?itemCount) (GROUP_CONCAT(DISTINCT ?item; SEPARATOR=" | ") AS ?wdIDs) (GROUP_CONCAT(DISTINCT ?itemLabel;SEPARATOR=" | ") AS ?labels) WHERE { SELECT ?viafID ?item ?itemLabel ?itemDescription ?sitelinks WHERE { [] p:P214 [ wikibase:hasViolationForConstraint wds:P214-B36B72ED-7C33-4CF1-A4E9-55366E0B6501 ; ps:P214 ?viafID ]. OPTIONAL {?item wdt:P214 ?viafID} OPTIONAL {?item p:P214 [ps:P214 ?viafID]} SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de". ?item rdfs:label ?itemLabel} } } GROUP BY ?viafID HAVING (?itemCount > 1) ORDER BY DESC(?itemCount)
Allowed qualifiers on External ID claims
[edit]The following query uses these:
- Properties: property constraint (P2302)
, property (P2306)
SELECT DISTINCT ?allowedQualifier ?allowedQualifierLabel (COUNT(?prop) AS ?numOccurs) WHERE { ?prop wikibase:propertyType wikibase:ExternalId ; p:P2302 [ ps:P2302 wd:Q21510851; pq:P2306 ?allowedQualifier ] SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } GROUP BY ?allowedQualifier ?allowedQualifierLabel ORDER BY DESC(?numOccurs)
External IDs that allow a Mapping Relation Type qualifier
[edit]The following query uses these:
- Properties: property constraint (P2302)
, property (P2306)
SELECT DISTINCT ?prop ?propLabel WHERE { ?prop wikibase:propertyType wikibase:ExternalId ; p:P2302 [ ps:P2302 wd:Q21510851; pq:P2306 wd:P4390 ] SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }
Mapping Relationship qualifiers that are used on External IDs
[edit]The following query uses these:
- Properties: property constraint (P2302)
, property (P2306)
, mapping relation type (P4390)
SELECT DISTINCT ?propLabel ?mappingRelationType ?mappingRelationTypeLabel (COUNT(?p) AS ?numOccurs) WHERE { ?prop wikibase:propertyType wikibase:ExternalId ; p:P2302 [ ps:P2302 wd:Q21510851; pq:P2306 wd:P4390 ] ; wikibase:claim ?p . ?item ?p [ pq:P4390 ?mappingRelationType ] SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } GROUP BY ?propLabel ?mappingRelationType ?mappingRelationTypeLabel ORDER BY DESC(?numOccurs)
Bibliograph.net mappings
[edit]The following query uses these:
- Properties: equivalent class (P1709)
, equivalent property (P1628)
PREFIX bgn: <http://bibliograph.net/> SELECT ?bgn ?class ?classLabel ?classDescription ?property ?propertyLabel ?propertyDescription WHERE { { ?class wdt:P1709 ?bgn . FILTER(STRSTARTS(STR(?bgn), STR(bgn:))) } UNION { ?property wdt:P1628 ?bgn . FILTER(STRSTARTS(STR(?bgn), STR(bgn:))) } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY ?bgn
Bibliograph.net reproduction query
[edit]The following query uses these:
- Properties: equivalent class (P1709)
, equivalent property (P1628)
PREFIX bgn: <http://bibliograph.net/> PREFIX schema: <http://schema.org/> CONSTRUCT { ?class a rdfs:Class ; rdfs:label ?label ; owl:equivalentClass ?item . ?property a rdf:Property ; rdfs:label ?label ; owl:equivalentProperty ?item . bgn:AudioBook a schema:BookFormatType ; rdfs:label "bgn:AudioBook"@en . bgn:CartographicMap a schema:MapCategoryType ; rdfs:label "bgn:CartographicMap"@en . bgn:LargePrintBook a schema:BookFormatType ; rdfs:label "bgn:LargePrintBook"@en . bgn:PrintBook a schema:BookFormatType ; rdfs:label "bgn:PrintBook"@en . } WHERE { { ?item wdt:P1709 ?class ; FILTER(STRSTARTS(STR(?class), STR(bgn:))) BIND(CONCAT('bgn:', STRAFTER(STR(?class), STR(bgn:))) AS ?label) } UNION { ?item wdt:P1628 ?property . FILTER(STRSTARTS(STR(?property), STR(bgn:))) BIND(CONCAT('bgn:', STRAFTER(STR(?property), STR(bgn:))) AS ?label) } }
Identifier overlap illustration
[edit]The following query uses these:
- Properties: Art & Architecture Thesaurus ID (P1014)
, Library of Congress authority ID (P244)
, FAST ID (P2163)
, GeoNames ID (P1566)
, NDL Authority ID (P349)
, GND ID (P227)
SELECT ?item ?itemLabel ?itemDescription ?aat ?lcsh ?fast ?gnd ?ndl ?geonames WHERE { ?item wdtn:P1014 ?aat . OPTIONAL {?item wdtn:P244 ?lcsh} OPTIONAL {?item wdtn:P2163 ?fast} OPTIONAL {?item wdtn:P1566 ?geonames} OPTIONAL {?item wdtn:P349 ?ndl} OPTIONAL {?item wdtn:P227 ?gnd} SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } LIMIT 100