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://qlever.dev/api/wikidata \
  --query - \
  --format csv \
  --to fourth-order-classes

Success0.78 s76 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",
      "conformsTo": {
        "@id": "https://w3id.org/ro/crate/1.3"
      },
      "about": {
        "@id": "./"
      }
    },
    {
      "@id": "./",
      "@type": "Dataset",
      "name": "results.csv",
      "description": "SPARQL retrieval materialized by Vitrify.",
      "datePublished": "2026-11-21T11:58:27.354122963+00:00",
      "additionalProperty": [
        {
          "@id": "#retrieval-duration"
        }
      ],
      "license": "No license asserted by Vitrify; consult the source endpoint's terms of use.",
      "hasPart": [
        {
          "@id": "results.csv"
        },
        {
          "@id": "query.rq"
        }
      ],
      "publisher": {
        "@id": "https://qlever.dev/api/wikidata"
      },
      "author": {
        "@id": "https://vitrify.iolanta.tech"
      }
    },
    {
      "@id": "results.csv",
      "@type": "File",
      "contentSize": "76",
      "sha256": "9b6bd97bf66d0f04b74a39c558d663b64c74963ee31505636d67a1fb663e292e",
      "encodingFormat": "text/csv"
    },
    {
      "@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.4"
    },
    {
      "@id": "https://qlever.dev/api/wikidata",
      "@type": "Organization"
    },
    {
      "@id": "#retrieval",
      "@type": "CreateAction",
      "actionStatus": {
        "@id": "http://schema.org/CompletedActionStatus"
      },
      "startTime": "2026-11-21T11:58:26.569917043+00:00",
      "endTime": "2026-11-21T11:58:27.354122963+00:00",
      "instrument": {
        "@id": "https://vitrify.iolanta.tech"
      },
      "agent": {
        "@id": "https://vitrify.iolanta.tech"
      },
      "object": [
        {
          "@id": "https://qlever.dev/api/wikidata"
        },
        {
          "@id": "query.rq"
        }
      ],
      "result": {
        "@id": "results.csv"
      },
      "identifier": "https://qlever.dev/api/wikidata",
      "description": "HTTP 200; Accept: text/csv"
    },
    {
      "@id": "#retrieval-duration",
      "@type": "PropertyValue",
      "propertyID": "retrieval-duration",
      "name": "Retrieval duration",
      "value": 0.782397498,
      "unitCode": "SEC"
    }
  ]
}

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