Skip to content

Fourth-order classes

The query lists all items in Wikidata whose recorded instance of (P31) type is fourth-order class or a subclass of that type, ordered by English label and item URI. A fourth-order class has third-order classes as its instances. This query selects recorded types; it does not check the order of every instance.

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 DISTINCT ?class ?classLabel WHERE {
  ?class wdt:P31/wdt:P279* wd:Q24027474 .
  OPTIONAL {
    ?class rdfs:label ?englishLabel .
    FILTER(LANG(?englishLabel) = "en")
  }
  BIND(COALESCE(?englishLabel, STRAFTER(STR(?class), "entity/")) AS ?classLabel)
}
ORDER BY ?classLabel ?class
' |
  vitrify sparql --endpoint https://query.wikidata.org/sparql \
  --query - \
  --format csv \
  --to fourth-order-classes

Success0.64 s78 bytes

Response bytes

fourth-order-classes/
├── results.csv
├── ro-crate-metadata.json
└── query.rq

{
  "@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": "./",
      "@type": "Dataset",
      "additionalProperty": [
        {
          "@id": "#retrieval-duration"
        }
      ],
      "author": {
        "@id": "https://vitrify.iolanta.tech"
      },
      "datePublished": "2026-11-07T10:52:00.383167465+00:00",
      "description": "SPARQL retrieval materialized by Vitrify.",
      "hasPart": [
        {
          "@id": "results.csv"
        },
        {
          "@id": "query.rq"
        }
      ],
      "license": "No license asserted by Vitrify; consult the source endpoint's terms of use.",
      "name": "results.csv",
      "publisher": {
        "@id": "https://query.wikidata.org/sparql"
      }
    },
    {
      "@id": "results.csv",
      "@type": "File",
      "contentSize": "78",
      "encodingFormat": "text/csv",
      "sha256": "e50d18b8a65b1cc52f9f2bb5fc516dff1719cc528b87c824c9d4e62b66e37983"
    },
    {
      "@id": "query.rq",
      "@type": "File",
      "contentSize": "440",
      "encodingFormat": "application/sparql-query",
      "sha256": "ed05d8a1f14015499577c2472b7373cf251d61d1e64ee9e226771962883f6022"
    },
    {
      "@id": "https://vitrify.iolanta.tech",
      "@type": "SoftwareApplication",
      "name": "Vitrify",
      "url": "https://vitrify.iolanta.tech",
      "version": "0.1.3"
    },
    {
      "@id": "https://query.wikidata.org/sparql",
      "@type": "Organization"
    },
    {
      "@id": "#retrieval",
      "@type": "CreateAction",
      "actionStatus": {
        "@id": "http://schema.org/CompletedActionStatus"
      },
      "agent": {
        "@id": "https://vitrify.iolanta.tech"
      },
      "description": "HTTP 200; Accept: text/csv",
      "endTime": "2026-11-07T10:52:00.383167465+00:00",
      "identifier": "https://query.wikidata.org/sparql",
      "instrument": {
        "@id": "https://vitrify.iolanta.tech"
      },
      "object": [
        {
          "@id": "https://query.wikidata.org/sparql"
        },
        {
          "@id": "query.rq"
        }
      ],
      "result": {
        "@id": "results.csv"
      },
      "startTime": "2026-11-07T10:51:59.740399993+00:00"
    },
    {
      "@id": "#retrieval-duration",
      "@type": "PropertyValue",
      "name": "Retrieval duration",
      "propertyID": "retrieval-duration",
      "unitCode": "SEC",
      "value": 0.641391339
    }
  ]
}

Download ro-crate-metadata.json

ro-crate-metadata.json

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 DISTINCT ?class ?classLabel WHERE {
  ?class wdt:P31/wdt:P279* wd:Q24027474 .
  OPTIONAL {
    ?class rdfs:label ?englishLabel .
    FILTER(LANG(?englishLabel) = "en")
  }
  BIND(COALESCE(?englishLabel, STRAFTER(STR(?class), "entity/")) AS ?classLabel)
}
ORDER BY ?classLabel ?class

Download query.rq

query.rq