User:Bamyers99
Jump to navigation
Jump to search
Babel user information |
---|
Users by language |
Reports
[edit]Report | Updated |
---|---|
Class browser | 1st |
Deleted properties | 1st |
EntitySchema directory | 1st, 15th |
External identifier completeness | 1st |
Gadget usage statistics | 1st |
List of properties | 1st, 15th |
Navel gazer | 1st |
Links
[edit]- SPARQL
- Wikidata query service
- A Guide To WDQS
- mw:Wikidata query service/User Manual
- mw:Wikibase/Indexing/RDF Dump Format
- SPARQL 1.1 Query Language
- Wikidata:SPARQL query service/query optimization
- SERVICE wikibase:mwapi
SPARQL examples
[edit]![](http://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Rdf_mapping-vector.svg/708px-Rdf_mapping-vector.svg.png)
Turn off query optimizer
[edit]hint:Query hint:optimizer "None" .
Searches super-classes (non-truthy instance of), checks for non-existence, must have enwiki link
[edit]Bridges in USA w/o crosses.
SELECT DISTINCT ?s ?sLabel WHERE {
?s wdt:P17 wd:Q30 .
?s p:P31 ?stmt .
?stmt ps:P31/wdt:P279* wd:Q12280 .
OPTIONAL {
?s p:P177 ?dummy # includes novalue statements
}
FILTER ( !bound(?dummy) ) .
FILTER EXISTS {
?article schema:about ?s .
?article schema:inLanguage "en" .
?article schema:isPartOf <https://en.wikipedia.org/>
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,de,fr,es,it,pl,nl,pt,sv,no,ar,cs,ca,ml,ms,az,ru" }
}
ORDER BY ?sLabel
Searches super-administrative entities
[edit]Covered bridges in Pennsylvania.
SELECT DISTINCT ?s ?sLabel WHERE {
?s wdt:P31 wd:Q1825472 .
?s wdt:P131/wdt:P131* wd:Q1400 .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?sLabel
A qualifier's 'value counts' for a specific property
[edit]population (P1082) qualifier determination method (P459).
SELECT ?determinemethod ?determinemethodLabel ?count WHERE {
{
SELECT ?determinemethod (COUNT(?determinemethod) AS ?count) WHERE {
?s p:P1082 ?popstatement .
?popstatement pq:P459 ?determinemethod .
}
GROUP BY ?determinemethod
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY DESC(?count)
A qualifier's usage counts
[edit]Qualifier start time (P580).
SELECT ?wdP ?wdPLabel ?count WHERE {
{
SELECT ?prop (COUNT(?prop) AS ?count) WHERE {
?s ?prop ?propstatement .
?propstatement pq:P580 ?proptime .
}
GROUP BY ?prop
}
?wdP wikibase:claim ?prop .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY DESC(?count)
A property's qualifier property counts, includes a SPARQL query of instances
[edit]Property formatter URL (P1630).
SELECT ?qual ?qualLabel ?count (IRI(CONCAT("https://query.wikidata.org/#%23%20qualifier%20-%20", ?qualLabel, "%0ASELECT%20%3Fitem%20%3FitemLabel%20%3FqualLabel%0AWHERE%0A{%0A%09%3Fitem%20p%3AP1630%20%3Fstatement%20.%0A%20%20%20%20%3Fstatement%20pq%3A", SUBSTR(STR(?qual),32), "%20%3Fqual%0A%09SERVICE%20wikibase%3Alabel%20{%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20%20}%20%20%20%20%0A}%0AORDER BY %3FitemLabel")) as ?instances)
WHERE {
{
SELECT ?qual (COUNT(DISTINCT ?item) AS ?count) WHERE {
hint:Query hint:optimizer "None" .
?item p:P1630 ?statement .
?statement ?pq_qual ?pq_obj .
?qual wikibase:qualifier ?pq_qual .
} GROUP BY ?qual
} .
OPTIONAL {
?qual rdfs:label ?qualLabel filter (lang(?qualLabel) = "en") .
}
}
ORDER BY DESC(?count) ASC(?qualLabel)
Missing a qualifier
[edit]award received (P166)Nobel Prize in Physiology or Medicine (Q80061) missing point in time (P585).
SELECT DISTINCT ?item ?itemLabel
WHERE {
?item p:P166 ?awardStat .
?awardStat ps:P166 wd:Q80061 .
OPTIONAL {
?awardStat pq:P585 ?when .
}
FILTER ( !bound(?when) ) .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?itemLabel
Unreferenced statement
[edit]award received (P166)Nobel Prize in Physiology or Medicine (Q80061) missing reference.
SELECT DISTINCT ?item ?itemLabel
WHERE {
?item p:P166 ?stmt .
?stmt ps:P166 wd:Q80061 .
OPTIONAL {
?stmt prov:wasDerivedFrom ?derivedFrom .
}
FILTER ( !bound(?derivedFrom) ) .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY ?itemLabel
Reference URL starts with
[edit]SELECT DISTINCT ?item ?itemLabel
WHERE {
?item p:P1411 ?stmt .
?stmt prov:wasDerivedFrom ?derivedFrom .
?derivedFrom pr:P854 ?refurl .
FILTER(STRSTARTS(xsd:string(?refurl), "http://www.nobelprize.org/"))
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?itemLabel
Multiple optionals, or filter, must have English label
[edit]SELECT DISTINCT ?s ?sLabel ?fatherLabel ?motherLabel WHERE {
?s wdt:P31/wdt:P279* wd:Q726 .
OPTIONAL {
?s wdt:P22 ?father
}
OPTIONAL {
?s wdt:P25 ?mother
}
OPTIONAL {
?s wdt:P3165 ?dummy
}
FILTER ( !bound(?dummy) ) .
FILTER (bound(?father) || bound(?mother) ) .
FILTER(EXISTS {
?s rdfs:label ?lang_label.
FILTER(LANG(?lang_label) = "en")
})
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?sLabel
Items with multiple values for a given property
[edit]SELECT ?school ?schoolLabel (COUNT(?isni) AS ?isniC) {
{
SELECT DISTINCT ?school ?isni {
?school wdt:P31/wdt:P279* wd:Q3914 .
?school wdt:P213 ?isni .
?school wdt:P17 wd:Q30 .
}
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?school ?schoolLabel
HAVING (COUNT(?isni) > 1)
ORDER BY ?schoolLabel
Items with a specific value attribute
[edit]Impact craters with coordinate globe Earth
SELECT DISTINCT ?s ?sLabel WHERE {
?s p:P31 ?stmt .
?stmt ps:P31/wdt:P279* wd:Q55818 .
?s p:P625 ?coordstmt .
?coordstmt psv:P625 ?coordvalue .
?coordvalue wikibase:geoGlobe <http://www.wikidata.org/entity/Q2> .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,de,fr,es,it,pl,nl,pt,sv,no,ar,cs,ca,ml,ms,az,ru" }
}
ORDER BY ?sLabel
Label service in chunks
[edit]SELECT ?item ?itemLabel ?itemDescription ?mbvalue ?dcvalue WHERE {
{
SELECT ?item ?mbvalue ?dcvalue WHERE
{
?item wdt:P434 ?mbvalue .
?item wdt:P1953 ?dcvalue .
}
ORDER BY ?mbvalue ?dcvalue
OFFSET 150000
LIMIT 50000
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}