Legislation.gov.uk data reuse documentation

Linked Data and the SPARQL endpoint

What is the Linked Data service?

The Legislation Linked Data service provides metadata about UK legislation from 1235 to the present day, including historical legislation enacted before the existence of Great Britain and the United Kingdom. You can query the metadata through a SPARQL query service (see the section on querying using SPARQL below), and we intend to also offer the data via a REST API in future (see the section on future developments below).

The metadata in the Linked Data store come from various sources, including the legislation itself and various reference texts and databases supplied to us by other organisations. We are grateful to our partner organisations for their contributions to the core reference dataset.

The Legislation Linked Data service is currently in beta and the service is subject to change (see the section on limitations and future developments below). We want to gather diverse feedback and very much appreciate all users who are able to find time to experiment with the service and tell us about their experiences. You are welcome to contact us with feedback.

What does the Linked Data service provide?

Purpose of the service

The purpose of the Linked Data service is to be a single source of truth for UK legislation, combining different kinds of data about legislation from many sources and making it available in one place through a unified interface. We are modelling our data using public ontologies, both pre-existing and bespoke (read about our ontologies and vocabularies below), so that our data have a coherent and consistent structure.

We hope that the Linked Data service will enable developers and data users to more easily find information about legislation and build applications that use legislation data.

The data

Sources of data

The Linked Data service will provide legislation data from multiple sources (internal and external systems, reference texts and databases, external organisations) and on various topics (basic data, amendments to legislation, citations and cross-references and so on). We have designed our data model to distinguish which data for each item of legislation relate to which source and topic (see the Datasets section below), so that it is possible to query for only certain kinds of data for a given item or items.

The sources of data we currently use include:

We will continue to add new sources and kinds of data to the Linked Data service (see the section on future developments below).

Categories of available data

The Linked Data service currently provides basic metadata about:

Thing Description
Legislation and interpretations The current and original interpretation of each item of UK legislation and the item of legislation that it represents
Welsh-language interpretations of legislation
Quashed items of UK legislation
Monarchs, reigns and parliamentary sessions For older legislation, the parliamentary sessions, reigns and regnal years during which legislation was enacted, and the reigning monarchs for those periods
Datasets Datasets available through the service
Ontology Classes and properties used in the core reference ontology
The service The service itself and its SPARQL endpoint
Provenance Information about the provenance of data in the store, such as when and how it was created

Understanding the structure of the data

Legislation, versions and FRBR

We use a variant of the FRBR model to structure our legislation and its metadata. FRBR defines the concept of a “work” (an intellectual creation) separately from an “expression” (the realisation of a work, such as an edition of a book or an arrangement of a song) and a “manifestation” (the embodiment of an expression, such as a print or e-book version of an edition of a book, or a recording of an arrangement of a song).

In the legislation ontology, we map the FRBR concepts onto the following legislation concepts:

An item of legislation will always have at least one interpretation, which is the text of the item as it was enacted by a legislature or made by a government minister or body. If the item has been amended, it will also have additional interpretations for each time period (and in some cases geographical extent) where the text or meaning or the document differs. Currently, the core reference dataset only contains information on the original and current interpretation of each item of legislation (plus an additional Welsh original and current interpretation for Welsh dual-language items), or a “quashed” interpretation for any item that the courts have declared unlawful.

Note that we only provide metadata about items and interpretations of legislation, not their manifestations.

Triples

The Linked Data store is a triplestore – a database that contains triples. Each triple is a three-part statement consisting of:

For example, a triple stating that the title of 2021 c. 10 is “Trade Act 2021” could be represented as follows:

prefix @leg: <http://www.legislation.gov.uk/def/legislation>

<http://www.legislation.gov.uk/id/ukpga/2021/10> leg:title "Trade Act 2021"@en.

In this example:

