Metaclasses by instance count
The query ranks metaclasses in Wikidata by their number of
distinct direct instance of (P31) statements. Candidates are explicitly typed
metaclasses: they have an
instance of type equal to metaclass
or one of its subclasses, such as second-order class. This follows recorded
types, rather than checking that each instance is itself a class. The counts
use truthy P31 values and do not include instances inherited
through subclasses. Ties are resolved by item URI.
printf '%s' 'PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?metaclass ?metaclassLabel ?instanceCount WHERE {
{
SELECT ?metaclass (COUNT(DISTINCT ?instance) AS ?instanceCount) WHERE {
{
SELECT DISTINCT ?metaclass WHERE {
?metaclass wdt:P31/wdt:P279* wd:Q19478619 .
}
}
?instance wdt:P31 ?metaclass .
}
GROUP BY ?metaclass
ORDER BY DESC(?instanceCount) ?metaclass
}
OPTIONAL {
?metaclass rdfs:label ?englishLabel .
FILTER(LANG(?englishLabel) = "en")
}
BIND(COALESCE(?englishLabel, STRAFTER(STR(?metaclass), "entity/")) AS ?metaclassLabel)
}
ORDER BY DESC(?instanceCount) ?metaclass
' |
vitrify sparql --endpoint https://query.wikidata.org/sparql \
--query - \
--format csv \
--to top-metaclasses
Failure65.12 s
Response bytes
top-metaclasses/
├── ro-crate-metadata.json
└── query.rq
Failure
endpoint returned HTTP 504 Gateway Timeout
{
"@context": "https://w3id.org/ro/crate/1.3/context",
"@graph": [
{
"@id": "ro-crate-metadata.json",
"@type": "CreativeWork",
"about": {
"@id": "./"
},
"conformsTo": {
"@id": "https://w3id.org/ro/crate/1.3"
}
},
{
"@id": "query.rq",
"@type": "File",
"contentSize": "756",
"encodingFormat": "application/sparql-query",
"sha256": "f3557c77790806b0596f657270d920ceedf03359c71d023158f1558b0b38a61c"
},
{
"@id": "https://query.wikidata.org/sparql",
"@type": "Organization"
},
{
"@id": "https://vitrify.iolanta.tech",
"@type": "SoftwareApplication",
"name": "Vitrify",
"url": "https://vitrify.iolanta.tech",
"version": "0.1.3"
},
{
"@id": "#retrieval-duration",
"@type": "PropertyValue",
"name": "Retrieval duration",
"propertyID": "retrieval-duration",
"unitCode": "SEC",
"value": 65.120325202
},
{
"@id": "#error",
"@type": "Thing",
"description": "endpoint returned HTTP 504 Gateway Timeout"
},
{
"@id": "./",
"@type": "Dataset",
"additionalProperty": [
{
"@id": "#retrieval-duration"
}
],
"datePublished": "2026-10-31T11:21:53.387052171+00:00",
"description": "SPARQL retrieval recorded by Vitrify.",
"hasPart": [
{
"@id": "query.rq"
}
],
"license": "No license asserted by Vitrify; consult the source endpoint's terms of use.",
"name": "SPARQL retrieval",
"publisher": {
"@id": "https://query.wikidata.org/sparql"
}
},
{
"@id": "#retrieval",
"@type": "CreateAction",
"actionStatus": {
"@id": "http://schema.org/FailedActionStatus"
},
"agent": {
"@id": "https://vitrify.iolanta.tech"
},
"description": "HTTP 504; Accept: text/csv",
"endTime": "2026-10-31T11:21:53.387052171+00:00",
"error": {
"@id": "#error"
},
"identifier": "https://query.wikidata.org/sparql",
"instrument": {
"@id": "https://vitrify.iolanta.tech"
},
"object": [
{
"@id": "https://query.wikidata.org/sparql"
},
{
"@id": "query.rq"
}
],
"startTime": "2026-10-31T11:20:48.265490021+00:00"
}
]
}
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?metaclass ?metaclassLabel ?instanceCount WHERE {
{
SELECT ?metaclass (COUNT(DISTINCT ?instance) AS ?instanceCount) WHERE {
{
SELECT DISTINCT ?metaclass WHERE {
?metaclass wdt:P31/wdt:P279* wd:Q19478619 .
}
}
?instance wdt:P31 ?metaclass .
}
GROUP BY ?metaclass
ORDER BY DESC(?instanceCount) ?metaclass
}
OPTIONAL {
?metaclass rdfs:label ?englishLabel .
FILTER(LANG(?englishLabel) = "en")
}
BIND(COALESCE(?englishLabel, STRAFTER(STR(?metaclass), "entity/")) AS ?metaclassLabel)
}
ORDER BY DESC(?instanceCount) ?metaclass