Demos: one question, every backend¶
The demo/ folder has one script per backend. Each script asks the same
question of the course's sample Labour Force Survey: which codes and
categories does the variable ILOSTAT (labour force status) have?
The survey comes in three files, one per DDI flavor, in tests/fixtures/.
Each flavor keeps a variable's codes its own way, so each script has one
query per flavor. The answer is the same in all 18 cases:
1 Employed
2 Unemployed
3 Not in the labour force
| Flavor | File | Path from the variable to its codes |
|---|---|---|
| DDI-Codebook | lfs_codebook.xml |
Variable -USES_CATEGORY-> Category. The code is on the category. |
| DDI-Lifecycle | lfs_lifecycle.xml |
Variable -USES_CODELIST-> CodeList -CONTAINS-> Code -HAS_CATEGORY-> Category. The value is on the code. |
| DDI-CDI | lfs_cdi.xml |
InstanceVariable -TAKES_SUBSTANTIVE_VALUES_FROM-> ValueDomain -TAKES_VALUES_FROM-> CodeList -HAS_CODE-> Code. The code DENOTES its category and USES a notation, which holds the value. |
Run each script from the root of a clone, since it reads the files in
tests/fixtures/. Add --flavor codebook, lifecycle or cdi for one
file, and --variable SEX for another variable. Each picture below
opens full size when you click it.
NetworkX¶
No server is needed. The script walks the edges of the graph in memory.
uv run --extra networkx python demo/backend_networkx.py
The pictures draw the same path as a tree: the variable at the top, its codes and categories below it.
pandas¶
No server is needed. Each edge on the path is one merge on the relationships table.
uv run --extra pandas python demo/backend_pandas.py
RDF and SPARQL¶
No server is needed: the graph is an rdflib graph in memory. A category is
a skos:Concept with a skos:prefLabel in all three flavors.
uv run --extra rdf python demo/backend_rdf.py
PostgreSQL and DuckDB¶
In ddigraph's tables, each edge is a join on ddigraph_relationships and
each property a join on ddigraph_properties. --duckdb needs no server.
PostgreSQL needs one; never point the script at a database you care
about, since it replaces its three demo datasets.
uv run --extra duckdb python demo/backend_postgresql.py --duckdb
uv run --extra postgres python demo/backend_postgresql.py --postgres postgresql://postgres:postgres@localhost:5432/postgres
Neo4j¶
The script loads each file as its own dataset (demo-lfs-codebook,
demo-lfs-lifecycle, demo-lfs-cdi), then runs one Cypher query per
flavor. It needs Neo4j 5 and the settings in demo/demo.md. Never point it
at a database you care about.
uv run python demo/backend_neo4j.py
The pictures are from Neo4j Browser. They show the path each query follows, and the chips on the right are the legend.
Gremlin¶
The script writes each file to a Gremlin server as its own dataset, then
runs one traversal per flavor. A node's label property is ddi_label in
Gremlin, since some servers keep the name label for themselves.
uv run --extra gremlin python demo/backend_gremlin.py
Gremlin Server has no viewer of its own. These pictures are from the open-source gremlin-visualizer, which draws the same path in colours of its own. Its physics is turned off, and each node sits where it is in the NetworkX pictures. You could do the same by dragging the nodes.
Remaking the pictures¶
scripts/docs_images.py --set demos takes all 18 pictures again from the
running servers. The course's pictures come from the same script.

















