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
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.
- legalgraph/The repository
- sources/The official texts, byte for byte, one folder per law1
- de/ddg/One law: the Digitale-Dienste-Gesetz
- source.yamlWhere and when it was fetched, and its SHA-256Secure Hash Algorithm, 256 bitsA fingerprint of a file: any change, even of one character, gives a completely different value.1
- BJNR0950B0024.xmlThe file from gesetze-im-internet.de, unchanged1
- BJNR0950B0024.annotated.xmlThe same file with our lga: marks2
- schemas/law.xsdOur XML schema, for texts published only as HTMLHyperText Markup LanguageThe language of web pages. Where a portal publishes a law only as a web page, legalgraph keeps the page and transcribes the text. or PDFPortable Document FormatA format for fixed page layouts (ISO 32000). Laws published only as PDF are kept as published and transcribed.2
- data/The graph, in Turtle
- extracted/Generated from the annotated texts, never edited4
- translations/en/English for every quote in another language3
- rules/Rules for businesses, written by hand5
- cases/Court and authority decisions, written by hand5
- ontology/Classes, vocabularies and the SHACL shapes
- scenarios/Example businesses and the rules they must get
- queries/Example SPARQL queries
- src/legalgraph/The code: fetch, verify, extract, validate, build
- tests/The tests
- site/This website6
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:
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.xml2. 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:
- Official XML (EU Formex, gesetze-im-internet.de, legislation.gov.uk, Fedlex, the US Code): annotations are added inside the official file's own tags. Strip them again and the file is byte-identical to the original — proof that nothing was edited, not just asserted.
- Authored XML (portals with only HTML or PDF — the Rada, EDPBEuropean Data Protection BoardThe EU body of the national data protection authorities; its guidelines say how they read the GDPR. and DSKGerman Data Protection ConferenceGerman: DatenschutzkonferenzThe joint body of Germany's federal and state data protection authorities; its guidance shows how they apply the law. guidance, much of US and member-state law): the text is transcribed into a small readable schema.
sources verifyvalidates the schema and requires every paragraph to occur word for word in the saved original, list item for list item — a transcription cannot silently drift from what was published.
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.
<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:
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:
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:
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:
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).
- Questions across laws and countries. One SPARQL query reaches every provision in every jurisdiction, as the example below shows.
- Every statement has an address. Each entry is a URLUniform Resource LocatorA web address. Every entry in legalgraph has one, which a browser opens as a page and a program can fetch as data., such as
legalgraph.org/id/DE-DDG-s5-1, that people can cite and programs can fetch. - Shared vocabularies. Laws are described with ELI, the European Legislation Identifier ontology that EUR-LexThe EU's official portal for its lawThe official website for EU law: the Official Journal, legislation, case law and their consolidated versions. and many national gazettes use; terms with SKOS; metadata with Dublin Core. Court decisions carry their ECLIEuropean Case Law IdentifierA uniform identifier for court decisions in Europe, such as ECLI:EU:C:2016:612: country, court, year and number. where the court publishes one, and countries link to the EU Publications Office's country list. Tools that know these standards understand the graph without learning ours.
- It connects with other graphs. RDF from different sources merges as it is: load legalgraph next to EUR-Lex's own data, or your company's, and query across them.
- Rules for the data, checked by a program. SHACL, a W3C standard, states what every entry must have, and validation checks the whole graph against it.
- Turtle is text. People read it, Git shows every change line by line, and reviewers check a correction as they would code. It converts without loss to N-Triples and JSON-LD.
- It grows without migrations. A new country or a new kind of duty adds statements; there is no database schema to change.
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:
# 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 ?citationToday it finds 22 provisions in 14 jurisdictions. Some of them:
| Jurisdiction | Provision |
|---|---|
| AT | § 5 Abs. 1 ECGAustrian E-Commerce ActGerman: E-Commerce-GesetzAustria's law implementing the e-Commerce Directive; its § 5 sets the information a website must give about its provider. |
| DE | § 5 Abs. 1 DDG |
| EU | Art. 5(1) Directive 2000/31/EC |
| FR | Article 19, alinéa 1, LCENFrench Law on Confidence in the Digital EconomyFrench: Loi pour la confiance dans l'économie numériqueThe French law of 2004 behind the mentions légales: who publishes a website, and what an online seller must disclose. |
| GB | reg. 6(1) Electronic Commerce Regulations 2002 |
| NL | Artikel 3:15d lid 1 BW |
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.