User:Moebeus/SPARQL queries

Home

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)
Number of albums by language in descending order

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
Most frequently used titles (P1476) found on audio tracks (Q7302866)

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 []. }
}
Albums without a performer

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))
}
Orphaned or incorrectly linked discographies, using FILTER
#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. }
}
Orphaned or incorrectly linked discographies, using MINUS

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)
number of instances of genres in descending order
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". }
}
musical works/compositions with a Wikisource link

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 []. }
}
Try it!
#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 []. }
}
Try it!
#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 []. }
}
Try it!
#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 []. }
}
Try it!
#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.
}
Try it!

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.
  }
}
Try it!
#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.
  }
}
Try it!
#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
Try it!