Metaclasses of metaclasses
The query finds explicitly typed metaclasses in Wikidata
whose recorded direct instances are all explicitly typed metaclasses too.
It requires at least one instance, ranks matches by distinct
instance count, and shows one example instance per match. Metaclass typing
uses instance of (P31), followed by the type's subclass of (P279) hierarchy
to metaclass.
Wikidata calls a class of second-order classes a third-order class. The query also allows mixed or higher orders. It checks recorded truthy P31 values; missing metaclass typing excludes a candidate, and unrecorded instances cannot be checked. Ties and example instances are selected by 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 ?exampleInstance ?exampleInstanceLabel WHERE {
{
SELECT ?metaclass (COUNT(DISTINCT ?instance) AS ?instanceCount)
(MIN(STR(?instance)) AS ?exampleInstanceIRI) WHERE {
{
SELECT DISTINCT ?metaclass WHERE {
?metaclass wdt:P31/wdt:P279* wd:Q19478619 .
}
}
?instance wdt:P31 ?metaclass .
FILTER NOT EXISTS {
?counterexample wdt:P31 ?metaclass .
FILTER NOT EXISTS {
?counterexample wdt:P31/wdt:P279* wd:Q19478619 .
}
}
}
GROUP BY ?metaclass
ORDER BY DESC(?instanceCount) ?metaclass
}
BIND(IRI(?exampleInstanceIRI) AS ?exampleInstance)
OPTIONAL {
?metaclass rdfs:label ?englishLabel .
FILTER(LANG(?englishLabel) = "en")
}
OPTIONAL {
?exampleInstance rdfs:label ?exampleEnglishLabel .
FILTER(LANG(?exampleEnglishLabel) = "en")
}
BIND(COALESCE(?englishLabel, STRAFTER(STR(?metaclass), "entity/")) AS ?metaclassLabel)
BIND(COALESCE(?exampleEnglishLabel, STRAFTER(STR(?exampleInstance), "entity/")) AS ?exampleInstanceLabel)
}
ORDER BY DESC(?instanceCount) ?metaclass
' |
vitrify sparql --endpoint https://qlever.dev/api/wikidata \
--query - \
--format csv \
--to metaclasses-of-metaclasses
Failure30.65 s
metaclasses-of-metaclasses/
├── ro-crate-metadata.json
└── query.rq
Failure
endpoint returned HTTP 429 Too Many Requests
{
"@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": "1306",
"encodingFormat": "application/sparql-query",
"sha256": "edb75482041c86b5f18389864f00cf5eb7da8a99f75753a3867a1ce1c788bbe0"
},
{
"@id": "https://qlever.dev/api/wikidata",
"@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": 30.649399697
},
{
"@id": "#error",
"@type": "Thing",
"description": "endpoint returned HTTP 429 Too Many Requests"
},
{
"@id": "./",
"@type": "Dataset",
"additionalProperty": [
{
"@id": "#retrieval-duration"
}
],
"datePublished": "2026-11-07T10:53:50.683318959+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://qlever.dev/api/wikidata"
}
},
{
"@id": "#retrieval",
"@type": "CreateAction",
"actionStatus": {
"@id": "http://schema.org/FailedActionStatus"
},
"agent": {
"@id": "https://vitrify.iolanta.tech"
},
"description": "HTTP 429; Accept: text/csv",
"endTime": "2026-11-07T10:53:50.683318959+00:00",
"error": {
"@id": "#error"
},
"identifier": "https://qlever.dev/api/wikidata",
"instrument": {
"@id": "https://vitrify.iolanta.tech"
},
"object": [
{
"@id": "https://qlever.dev/api/wikidata"
},
{
"@id": "query.rq"
}
],
"startTime": "2026-11-07T10:53:20.032658271+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 ?exampleInstance ?exampleInstanceLabel WHERE {
{
SELECT ?metaclass (COUNT(DISTINCT ?instance) AS ?instanceCount)
(MIN(STR(?instance)) AS ?exampleInstanceIRI) WHERE {
{
SELECT DISTINCT ?metaclass WHERE {
?metaclass wdt:P31/wdt:P279* wd:Q19478619 .
}
}
?instance wdt:P31 ?metaclass .
FILTER NOT EXISTS {
?counterexample wdt:P31 ?metaclass .
FILTER NOT EXISTS {
?counterexample wdt:P31/wdt:P279* wd:Q19478619 .
}
}
}
GROUP BY ?metaclass
ORDER BY DESC(?instanceCount) ?metaclass
}
BIND(IRI(?exampleInstanceIRI) AS ?exampleInstance)
OPTIONAL {
?metaclass rdfs:label ?englishLabel .
FILTER(LANG(?englishLabel) = "en")
}
OPTIONAL {
?exampleInstance rdfs:label ?exampleEnglishLabel .
FILTER(LANG(?exampleEnglishLabel) = "en")
}
BIND(COALESCE(?englishLabel, STRAFTER(STR(?metaclass), "entity/")) AS ?metaclassLabel)
BIND(COALESCE(?exampleEnglishLabel, STRAFTER(STR(?exampleInstance), "entity/")) AS ?exampleInstanceLabel)
}
ORDER BY DESC(?instanceCount) ?metaclass