Deriving a denormalized schema
A specification that flattens a normalized model into a denormalized one also implies the
denormalized schema. SchemaMapper derives it from the source schema and the specification,
as linkml-map derive-schema does on the command line.
This uses the flattening example from the repository's tests/input/examples.
from pathlib import Path
from linkml_runtime.dumpers import yaml_dumper
from linkml_runtime.utils.schemaview import SchemaView
from linkml_map import load_specification
from linkml_map.inference.schema_mapper import SchemaMapper
EXAMPLE = Path.cwd().parent.parent / "tests/input/examples/flattening"
source = SchemaView(str(EXAMPLE / "source/normalized.yaml"))
spec = load_specification(EXAMPLE / "transform/denormalize.transform.yaml")
target_schema = SchemaMapper(source_schemaview=source).derive_schema(
specification=spec,
target_schema_id="denormalized-view",
target_schema_name="DenormalizedView",
)
derived = SchemaView(yaml_dumper.dumps(target_schema))
for class_name in derived.all_classes():
print(class_name)
print()
for slot_name in derived.all_slots():
print(slot_name)