-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from chinchien-lin/main
updated tut 3
- Loading branch information
Showing
2 changed files
with
232 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
232 changes: 232 additions & 0 deletions
232
..._3_add_sparc_tools_to_knowledge_graph/tutorial_3_add_sparc_tools_to_knowledge_graph.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "58dcd0c7", | ||
"metadata": {}, | ||
"source": [ | ||
"# Tutorial 3: Adding tools created from existing SPARC datasets to the knowledge graph\n", | ||
"\n", | ||
"This tutorial demonstrates how tools and models stored in SDS from Tutorial 1 can be added to the knowledge graph created in Tutorial 2. \n", | ||
"\n", | ||
"** data is sourced from https://sparc.science/datasets/262?type=dataset" | ||
] | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [ | ||
"### Prerequisites\n", | ||
"Please see Tutorial 1 for how to add tools and models to a SDS dataset; and Tutorial 2 for creating knowledge graphs." | ||
], | ||
"id": "b873792b2a2703a5" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"source": [ | ||
"# Requirements\n", | ||
"!pip install -U sparc_assemble\n", | ||
"# !pip install -U sparc_flow\n", | ||
"# !pip install -U sparc_me\n", | ||
"from sparc_assemble.core.kg import KG" | ||
], | ||
"id": "28a4e66147375179", | ||
"outputs": [], | ||
"execution_count": null | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [ | ||
"### Step 1: Initialise knowledge graph" | ||
], | ||
"id": "6c3c75e76db405fa" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [ | ||
"We will initialise the knowledge graph, KG, from a default ontology, \"EDAM\"." | ||
], | ||
"id": "538d81f6db0d35e4" | ||
}, | ||
{ | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2024-08-13T03:36:12.450189500Z", | ||
"start_time": "2024-08-13T03:36:12.040131200Z" | ||
} | ||
}, | ||
"cell_type": "code", | ||
"source": [ | ||
"kg = KG()" | ||
], | ||
"id": "c535a0124b0aec22", | ||
"outputs": [], | ||
"execution_count": 2 | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [ | ||
"### Step 2: Add tools from SPARC dataset to knowledge graphs" | ||
], | ||
"id": "42742867538d19f8" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Navigate to a tool dataset generated from Tutorial 1, use this as the input for adding tools to knowledge graphs." | ||
], | ||
"id": "30e64b90fb4ea46b" | ||
}, | ||
{ | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2024-08-13T03:37:17.831374500Z", | ||
"start_time": "2024-08-13T03:37:17.809377Z" | ||
} | ||
}, | ||
"cell_type": "code", | ||
"source": [ | ||
"tools_sds = 'resources/tools_dataset'\n", | ||
"kg.add_tools(tool_library=tools_sds)" | ||
], | ||
"id": "9189e7be765b269d", | ||
"outputs": [], | ||
"execution_count": 4 | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [], | ||
"id": "fcfdb6979681ca59" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [ | ||
"### Step 3: Add models from SPARC dataset to knowledge graphs" | ||
], | ||
"id": "5af9176bc0ebb324" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Recall Tutorial 1 where we downloaded a model dataset. Here, we use the simulation.json file from that dataset to add this model to the knowledge graph." | ||
], | ||
"id": "5ee56629083aeaaa" | ||
}, | ||
{ | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2024-08-13T03:37:24.701925200Z", | ||
"start_time": "2024-08-13T03:37:24.671927700Z" | ||
} | ||
}, | ||
"cell_type": "code", | ||
"source": [ | ||
"model_file = 'resources/models/simulation.json'\n", | ||
"kg.add_sparc_model(model_path=model_file)" | ||
], | ||
"id": "9510b3f174385b3a", | ||
"outputs": [], | ||
"execution_count": 5 | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [ | ||
"### Step 4: List all tools and models in knowledge graph" | ||
], | ||
"id": "79034b2f8426c802" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Show what models and tools does this knowledge graph keep a record of." | ||
], | ||
"id": "5b0b590a67707091" | ||
}, | ||
{ | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2024-08-13T03:37:27.496585600Z", | ||
"start_time": "2024-08-13T03:37:27.341588800Z" | ||
} | ||
}, | ||
"cell_type": "code", | ||
"source": [ | ||
"kg.list()" | ||
], | ||
"id": "3bb1118ff16ac87c", | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\t 1- vsl.Stimulation level,ssl.Stimulation level,sm.Simulation mode -> HumanSAN_Fabbri_Fantini_Wilders_Severi_2017 -> vm.Membrane/V, time.environment/time\n", | ||
"\t 2- example_data -> extract_mode -> sm.Simulation mode\n" | ||
] | ||
} | ||
], | ||
"execution_count": 6 | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [ | ||
"### Step 5: Save knowledge graph" | ||
], | ||
"id": "fc3c96d6f62bfb27" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Now we save the knowledge graph for future use." | ||
], | ||
"id": "f7ad7ef936569d38" | ||
}, | ||
{ | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2024-08-13T03:37:37.413164Z", | ||
"start_time": "2024-08-13T03:37:37.242124200Z" | ||
} | ||
}, | ||
"cell_type": "code", | ||
"source": [ | ||
"kg.save(save_path=\"resources/kg_sparc_model.owl\")" | ||
], | ||
"id": "aa02d8b054488071", | ||
"outputs": [], | ||
"execution_count": 7 | ||
} | ||
], | ||
"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.9.16" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |