legalgraph

How the knowledge graph is built from official law texts

From law text to graph: how each text is fetched, checked and turned into data, and how you can check it.

Every provision, quote and checklist rule on this site traces back to a file published by an official portal. What the law says is never typed in by hand: it is generated from the official text, and the generation is checked by a program. Our readings of the law are written by hand, kept apart, and marked as drafts. This page is the process, and what makes each step verifiable.

Before you start: the terms

This page walks through how the graph is built, step by step: from the official text to the files you can download, and the checks in between. The graph is not in a format of our own: it uses open standards of the W3CWorld Wide Web ConsortiumThe body that writes the open standards of the web, among them RDF, SPARQL, SHACL, SKOS and OWL., which off-the-shelf tools read, so you can query and check it without our software.

RDFResource Description FrameworkThe W3C's model for data as a graph: every statement is a triple of subject, predicate and object, each named by a URL.
The data model. Everything is a statement of three parts, such as “§ 5(1) DDGGerman Digital Services ActGerman: Digitale-Dienste-GesetzThe German law that says what a business website must show about who runs it, the imprint (Impressum). — requires — the register entry”; together, the statements form the graph.
TurtleTerse RDF Triple LanguageA W3C syntax for writing RDF as plain text, readable by people as well as programs; its files end in .ttl.
Just a syntax: a plain-text way of writing those statements down, readable by people as well as programs. The graph's files end in .ttl.
SPARQLSPARQL Protocol and RDF Query LanguageThe query language for RDF graphs: it finds every match of a pattern across the whole graph.
The query language. One query searches the whole graph, across every country at once; an example follows below.
SHACLShapes Constraint LanguageA W3C standard for rules about RDF data, such as 'every act has exactly one jurisdiction', checked by a program.
Rules about the data, checked by a program, such as “every obligation names the provisions it comes from”.
ELIEuropean Legislation IdentifierAn EU standard for naming and describing legislation, with stable web addresses and an ontology; legalgraph uses its ontology., SKOSSimple Knowledge Organization SystemA W3C standard for vocabularies: concepts with labels in several languages, definitions and broader or narrower terms.
Shared vocabularies: ELI for identifying legislation, SKOS for labels and categories. Because we use them, other graphs understand ours without a translation table.
XMLExtensible Markup LanguageA text format that marks up a document's structure with tags; many official portals publish their laws in it.
The markup in which the law texts are annotated before anything is generated from them.

Every technical term on this page links to the glossary: point at an underlined term for a short explanation, or click it to read more. Why we chose a graph at all is explained further down.

The process at a glance

From the law text to the siteThe official text is kept in Git unchanged. It is annotated, and the annotation is proved against the original. A program extracts Turtle from it. Editorial Turtle (rules, cases, translations) is added. The whole graph is validated, then published as a static site, as downloads and for SPARQL queries.Kept in Git: every change versioned and reviewedGenerated on every build1Official text
Laws, judgments, guidelines as the portal publishes them: XML, HTML or PDF
sources/
2Annotated text
Our marks on the official XML, or a transcription into our XML schema
*.annotated.xml
4Generated Turtle
Provisions and quotes, extracted by a program, never edited by hand
data/extracted/
The graph
All the Turtle, checked against the ontology and its SHACL shapes
legalgraph.ttl
5Editorial Turtle
Rules, cases, translations: each cites its provisions, Draft until reviewed
data/rules/ …
✓ hash + date; re-checked upstream
✓ marks removed = the original
✓ same input, same bytes
✓ syntax · terms · shapes · English
Static sitelegalgraph.orgDownloadsTTL · NT · JSON-LD · JSONSPARQLyour own questions
From the law text to the site. Numbers are the sections below; each tick is a check that fails the build if the step went wrong.

Where everything lives

All of it is in one public repository on GitHub. Each folder below links to it there; the numbers are the steps on this page.

One duty, followed through

The steps below follow a single duty from the law to this site. A business established in Germany that is entered in the commercial register must name the register and its number on its website, for example Amtsgericht Charlottenburg, HRBCommercial register, section BGerman: Handelsregister Abteilung BThe part of the German commercial register for companies such as a GmbH or AG; with the court, its number identifies the company. 272803 B, as our own imprint does. The duty is in point 4 of § 5(1) of the Digitale-Dienste-Gesetz (DDG). Businesses elsewhere in the EUEuropean UnionThe union of 27 European states; its regulations apply directly in each of them, and its directives are put into national law. have the same duty under their own country's law.

