Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
133 changes: 133 additions & 0 deletions src/dackar/knowledge_graph/KG_class_test.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "fdfa1e8f",
"metadata": {},
"outputs": [],
"source": [
"import sys, os\n",
"cwd = os.getcwd()\n",
"frameworkDir = os.path.abspath(os.path.join(cwd, os.pardir, os.pardir))\n",
"sys.path.append(frameworkDir)\n",
"\n",
"import pandas as pd\n",
"\n",
"from dackar.knowledge_graph.KGconstruction import KG"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "69114812",
"metadata": {},
"outputs": [],
"source": [
"cause_dict= {'A': ['alpha','beta','gamma'], \n",
" 'B': [1.,2.,3.]}\n",
"cause_df = pd.DataFrame(cause_dict)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fe9186d3",
"metadata": {},
"outputs": [],
"source": [
"config_file_path = '/Users/mandd/Library/Application Support/Neo4j Desktop/Application/relate-data/dbmss/dbms-666d9aa2-b0c5-4903-9f08-1cad30136945/conf/neo4j.conf'\n",
"uri = \"bolt://localhost:7687\"\n",
"pwd = \"123456789\"\n",
"user='neo4j'\n",
"\n",
"knowledgeGraph = KG(config_file_path, uri, pwd, user)\n",
"\n",
"knowledgeGraph.resetGraph()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e4f8adfe",
"metadata": {},
"outputs": [],
"source": [
"knowledgeGraph.importGraphSchema('condition_report','schemas/conditionReportSchema.toml')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12cd86d0",
"metadata": {},
"outputs": [],
"source": [
"nodeConstSchemaCause = {'cause': {'prop1': 'A', 'prop2': 'B'}}\n",
"constSchemaCause = {'nodes': nodeConstSchemaCause}\n",
"\n",
"knowledgeGraph.genericWorkflow(cause_df, constSchemaCause)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ff8376c",
"metadata": {},
"outputs": [],
"source": [
"conseq_dict = {'C': ['x','y','z'], \n",
" 'D': [1.1,1.2,1.3],\n",
" 'prop_rel': [2.1,2.2,2.3],\n",
" 'A': ['alpha','beta','gamma']} # link to cause\n",
"conseq_df = pd.DataFrame(conseq_dict)\n",
"\n",
"nodeConstSchemaConseq = {'consequence': {'ID_A': 'C', 'ID_B': 'D'}}\n",
"relConstSchemaConseq = [{'source': {'cause.prop1':'A'},\n",
" 'target': {'consequence.ID_A':'C'},\n",
" 'type' : 'causality',\n",
" 'properties': {'amplitude': 'prop_rel'}}] \n",
"\n",
"constSchemaConseq= {'nodes' : nodeConstSchemaConseq,\n",
" 'relations': relConstSchemaConseq}\n",
"\n",
"knowledgeGraph.genericWorkflow(conseq_df, constSchemaConseq)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "128e96b8",
"metadata": {},
"outputs": [],
"source": [
"node_properties=[{'name': 'date', 'type': 'string', 'optional': False},\n",
" {'name': 'ID', 'type': 'string', 'optional': False}]\n",
"\n",
"df = pd.DataFrame(node_properties)\n",
"df"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "dackar_libs",
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading