Skip to content

Commit

Permalink
adding denormalize example notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
sierra-moxon committed Nov 18, 2024
1 parent 1b131d7 commit 6e4fde2
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions docs/examples/denormalizing.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"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.formatutils import camelcase, underscore\n",
"from linkml_runtime.utils.schemaview import SchemaView\n",
"from pytest import fixture\n",
"\n",
"from linkml_map.datamodel.transformer_model import (\n",
" ClassDerivation,\n",
" CopyDirective,\n",
" SlotDerivation,\n",
" TransformationSpecification,\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
}

0 comments on commit 6e4fde2

Please sign in to comment.