1. The original is kept, and locked

The act is downloaded from the official portal — the EU's Cellar, gesetze-im-internet.de, legislation.gov.uk, zakon.rada.gov.ua — and the file is kept unchanged with its SHA-256 and retrieval date. Where a portal blocks automated access, a page saved by hand in a browser does instead: it is matched to its entry by the browser's saved from url marker. Re-downloading later (sources fetch --check) flags a changed text; for HTML pages the comparison is on the words, not the markup, so a regenerated page or a browser's rewrite does not look like a legal change.

In the example: the DDG comes as XML inside a zip from gesetze-im-internet.de. Its index records the file, where it came from, when, and its fingerprint:

sources/de/ddg/source.yamlexcerpt
originals:
  - file: BJNR0950B0024.xml
    url: https://www.gesetze-im-internet.de/ddg/xml.zip
    fetch: zip-member
    member: BJNR0950B0024.xml
    media_type: application/xml
    retrieved_on: 2026-10-31
    sha256: bded1462fd8cf26db62d7a09883d361a4517c378f094a9a50e29f298526011c6
annotated: BJNR0950B0024.annotated.xml

2. The text is annotated — and checked against the original

Which provisions matter, and what each says, is marked up in XML. Two forms, depending on what the portal publishes:

In the example: the paragraph gets an identifier and a citation, and point 4 gets one mark, lga:requires="RegisterEntry": this line requires the register entry. Everything else is the official file, untouched.

sources/de/ddg/BJNR0950B0024.annotated.xmlexcerpt
<P lga:provision="DE-DDG-s5-1" lga:citation="§ 5 Abs. 1 DDG"
   lga:regulates="ProviderIdentification" lga:implements="EU-2000-31-art5-1">
  (1) Diensteanbieter haben für geschäftsmäßige, … digitale Dienste folgende Informationen … ständig verfügbar zu halten:
  …
  <DT>4.</DT>
  <DD Font="normal" lga:requires="RegisterEntry">
    <LA Size="normal">die Angabe des Handelsregisters oder ähnlicher Register, in das sie eingetragen sind, und die entsprechende Registernummer,</LA>
  </DD>

3. Language versions are checked the same way — or marked as ours

Where a portal publishes other language versions, they are kept as originals too and each translated provision is checked against its own original and against the structure of the main text. A translation gets an as_of date: where the portal's own notes show the text it translates was amended later, the check fails — an official translation older than the law must not stand in for it. Whatever has no usable official English is translated by machine and marked translatedBy as such; nothing in the graph is passed off as official that we wrote ourselves.

In the example: the DDG has no official English, so its English is a machine translation, marked as one and a draft until a person reviews it. It carries a hash of the German it translates, so it goes stale if the law changes:

data/translations/en/de.ttlexcerpt
4. the commercial register or similar register in which they are entered, and the corresponding register number,

4. The graph is generated, not written

sources extract turns the annotated XML into Turtle — mechanically, same input same bytes — and extract --check proves the published files are exactly what the generator produces.

In the example: the mark on point 4 becomes lgv:RegisterEntry in the provision's list of required information. The entry also records the file and the exact element it came from, so the statement leads back to its words:

data/extracted/de/ddg.ttlexcerpt
lg:DE-DDG-s5-1
    a lgo:Provision ;
    eli:is_part_of lg:DE-DDG ;
    lgo:citation "§ 5 Abs. 1 DDG" ;
    lgo:implements lg:EU-2000-31-art5-1 ;
    lgo:regulates lgv:ProviderIdentification ;
    lgo:requiresDisclosureOf lgv:ProviderName , … , lgv:RegisterEntry , … ;
    lgo:reviewStatus lgv:SourceChecked ;
    lgo:sourceDocument lg:DE-DDG-source ;
    lgo:sourceElement "/dokumente/norm[8]/textdaten[1]/text[1]/Content[1]/P[1]" ;
    lgo:sourceUrl "https://www.gesetze-im-internet.de/ddg/__5.html"^^xsd:anyURI .

5. Our readings are kept apart

What a provision means for a business is a rule, written by hand in its own Turtle files with the cases that illustrate it. Each rule names the provisions it is read from, the conditions under which it applies, and its review status. Rules stay Draft until a lawyer reviews them.

