Skip to content

Commit 151dde7

Browse files
committed
edits
1 parent e524d90 commit 151dde7

File tree

3 files changed

+142
-11
lines changed

3 files changed

+142
-11
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "fdfa1e8f",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import sys, os\n",
11+
"cwd = os.getcwd()\n",
12+
"frameworkDir = os.path.abspath(os.path.join(cwd, os.pardir, os.pardir))\n",
13+
"sys.path.append(frameworkDir)\n",
14+
"\n",
15+
"import pandas as pd\n",
16+
"\n",
17+
"from dackar.knowledge_graph.KGconstruction import KG"
18+
]
19+
},
20+
{
21+
"cell_type": "code",
22+
"execution_count": null,
23+
"id": "69114812",
24+
"metadata": {},
25+
"outputs": [],
26+
"source": [
27+
"cause_dict= {'A': ['alpha','beta','gamma'], \n",
28+
" 'B': [1.,2.,3.]}\n",
29+
"cause_df = pd.DataFrame(cause_dict)"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"id": "fe9186d3",
36+
"metadata": {},
37+
"outputs": [],
38+
"source": [
39+
"config_file_path = '/Users/mandd/Library/Application Support/Neo4j Desktop/Application/relate-data/dbmss/dbms-666d9aa2-b0c5-4903-9f08-1cad30136945/conf/neo4j.conf'\n",
40+
"uri = \"bolt://localhost:7687\"\n",
41+
"pwd = \"123456789\"\n",
42+
"user='neo4j'\n",
43+
"\n",
44+
"knowledgeGraph = KG(config_file_path, uri, pwd, user)\n",
45+
"\n",
46+
"knowledgeGraph.resetGraph()"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": null,
52+
"id": "e4f8adfe",
53+
"metadata": {},
54+
"outputs": [],
55+
"source": [
56+
"knowledgeGraph.importGraphSchema('condition_report','schemas/conditionReportSchema.toml')"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"id": "12cd86d0",
63+
"metadata": {},
64+
"outputs": [],
65+
"source": [
66+
"nodeConstSchemaCause = {'cause': {'prop1': 'A', 'prop2': 'B'}}\n",
67+
"constSchemaCause = {'nodes': nodeConstSchemaCause}\n",
68+
"\n",
69+
"knowledgeGraph.genericWorkflow(cause_df, constSchemaCause)"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"id": "2ff8376c",
76+
"metadata": {},
77+
"outputs": [],
78+
"source": [
79+
"conseq_dict = {'C': ['x','y','z'], \n",
80+
" 'D': [1.1,1.2,1.3],\n",
81+
" 'prop_rel': [2.1,2.2,2.3],\n",
82+
" 'A': ['alpha','beta','gamma']} # link to cause\n",
83+
"conseq_df = pd.DataFrame(conseq_dict)\n",
84+
"\n",
85+
"nodeConstSchemaConseq = {'consequence': {'ID_A': 'C', 'ID_B': 'D'}}\n",
86+
"relConstSchemaConseq = [{'source': {'cause.prop1':'A'},\n",
87+
" 'target': {'consequence.ID_A':'C'},\n",
88+
" 'type' : 'causality',\n",
89+
" 'properties': {'amplitude': 'prop_rel'}}] \n",
90+
"\n",
91+
"constSchemaConseq= {'nodes' : nodeConstSchemaConseq,\n",
92+
" 'relations': relConstSchemaConseq}\n",
93+
"\n",
94+
"knowledgeGraph.genericWorkflow(conseq_df, constSchemaConseq)"
95+
]
96+
},
97+
{
98+
"cell_type": "code",
99+
"execution_count": null,
100+
"id": "128e96b8",
101+
"metadata": {},
102+
"outputs": [],
103+
"source": [
104+
"node_properties=[{'name': 'date', 'type': 'string', 'optional': False},\n",
105+
" {'name': 'ID', 'type': 'string', 'optional': False}]\n",
106+
"\n",
107+
"df = pd.DataFrame(node_properties)\n",
108+
"df"
109+
]
110+
}
111+
],
112+
"metadata": {
113+
"kernelspec": {
114+
"display_name": "dackar_libs",
115+
"language": "python",
116+
"name": "python3"
117+
},
118+
"language_info": {
119+
"codemirror_mode": {
120+
"name": "ipython",
121+
"version": 3
122+
},
123+
"file_extension": ".py",
124+
"mimetype": "text/x-python",
125+
"name": "python",
126+
"nbconvert_exporter": "python",
127+
"pygments_lexer": "ipython3",
128+
"version": "3.11.8"
129+
}
130+
},
131+
"nbformat": 4,
132+
"nbformat_minor": 5
133+
}

src/dackar/knowledge_graph/KGconstruction.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ def __init__(self, config_file_path, uri, pwd, user):
4646
"items": {"type": "object",
4747
"properties": {"name" : {"type": "string", "description": "Name of the node property"},
4848
"type" : {"type": "string", "description": "Type of the node property"},
49-
"optional": {"type": "boolean", "description": "Specifies if this property is required or not"}},
50-
"required":["name","type","optional"],
49+
"optional": {"type": "boolean", "description": "Specifies if this property is required or not"}
50+
},
51+
"required":["name","type","optional"]
5152
}
5253
}
5354
},
@@ -63,11 +64,13 @@ def __init__(self, config_file_path, uri, pwd, user):
6364
"items": {"type": "object",
6465
"properties": {"name" : {"type": "string", "description": "Name of the relation property"},
6566
"type" : {"type": "string", "description": "Type of the node property"},
66-
"optional": {"type": "boolean", "description": "Specifies if this property is required or not"}},
67-
"required":["name","type","optional"],
67+
"optional": {"type": "boolean", "description": "Specifies if this property is required or not"}
68+
},
69+
"required":["name","type","optional"]
6870
}
69-
}},
70-
"required":["relation_description","from_entity","to_entity"],
71+
}
72+
},
73+
"required":["relation_description","from_entity","to_entity"]
7174
}
7275
},
7376
"required":["title"]}

src/dackar/knowledge_graph/schemas/conditionReportSchema.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ node_description = """Represents a structured report documenting an observed abn
1212
node_properties = [{name = "date", type = "string", optional = false},
1313
{name = "ID", type = "string", optional = false}]
1414

15-
[node.work_order]
16-
description = """[]"""
17-
node_properties = [{name = "date", type = "string", optional = false},
18-
{name = "ID", type = "string", optional = false}]
19-
2015
# ====================
2116
# Relations
2217
# ====================

0 commit comments

Comments
 (0)