User:Moebeus/SPARQL queries
Jump to navigation
Jump to search
Number of albums by language in descending order
Most frequently used titles (P1476) found on audio tracks (Q7302866)
Albums without a performer
Orphaned or incorrectly linked discographies, using FILTER
Orphaned or incorrectly linked discographies, using MINUS
number of instances of genres in descending order
musical works/compositions with a Wikisource link
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Try it!
Shout-out to sparql wizards like CamelCaseNick, Tagishmon, Mahir256, Lucas Werkmeister, and several others that helped put these queries together. Them's the real MVPs!
Album reports
[edit]#title:Number of albums by language in descending order
#credit:CamelCaseNick on Telegram
SELECT (count(?album) as ?albums) ?P407Label ?P407 WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?album wdt:P31 wd:Q482994.
OPTIONAL { ?album wdt:P407 ?P407. }
}
GROUP BY ?P407 ?P407Label
ORDER BY DESC(?albums) ASC(?P407)
Track reports
[edit]#title:Most frequently used titles (P1476) found on audio tracks (Q7302866)
#credit: Mahir256 on Telegram
select ?label (LANG(?label) as ?lang) (count(?i) as ?is) {
?i wdt:P31/wdt:P279* wd:Q7302866; wdt:P1476 ?label .
}
group by ?label ?lang
having(?is > 5)
order by desc(?is) ?lang
Find erroneous MusicBrainz IDs
[edit]Wikidata:Database reports/uuid - Wikidata
Clean-Up queries
[edit]The following are queries designed to return datasets of items that most likely could be improved. NB! Any of these might return false positives, sometimes there are legitimate reasons for why an item is modelled in an unconventional way.
Albums without a performer
[edit]#title:Albums without a performer
SELECT ?q WHERE {
?q wdt:P31 wd:Q482994.
MINUS { ?q wdt:P31 ?otherClass. FILTER(?otherClass != wd:Q482994) }
MINUS { ?q wdt:P175 []. }
}
Orphaned or incorrectly linked discographies
[edit]#title:Orphaned or incorrectly linked discographies, using FILTER
#credit: Daniel Eriksson on Telegram
SELECT ?discog WHERE {
?discog wdt:P31 wd:Q273057.
OPTIONAL{ ?artist wdt:P358 ?discog }
FILTER( !BOUND(?artist))
}
#title:Orphaned or incorrectly linked discographies, using MINUS
#credit: Lucas Werkmeister on Telegram
SELECT ?discog ?discogLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?discog wdt:P31 wd:Q273057.
MINUS { ?artist wdt:P358 ?discog. }
}
Instances of genre
[edit]Normally there should be no instances (P31) of genres.
#title:number of instances of genres in descending order
#credit:Solidest
SELECT ?genre ?genreLabel (COUNT(*) AS ?count) WHERE {
wd:Q188451 ^wdt:P279*/^wdt:P31 ?genre.
?instance wdt:P31 ?genre
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?genre ?genreLabel
ORDER BY DESC(?count)
Composition items with Wikisource links
[edit]Ideally Wikisource editions of songs should be "their own thing", not composition items.
#title:musical works/compositions with a Wikisource link
#credit: Mahir256
select ?i ?name ?lang {
?i wdt:P31 wd:Q105543609 .
?sitelink schema:about ?i ;
schema:name ?name ;
schema:inLanguage ?lang ;
schema:isPartOf/wikibase:wikiGroup "wikisource" .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Older queries that might not work after re-modelling
[edit]#soundtrack albums without a performer
SELECT ?q WHERE {
?q wdt:P31 wd:Q4176708.
MINUS { ?q wdt:P31 ?otherClass. FILTER(?otherClass != wd:Q4176708) }
MINUS { ?q wdt:P175 []. }
}
#compilation albums without a performer
SELECT ?q WHERE {
?q wdt:P31 wd:Q222910.
MINUS { ?q wdt:P31 ?otherClass. FILTER(?otherClass != wd:Q222910) }
MINUS { ?q wdt:P175 []. }
}
#music singles without a performer
SELECT ?q WHERE {
?q wdt:P31 wd:Q134556.
MINUS { ?q wdt:P31 ?otherClass. FILTER(?otherClass != wd:Q134556) }
MINUS { ?q wdt:P175 []. }
}
#extended plays (EPs) without a performer
SELECT ?q WHERE {
?q wdt:P31 wd:Q169930.
MINUS { ?q wdt:P31 ?otherClass. FILTER(?otherClass != wd:Q169930) }
MINUS { ?q wdt:P175 []. }
}
#conflation of song and single
SELECT ?single ?singleLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?single wdt:P31 wd:Q134556.
?single wdt:P31 wd:Q7366.
}
via CamelCaseNick on Telegram:
#compund name not marked as such
select ?name ?spelling where {
?name wdt:P31/wdt:P279* wd:Q202444;
wdt:P1705 ?spelling.
filter(contains(?spelling, " "))
filter not exists {
?name wdt:P31/wdt:P279* wd:Q1243157.
}
}
#hyphenated name not marked as such
select ?name ?spelling where {
?name wdt:P31/wdt:P279* wd:Q202444;
wdt:P1705 ?spelling.
filter(contains(?spelling, "-"))
filter not exists {
?name wdt:P31/wdt:P279* wd:Q1243157.
}
}
#Items with (P31 = album) + amountOfStatements more statements
select distinct ?item where {
bind(1 as ?amountOfStatements)
filter not exists { ?item a ontolex:LexicalEntry. }
filter not exists { ?item a wikibase:Property. }
###
bind(?amountOfStatements + 1 as ?correctedAmountOfStatements)
?item wikibase:statements ?correctedAmountOfStatements;
wdt:P31 wd:Q482994.
}
limit 100
offset 0