Here, the URI ending /ukpga/2021/10 is the subject, leg:title (short for <http://www.legislation.gov.uk/def/legislation/title>) is the predicate and "Trade Act 2021"@en is the object – in this case, a string with an @en (English) language tag.

Ontologies and vocabularies

The Linked Data service uses a bespoke legislation ontology. The ontology specifies a vocabulary of classes and properties that entities in the data can use, such as ScottishAct or title. There is documentation for the ontology.

The most commonly used vocabularies in the Linked Data service are:

Ontology Namespace prefix Description
Core legislation ontology http://www.legislation.gov.uk/def/legislation/ Defines core classes and properties for linked data for legislation.gov.uk
RDF vocabulary http://www.w3.org/1999/02/22-rdf-syntax-ns# Defines core classes and properties for relational data
RDF schema vocabulary http://www.w3.org/2000/01/rdf-schema# Defines core classes and properties for describing ontologies
Dublin Core http://purl.org/dc/terms/ Defines common classes and properties for metadata
OWL (Web Ontology Language) http://www.w3.org/2002/07/owl# Defines further classes and properties for describing ontologies

Graphs

Each triple in the Linked Data store exists within a named graph, which is a group of triples named by a URI. The Linked Data service uses graphs to group together triples that relate to one or more entities and also share a specific theme and source. For example, the above triple exists within the graph named <http://www.legislation.gov.uk/graph/core/publishingsystem/department/ukpga/2021/10>. The graph URI indicates that this graph is part of the “core” topic dataset, the “publishing” system dataset and the “department” origin dataset (see below).

Datasets

The Linked Data service subdivides its data into different datasets according to the following attributes:

Each topic, system, origin and data unit has a dataset in the Linked Data store. Each dataset links to all the graphs that contain related data (either data within the dataset’s topic, from the dataset’s related system or origin, or within the related data unit).

Provenance information

The Linked Data store contains provenance information, which explains when and how a particular graph or dataset was modified. Each graph and dataset links to one or more provenance events via the predicate <http://www.w3.org/ns/prov#wasInfluencedBy>, each of which indicates a type of event (creation or update) and a time of occurrence.

Limitations and future developments

Limitations

The Legislation Linked Data service is currently in beta and so its functionality may change, including:

However, we do not expect to make many breaking changes to the ontology, or to remove more than a very small amount of data. We do not normally remove data unless they are erroneous.

The Linked Data service does not not currently support querying legislation document structure or text.

Future developments

In future, we intend to release a Linked Data API that will allow users to retrieve metadata from the Linked Data service for individual legislation items and entities. It will augment the existing Legislation API available on legislation.gov.uk by providing metadata from the Linked Data service both as individual metadata resources and embedded within legislation documents.

We also plan for the Linked Data service to provide the following additonal data:

Please contact us if you want to request or suggest other legislation data that we could make available through the Linked Data service.

Querying using SPARQL

You can query the data in the Linked Data store directly through a SPARQL endpoint, either with our in-browser query editor or connecting directly or using your own software. The endpoint is compliant with the SPARQL 1.1 Query Language specification. For more information on using SPARQL to query linked data, read the specification for the SPARQL query language.

The SPARQL endpoint allows you to query all data available from the Linked Data service. For example, the following SPARQL query returns all the data units containing data about the Kew Gardens (Leases) Act 2019 (c. 25) and its interpretations, along with information about each of the provenance events that affected them:

PREFIX prov: <http://www.w3.org/ns/prov#>

SELECT DISTINCT ?dataunit ?prov ?provProperty ?provValue WHERE {
  VALUES ?item {
  <http://www.legislation.gov.uk/id/ukpga/2019/25>
  <http://www.legislation.gov.uk/ukpga/2019/25>
  <http://www.legislation.gov.uk/ukpga/2019/25/enacted>
  }

  GRAPH ?dataunit { 
  ?item ?p []
  }

  ?dataunit prov:wasInfluencedBy ?prov .
  ?prov ?provProperty ?provValue
}
ORDER BY ?dataunit ?prov ?provProperty

The following SPARQL query finds all UK Public General Acts and UK Local Acts with the string “Cambridge” (case-insensitive) anywhere in the title:

PREFIX leg: <http://www.legislation.gov.uk/def/legislation/>

SELECT ?leg ?title WHERE {
  VALUES ?type {
  leg:UnitedKingdomPublicGeneralAct
  leg:UnitedKingdomLocalAct
  }

  ?leg a ?type ; leg:title ?title .

  FILTER REGEX(STR(?title), 'Cambridge')
}

Licence

For information on licensing and re-using our data, please see the Licence page.