Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sierra-moxon committed Nov 18, 2024
2 parents 6d99cf8 + 6f049d1 commit 1b131d7
Show file tree
Hide file tree
Showing 20 changed files with 3,950 additions and 4,455 deletions.
2 changes: 1 addition & 1 deletion .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
identity and expression, level of experience, education, socioeconomic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

Expand Down
207 changes: 125 additions & 82 deletions docs/examples/MetamodelMapping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,51 @@
"cells": [
{
"cell_type": "markdown",
"id": "20a69830e031dd42",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"# LinkML Metamodel Mappings\n",
"\n",
"The primary use case of LinkML is to map *data* to *data*. However, because the LinkML metamodel is\n",
"expressed as a LinkML schema, it is possible to map to and from the metamodel itself.\n",
"\n",
"__NOTE__ this workflow is not yet fully matured, and is subject to change."
],
"metadata": {
"collapsed": false
},
"id": "20a69830e031dd42"
]
},
{
"cell_type": "markdown",
"id": "926150383baeb0f1",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"## Creation of ad-hoc metamodel\n",
"\n",
"Let's assume that we have data represented using models conforming to an ad-hoc metamodel with core constructs: `Schema`, `Table`, and `Column`. We can create a LinkML schema that represents this metamodel as follows:"
],
"metadata": {
"collapsed": false
},
"id": "926150383baeb0f1"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "569394bf0a0aa7c4",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-11T02:15:26.923272Z",
"start_time": "2024-04-11T02:15:26.737620Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -103,31 +120,37 @@
"\n",
"my_metamodel = sb.as_dict()\n",
"print(yaml.dump(sb.as_dict(), sort_keys=False))"
],
]
},
{
"cell_type": "markdown",
"id": "504e5e995a56d9d",
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-04-11T02:15:26.923272Z",
"start_time": "2024-04-11T02:15:26.737620Z"
"jupyter": {
"outputs_hidden": false
}
},
"id": "569394bf0a0aa7c4"
},
{
"cell_type": "markdown",
"source": [
"## Example schema conforming to ad-hoc metamodel\n",
"\n",
"Now we'll make an example schema that conforms to this metamodel; this will be a fairly boring schema with a single table `Person` with three columns: `id`, `name`, and `description`:"
],
"metadata": {
"collapsed": false
},
"id": "504e5e995a56d9d"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2412c7508be85763",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-11T02:15:26.927278Z",
"start_time": "2024-04-11T02:15:26.925061Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"my_schema = {\n",
Expand All @@ -153,31 +176,37 @@
" },\n",
" ]\n",
"}"
],
]
},
{
"cell_type": "markdown",
"id": "a97465ad75c14ab9",
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-04-11T02:15:26.927278Z",
"start_time": "2024-04-11T02:15:26.925061Z"
"jupyter": {
"outputs_hidden": false
}
},
"id": "2412c7508be85763"
},
{
"cell_type": "markdown",
"source": [
"## Mapping to LinkML metamodel\n",
"\n",
"Now we'll create mappings from the ad-hoc metamodel to the LinkML metamodel, where **Table** maps to a LinkML **ClassDefinition**, **Column** maps to a LinkML **SlotDefinition*."
],
"metadata": {
"collapsed": false
},
"id": "a97465ad75c14ab9"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "781147edebbfeb9c",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-11T02:15:26.930857Z",
"start_time": "2024-04-11T02:15:26.929165Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"metamap = {\n",
Expand Down Expand Up @@ -227,54 +256,63 @@
" },\n",
" }\n",
"}"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-04-11T02:15:26.930857Z",
"start_time": "2024-04-11T02:15:26.929165Z"
}
},
"id": "781147edebbfeb9c"
]
},
{
"cell_type": "code",
"execution_count": 4,
"outputs": [],
"source": [
"from linkml_map.session import Session\n",
"\n",
"session = Session()"
],
"id": "df33c4db991ce4b3",
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-04-11T02:15:27.366482Z",
"start_time": "2024-04-11T02:15:26.931843Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"id": "df33c4db991ce4b3"
"outputs": [],
"source": [
"from linkml_map.session import Session\n",
"\n",
"session = Session()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"outputs": [],
"source": [
"session.set_source_schema(my_metamodel)\n",
"session.set_object_transformer(metamap)"
],
"id": "e5edb3e9efa49ed1",
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-04-11T02:15:27.450810Z",
"start_time": "2024-04-11T02:15:27.369239Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"id": "e5edb3e9efa49ed1"
"outputs": [],
"source": [
"session.set_source_schema(my_metamodel)\n",
"session.set_object_transformer(metamap)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "5fcae9c463c7146b",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-11T02:15:27.464442Z",
"start_time": "2024-04-11T02:15:27.453655Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stderr",
Expand Down Expand Up @@ -309,7 +347,14 @@
},
{
"data": {
"text/plain": "{'name': 'my_schema',\n 'id': 'https://example.org/my_schema',\n 'classes': {'Person': {'attributes': {'id': {'identifier': True,\n 'range': 'integer'},\n 'name': {'identifier': None, 'range': 'string'},\n 'description': {'identifier': None, 'range': 'string'}}}}}"
"text/plain": [
"{'name': 'my_schema',\n",
" 'id': 'https://example.org/my_schema',\n",
" 'classes': {'Person': {'attributes': {'id': {'identifier': True,\n",
" 'range': 'integer'},\n",
" 'name': {'identifier': None, 'range': 'string'},\n",
" 'description': {'identifier': None, 'range': 'string'}}}}}"
]
},
"execution_count": 6,
"metadata": {},
Expand All @@ -318,18 +363,17 @@
],
"source": [
"session.transform(my_schema)"
],
]
},
{
"cell_type": "markdown",
"id": "917015b3f12eac2f",
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-04-11T02:15:27.464442Z",
"start_time": "2024-04-11T02:15:27.453655Z"
"jupyter": {
"outputs_hidden": false
}
},
"id": "5fcae9c463c7146b"
},
{
"cell_type": "markdown",
"source": [
"## Customizing the LinkML model\n",
"\n",
Expand All @@ -340,44 +384,43 @@
"- every element MUST have a definition\n",
"\n",
"**TODO**"
],
"metadata": {
"collapsed": false
},
"id": "917015b3f12eac2f"
]
},
{
"cell_type": "code",
"execution_count": 6,
"outputs": [],
"source": [],
"id": "87c714635c108ea8",
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-04-11T02:15:27.470074Z",
"start_time": "2024-04-11T02:15:27.466371Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"id": "87c714635c108ea8"
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 1b131d7

Please sign in to comment.