Skip to content

Metamodel

The metamodel says what the official DDI models hold. It is one YAML file per flavor, in src/ddigraph/mm/model/. scripts/build_metamodel.py writes the files from the bundled XSDs. For DDI-CDI, it also reads the OWL ontology.

The rest of ddigraph reads these files, not the XSDs. The code generator turns them into the tables in src/ddigraph/schema/_generated/, and the coverage audit (scripts/xsd_coverage.py) counts what each frontend reads against them. The mapping spec (src/ddigraph/mm/overlay/*.toml) then says how each class becomes a node of the graph.

The files

Flavor Standard Version Classes Enums Identifiable classes Size
codebook DDI-Codebook 2.6 195 67 83 191 KB
lifecycle DDI-Lifecycle 3.3 517 29 189 752 KB
cdi DDI-CDI 1.0 211 16 160 365 KB
lifecycle4 (experimental) DDI-Lifecycle 4.0-pr 485 41 207 1093 KB
cdi11 (experimental) DDI-CDI 1.1beta 208 16 156 349 KB

An identifiable class is one whose objects have an identity that ddigraph reads:

  • a DDI-Lifecycle maintainable, versionable or identifiable;
  • a Codebook type that carries the GLOBALS attributes itself or through the type it extends (kind: element);
  • a DDI-CDI class with an identifier, its own or one it inherits.

The lifecycle4 and cdi11 models follow DDI-Lifecycle 4.0 and DDI-CDI 1.1. Neither standard is final, so these two models may change in any release.

The LinkML subset

The files use a small part of LinkML 1.x, so LinkML's own tools can read them:

  • A class has is_a, abstract, tree_root, description, class_uri, attributes and annotations.
  • An attribute has range, required, multivalued, description and annotations.
  • An enum has permissible_values.

A class is an XSD complex type, and is_a is its base type. A DDI-CDI type drops its XsdType suffix, so it has the name of its OWL class. The attributes are the type's own child elements and XML attributes. A range is a class, an enum or a LinkML type. One more class, Document, is the tree root. Its attributes are the global elements, since any of them may be the root of a document.

What ddigraph adds

ddigraph writes its own facts as annotations, as text. On a class:

Annotation What it says
element The global elements of this type, split by spaces
namespace The target namespace of the file that declares the type
kind maintainable, versionable or identifiable for DDI-Lifecycle; entity for a DDI-CDI class of the ontology; element for a Codebook type with the GLOBALS attributes
derivation restriction when the type restricts its base type

On an attribute:

Annotation What it says
xml element or attribute
global "true" when the child is a global element, so members of its substitution group may stand in for it
reference "true" when the slot points to another object

An attribute of Document also gives the element's namespace, says whether it is abstract, and names the head of its substitution group (substitutes). The docstring of src/ddigraph/mm/model.py gives every rule.

The model also records what the Rust engine's validating automaton needs, as more annotations: each type's content model (content, mixed, simple), the attributes a restriction prohibits and the attribute wildcard, and the exact XSD type of each slot (type). scripts/generate_rust_tables.py compiles them into the engine's tables, so the XSDs are still read in one place only. The docstring of scripts/build_metamodel.py gives the encoding. See Validating in the same pass.

Rebuild and check

Do not edit the files by hand. After a change to the bundled XSDs, rebuild the model, then the tables, then this page:

make schemas
python scripts/generate_metamodel_docs.py

These checks run in CI:

python scripts/build_metamodel.py --check
python scripts/generate_schema_definitions.py --check
python scripts/generate_metamodel_docs.py --check

The first fails when a model file is out of date. The second fails when the tables came from other model files. The third fails when the table above no longer matches the files.

LinkML can check the files too. make check-metamodel runs linkml-lint, gen-yaml, gen-shacl and gen-owl on each file, through uvx and LinkML 1.12.1. It needs uv and the network, so it is not a CI step. See Contributing for when to run it.