The script will build a TOML file with a hierarchical representation of the Destatis terms, which can be later extended with English labels and iterated over to yield terms.
65 lines
2 KiB
Python
65 lines
2 KiB
Python
"""Create a hierarchical TOML representation of Destatis data
|
|
|
|
We are operating on the following assumptions:
|
|
|
|
- Identifiers of Fächergruppe have two digits, Lehr-/Forschungsbereich
|
|
three, Fachgebiet four
|
|
- The input text file is ordered, so for each Fachgebiet we will have
|
|
parsed the Fächergruppe and Lehr-/Forschungsbereich before
|
|
|
|
We take the German labels from the Destatis document and insert empty
|
|
English labels, to be manually filled in later.
|
|
|
|
Using tomlkit lets us decide when to use dotted keys for readability.
|
|
|
|
"""
|
|
from pathlib import Path
|
|
|
|
from tomlkit import document, table, toml_file, key
|
|
|
|
|
|
group = None
|
|
field = None
|
|
area = None
|
|
|
|
group_id = None
|
|
field_id = None
|
|
|
|
doc = document()
|
|
|
|
|
|
with Path("derived/personal-stellenstatistik.txt").open() as fp:
|
|
for line in fp:
|
|
stripped = line.strip()
|
|
if len(stripped) > 0:
|
|
id, name = line.split(" ", maxsplit=1)
|
|
id = id.strip()
|
|
name = name.strip()
|
|
|
|
if len(id) == 2:
|
|
if field is not None and group is not None:
|
|
group.add(field_id, field)
|
|
doc.add(group_id, group)
|
|
field = None
|
|
group = table()
|
|
group_id = id
|
|
group.add(key(["prefLabel", "de"]), name)
|
|
group.add(key(["prefLabel", "en"]), "")
|
|
elif len(id) == 3:
|
|
if field is not None:
|
|
group.add(field_id, field)
|
|
field = table()
|
|
field_id = id
|
|
field.add(key(["prefLabel", "de"]), name)
|
|
field.add(key(["prefLabel", "en"]), "")
|
|
elif len(id) == 4:
|
|
area = table()
|
|
area.add(key(["prefLabel", "de"]), name)
|
|
area.add(key(["prefLabel", "en"]), "")
|
|
field.add(id, area)
|
|
|
|
group.add(field_id, field)
|
|
doc.add(group_id, group)
|
|
|
|
tf = toml_file.TOMLFile(Path("derived/personal-stellenstatistik.toml"))
|
|
tf.write(doc)
|