In the example: the rule says who must do what, and when. It applies when three things hold: the business is established in Germany, its website serves business purposes, and it is entered in a register. It rests on § 5(1) DDG and spells out the EU rule from the e-Commerce Directive:

data/rules/de.ttlexcerpt
lg:DE-R-impressum-register a lgo:Obligation ;
    rdfs:label "Impressum: register and registration number"@en ;
    lgo:refines lg:EU-R-service-provider-information-register ;
    lgo:establishedBy lg:DE-DDG-s5-1 ;
    lgo:bearer lgv:DigitalServiceProvider ;
    lgo:deonticType lgv:Must ;
    lgo:appliesIn lg:DE ;
    lgo:appliesWhen lgv:EstablishedInGermany , lgv:CommercialDigitalService , lgv:RegisteredInPublicRegister ;
    lgo:partOfDisclosure lgv:ProviderIdentification ;
    lgo:requiresDisclosureOf lgv:RegisterEntry ;
    lgo:reviewStatus lgv:Draft .

An example business pins the rule down. A German GmbHGerman limited liability companyGerman: Gesellschaft mit beschränkter HaftungThe most common German company form: its owners are liable only with the company's capital, at least 25,000 euros. with an online shop, entered in the register, must get this rule; the tests fail if it gets one rule more or one fewer than listed:

scenarios/de-gmbh-shop.yamlexcerpt
name: German GmbH with an online shop
established_in: DE
facts:
  - CommercialDigitalService
  - RegisteredInPublicRegister
  - …
obligations:
  - DE-R-impressum
  - DE-R-impressum-register
  - …

6. Published as a site and as data

One build turns the whole graph into this static site: a page for every country, act, provision, quote and rule. Every page serves its own Turtle too, and the whole graph is on the downloads page in Turtle, N-Triples and JSON-LDJSON for Linking DataRDF written as JSON: the whole graph, readable by any JSON tool, with its links intact.. The site has no database: what you read is the graph itself, rendered.

In the example: the rule is Impressum: register and registration number, the provision is § 5 Abs. 1 DDG with its German text and English side by side, and the checklist shows the rule to a business that picks Germany as its country and answers yes to the other two questions.

Why a graph, and why Turtle

Law is a web of references: provisions implement directives, refine each other, define terms and set fines. A graph stores those links as data instead of prose, in the open standards of the web (RDF).

Ask it your own questions

Because the graph is RDF, it answers questions no page was built for, in SPARQL. This query asks which law, in each country, requires a business to name its register and registration number:

queries/register-entry.rq
# Which provisions require a business to name the register it is entered in, and its registration
# number (in Germany, the Handelsregister and the HRB number), in each jurisdiction.
PREFIX lgo:  <https://legalgraph.org/ontology#>
PREFIX lgv:  <https://legalgraph.org/vocab/>
PREFIX eli:  <http://data.europa.eu/eli/ontology#>

SELECT ?jurisdiction ?citation
WHERE {
    ?provision lgo:requiresDisclosureOf lgv:RegisterEntry ;
        lgo:citation ?citation ;
        eli:is_part_of/lgo:jurisdiction/lgo:isoCode ?jurisdiction .
}
ORDER BY ?jurisdiction ?citation

Today it finds 22 provisions in 14 jurisdictions. Some of them:

Run it in the repository with uv run legalgraph query register-entry, or load a download into any SPARQL store. The queries folder has more, such as where national law asks for more than the EU directive it implements.

How the graph is tested

make check runs the last four checks below and fails if any one of them fails, so a change that breaks the link to the law cannot pass unnoticed. The first needs the network and runs on its own.

make upstream
Downloads every text again and fails if the portal's words have changed. It needs the network, so it runs on its own.
sources verify
Strips our marks and compares with the original, byte for byte; a transcription must match it word for word.
sources extract --check
Regenerates the Turtle and fails if it differs from what is published.
validate
Parses every file, rejects undefined terms and dangling links, applies the 16 SHACL shapes, and requires English for every non-English text.
pytest
Over 100 tests, among them the example businesses, which must get exactly their rules: one more or one fewer fails.

Check it yourself

Everything on this page is in the repository on GitHub: the originals, the annotated texts, the Turtle, the rules, the shapes and the tests. Clone it, run make check, and you have verified the graph yourself. The Law texts table lists every original with its hash and the annotated file it was checked against. English is a reading aid — the original text is what the law says.