query-9efc7ae38c81161960b357edcee31665

rq turtle/ttl

Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement). Each composer’s most used tonality, with number of works in that tonality.

(If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)

The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).

To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count WHERE { { # 4. Group again, this time just by the composer. # We also select the highest count of a tonality. # Notice that we don’t know what tonality this count is associated with – we’ll get to that. # So now we have each composer, along with how often they used whatever tonality they used most. SELECT ?composer (MAX(?count) AS ?count_) WHERE { { # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality. # (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.) ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”. } } GROUP BY ?composer } { # 6. Identical to 2. SELECT ?composer ?tonality (COUNT(?composition) AS ?count) WHERE { # 5. Identical to 1. ?composition wdt:P86 ?composer; wdt:P826 ?tonality. } GROUP BY ?composer ?tonality HAVING(?count > 1) # 7. Identical to 3. } # 8. That’s it. Wait, what? # From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most. # From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality. # The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined, # we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 – # that is, where this tonality was used as often as the composer’s most-used tonality. # In other words, this must be the composer’s most-used tonality (except when there are multiple tonalities with the same count). SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement).

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Each composer’s most used tonality, with number of works in that tonality.
# (If this is ambiguous – multiple tonalities with the same number – there are multiple results for one composer.)
#
# The SPARQL for this is an evil perversion of three subqueries (one of them nested in another).
# To understand it, you have to go inside out… follow the numbers.

SELECT ?composerLabel ?tonalityLabel ?count
WHERE
{
  {
    # 4. Group again, this time just by the composer.
    #    We also select the highest count of a tonality.
    #    Notice that we don’t know what tonality this count is associated with – we’ll get to that.
    #    So now we have each composer, along with how often they used whatever tonality they used most.
    SELECT ?composer (MAX(?count) AS ?count_)
    WHERE
    {
      {
        # 2. Group by composer and tonality, so that for each composer and tonality, we get a count of how often the composer used this tonality.
        SELECT ?composer ?tonality (COUNT(?composition) AS ?count)
        WHERE
        {
          # 1. Extremely straightforward: the ?composition has the composer ?composer and the tonality ?tonality.
          #    (I’m not bothering with any “instance of” because the presence of these two properties is a sufficient indicator of ?composition being a composition.)
          ?composition wdt:P86 ?composer;
                       wdt:P826 ?tonality.
        }
        GROUP BY ?composer ?tonality
        HAVING(?count > 1) # 3. Limit that to counts > 1, because using a tonality once is hardly “most used”.
      }
    }
    GROUP BY ?composer
  }
  {
    # 6. Identical to 2.
    SELECT ?composer ?tonality (COUNT(?composition) AS ?count)
    WHERE
    {
      # 5. Identical to 1.
      ?composition wdt:P86 ?composer;
                   wdt:P826 ?tonality.
    }
    GROUP BY ?composer ?tonality
    HAVING(?count > 1) # 7. Identical to 3.
  }
  # 8. That’s it. Wait, what?
  #    From 4, we now have ?composer, any composer, and ?count, the count of how often they used whatever tonality they used most.
  #    From 6, we also have a ?composer, as well as a ?tonality, and the count of how often they used that particular tonality.
  #    The trick is that ?composer and ?count are the same variable in each subquery, and so now, when the two subqueries are joined,
  #    we select only that ?tonality from 6 where the ?composer and the ?count are identical to those from 4 –
  #    that is, where this tonality was used as often as the composer’s most-used tonality.
  #    In other words, this must *be* the composer’s most-used tonality (except when there are multiple tonalities with the same count).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?count) # 9. Order by count (highest first), because the result isn’t very meaningful for low counts (many compositions aren’t on Wikidata or don’t have a tonality statement).

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?composer") v2("?composition") v6("?count"):::projected v5("?count_") v4("?tonality") c5(["bd:serviceParam"]):::iri c7(["en"]):::literal f0[["?count > '1^^xsd:integer'"]] f0 --> v6 v2 --"wdt:P86"--> v3 v2 --"wdt:P826"--> v4 bind2[/"count(?composition)"/] v2 --o bind2 bind2 --as--o v6 bind4[/"max(?count)"/] v6 --o bind4 bind4 --as--o v5 f5[["?count > '1^^xsd:integer'"]] f5 --> v6 v2 --"wdt:P86"--> v3 v2 --"wdt:P826"--> v4 bind7[/"count(?composition)"/] v2 --o bind7 bind7 --as--o v6 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c5 --"wikibase:language"--> c7 end