Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions docs/examples/denormalizing.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "cd2c8429-a0e7-4a95-a7ed-b1fd8a53b89d",
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"from linkml_runtime.dumpers import yaml_dumper\n",
"from linkml_runtime.utils.schemaview import SchemaView\n",
"\n",
"from linkml_map.inference.schema_mapper import SchemaMapper\n",
"from linkml_map.session import Session\n",
"from linkml_map.utils.loaders import load_specification\n",
"\n",
"REPO_ROOT = Path.cwd().parent.parent"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "121e9e1c-28c2-4fec-bb76-e078836d1f3e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MappingSet\n",
"Mapping\n",
"\n",
"mappings\n",
"subject_id\n",
"subject_name\n",
"object_id\n",
"object_name\n",
"predicate_id\n"
]
}
],
"source": [
"input_schema = REPO_ROOT / \"tests/input/examples/flattening/source/normalized.yaml\"\n",
"output_schema = REPO_ROOT / \"tests/input/examples/flattening/target/denormalized.yaml\"\n",
"transformation_specification_file = REPO_ROOT / \"tests/input/examples/flattening/transform/denormalize.transform.yaml\"\n",
"# Initialize Session and SchemaBuilder\n",
"session = Session()\n",
"\n",
"source_schema_view = SchemaView(input_schema)\n",
"target_schema_view = SchemaView(output_schema)\n",
"# Set the source schema in the session\n",
"session.set_source_schema(source_schema_view)\n",
"\n",
"tr_spec = load_specification(transformation_specification_file)\n",
"mapper = SchemaMapper()\n",
"mapper.source_schemaview = source_schema_view\n",
"\n",
"target_schema_obj = mapper.derive_schema(\n",
" specification=tr_spec,\n",
" target_schema_id=\"denormalized-view\",\n",
" target_schema_name=\"DenormalizedView\",\n",
")\n",
"\n",
"yaml_dumper.dump(target_schema_obj, str(\"denormalized_view.yaml\"))\n",
"\n",
"transformed_sv = SchemaView(\"denormalized_view.yaml\")\n",
"\n",
"for class_name in transformed_sv.all_classes():\n",
" print(class_name)\n",
"print()\n",
"for slot_name in transformed_sv.all_slots():\n",
" print(slot_name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc48f85d-bf7b-44fe-90e1-cd256191c06a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading