Skip to content

Commit 8467bbb

Browse files
committed
initial devs and schemas
1 parent 93b751c commit 8467bbb

File tree

6 files changed

+268
-0
lines changed

6 files changed

+268
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Copyright 2024, Battelle Energy Alliance, LLC ALL RIGHTS RESERVED
2+
3+
import os, sys
4+
import re
5+
6+
cwd = os.getcwd()
7+
frameworkDir = os.path.abspath(os.path.join(cwd, os.pardir, os.pardir, 'src'))
8+
9+
# Internal Modules #
10+
from dackar.knowledge_graph.py2neo import Py2Neo
11+
from dackar.knowledge_graph.graph_utils import set_neo4j_import_folder
12+
from dackar.utils.mbse.customMBSEparser import customMBSEobject
13+
14+
# External Modules #
15+
import pandas as pd
16+
import os, sys
17+
18+
class KG:
19+
def __init__(self, config_file_path, import_folder_path, uri, pwd, processedDataFolder):
20+
# Change import folder to user specific location
21+
set_neo4j_import_folder(config_file_path, import_folder_path)
22+
23+
self.processedDataFolder = processedDataFolder
24+
25+
# Create python to neo4j driver
26+
self.py2neo = Py2Neo(uri=uri, user='neo4j', pwd=pwd)
27+
28+
self.graphSchemas = []
29+
30+
def graphCheck(self):
31+
pass
32+
33+
def mbseWorkflow(self, name, type, nodesFile, edgesFile):
34+
if type =='customMBSE':
35+
mbseModel = customMBSEobject(nodesFile,
36+
edgesFile,
37+
path=self.processedDataFolder)
38+
39+
mbseModel.printEquipmentID()
40+
mbseModel.plot(name)
41+
42+
elif type =='LML':
43+
pass
44+
45+
def anomalyWorkflow(self, filename, constructionSchema):
46+
graphSchemas = BBD
47+
48+
# Congjian: how to add relations across schemas????
49+
# use Json/toml for validation
50+
51+
nodeConstructionSchema = {'nodeLabel1': {'property1': 'node.colA', 'property2': 'node.colB'},
52+
'nodeLabel2': {'property1': 'node.colC'}}
53+
54+
edgeConstructionSchema = [{'source': ('nodeLabel1.property1','col1'),
55+
'target': ('nodeLabel2.property1','col2'),
56+
'type': 'edgeType',
57+
'properties': {'property1': 'colAlpha', 'property2': 'colBeta'}}]
58+
59+
constructionSchema = {'nodes': nodeConstructionSchema,
60+
'edges': edgeConstructionSchema}
61+
62+
def kgConstructionWorkflow(self, dataframe, graphSchemas, constructionSchema):
63+
#TODO: Check constructionSchema against graphSchemas
64+
65+
for node in constructionSchema['nodes'].keys():
66+
map = {value: key for key, value in constructionSchema['nodes'][node].items()}
67+
tempDataframe = dataframe.rename(columns=map)
68+
self.py2neo.load_dataframe_for_nodes(tempDataframe, node, map.keys())
69+
70+
# Incomplete
71+
for edge in constructionSchema['edges']:
72+
self.py2neo.load_dataframe_for_relations(dataframe,
73+
l1='sourceLabel', p1='sourceNodeId',
74+
l2='targetLabel', p2='targetNodeId',
75+
lr='relationshipType',
76+
pr=None)
77+
78+
'''
79+
# Load nodes
80+
label = 'anomaly'
81+
self.py2neo.load_csv_for_nodes(file_path, label, nodeAttributes)
82+
83+
# Load edges
84+
l1='anomaly'
85+
p1={'ID':'ID'}
86+
l2='monitored_var'
87+
p2 ={'ID':'monitored_variable'}
88+
lr = 'detected_by'
89+
pr = None
90+
self.py2neo.load_csv_for_relations(file_path, l1, p1, l2, p2, lr, pr)
91+
'''
92+
93+
'''file_path = 'processed_data/mbse_model_nodes_kg.csv'
94+
label = 'MBSE'
95+
attribute = {'ID':'ID', 'type':'type'}
96+
self.py2neo.load_csv_for_nodes(file_path, label, attribute)
97+
98+
file_path = 'processed_data/mbse_model_edges_kg.csv'
99+
l1='MBSE'
100+
p1={'ID':'sourceNodeId'}
101+
l2='MBSE'
102+
p2 ={'ID':'targetNodeId'}
103+
lr = 'MBSE_link'
104+
pr = {'prop':'type'}
105+
self.py2neo.load_csv_for_relations(file_path, l1, p1, l2, p2, lr, pr)'''
106+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
title = "Condition Report Graph Schema"
2+
version = "1.0"
3+
4+
# ====================
5+
# Node Entities
6+
# ====================
7+
8+
[entities.condition_report]
9+
description = "Represents a structured report documenting an observed abnormal event or condition within
10+
a plant or operational environment. This entity captures descriptive information provided
11+
by plant staff, including the nature, context, and potential implications of the anomaly."
12+
properties = [
13+
{ name = "date", type = "string"},
14+
{ name = "ID", type = "string"},
15+
]
16+
17+
# ====================
18+
# Relationships
19+
# ====================
20+
21+
[relationships.refers]
22+
description = "Indicates that a generalized nuclear-relevant entity such as materials, chemical elements
23+
and compounds, chemical reactions, failure modes, degradation mechanisms, and components
24+
across electrical, hydraulic, and mechanical systems has been explicitly referenced within
25+
a condition report"
26+
from_entity = "condition_report"
27+
to_entity = "nuclear_entity"
28+
29+
30+
[relationships.mentions]
31+
description = "Indicates that a specific system, equipment, or component contained in the provided MBSE model
32+
has been explicitly referenced within a condition report, establishing a contextual link between
33+
the reported abnormal event or condition and the physical or functional asset involved."
34+
from_entity = "condition_report"
35+
to_entity = "mbse_entity"
36+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
title = "Custom MBSE Model Graph Schema"
2+
version = "1.0"
3+
4+
# ====================
5+
# Node Entities
6+
# ====================
7+
8+
[entities.mbse_entity]
9+
description = "Represents a specific MBSE component, equipment, or system"
10+
properties = [
11+
{ name = "label", type = "string"},
12+
{ name = "ID", type = "string", optional = true },
13+
]
14+
15+
# ====================
16+
# Relationships
17+
# ====================
18+
19+
[relationships.link]
20+
description = "Represents a functional relationship between two entities—such as components equipment
21+
or systems—where one entity influences, supports, or enables the operation, performance or
22+
behavior of the other within a defined operational or engineering context."
23+
from_entity = "mbse_entity"
24+
to_entity = "mbse_entity"
25+
26+
27+
[relationships.composition]
28+
description = "Denotes a hierarchical or structural relationship in which one entity—such as a component,
29+
equipment, or system—is a constituent part of another, indicating that the entities are
30+
physically or logically assembled together to form a larger, integrated whole.
31+
This link captures part-whole dependencies essential for understanding system architecture,
32+
configuration, and functional decomposition."
33+
from_entity = "mbse_entity"
34+
to_entity = "mbse_entity"
35+
36+
37+
[relationships.support]
38+
description = "Indicates a non-hierarchical relationship in which one entity—such as a component, equipment,
39+
or system—provides auxiliary functionality, infrastructure, or services that enable, enhance,
40+
or maintain the operation of another entity. This link captures dependencies where the supporting
41+
entity is not a direct part of the other, but is essential for its sustained performance, reliability,
42+
or availability within a broader system context."
43+
from_entity = "mbse_entity"
44+
to_entity = "mbse_entity"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
title = "Custom MBSE Model Graph Schema"
2+
version = "1.0"
3+
4+
# ====================
5+
# Node Entities
6+
# ====================
7+
8+
[entities.monitoring_variable]
9+
description = "Represents a measurable physical variable that is continuously or periodically recorded by monitoring sensors from
10+
a specific component, equipment,
11+
or system. This entity captures dynamic operational data that reflects the real-time or historical
12+
state of the asset, enabling monitoring, diagnostics, performance analysis, and integration with
13+
predictive models or digital twins within engineering and plant operations contexts."
14+
properties = [
15+
{ name = "label", type = "string", optional = true },
16+
{ name = "ID", type = "string"},
17+
]
18+
19+
# ====================
20+
# Relationships
21+
# ====================
22+
23+
[relationships.monitors]
24+
description = "Defines a semantic relationship in which a monitoring variable is associated with the performance
25+
monitoring of a specific component, equipment, or system. This relation captures the functional
26+
linkage between sensor-derived data and the operational behavior of
27+
the asset, enabling performance assessment, anomaly detection, and predictive maintenance.
28+
It supports traceability between real-time or historical measurements and the physical or logical entities
29+
they characterize within the system model."
30+
from_entity = "monitoring_variable"
31+
to_entity = "mbse_entity"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
title = "Nuclear Entity Graph Schema"
2+
version = "1.0"
3+
4+
# ====================
5+
# Node Entities
6+
# ====================
7+
8+
[entities.nuclear_entity]
9+
description = "Represents a generalized nuclear-relevant entity that may be referenced in unstructured
10+
text authored by plant personnel, encompassing a broad spectrum of technical and
11+
operational subjects. These include materials, chemical elements and compounds, chemical
12+
reactions, failure modes, degradation mechanisms, and components across electrical,
13+
hydraulic, and mechanical systems."
14+
properties = [
15+
{ name = "class", type = "string"},
16+
]
17+
18+
19+
20+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
title = "Custom MBSE Model Graph Schema"
2+
version = "1.0"
3+
4+
# ====================
5+
# Node Entities
6+
# ====================
7+
8+
[entities.anomaly]
9+
description = " Represents a specific occurrence of an anomaly (such as threshold
10+
violations, signal deviations, or unexpected patterns) associated
11+
with a particular component, equipment, or system that have been
12+
detected by monitoring sensors coupled with an anomaly detection
13+
algorithm. "
14+
15+
properties = [
16+
{ name = "t_initial", type = "datetime"},
17+
{ name = "t_final", type = "datetime", optional = true },
18+
]
19+
20+
# ====================
21+
# Relationships
22+
# ====================
23+
24+
[relationships.detected_by]
25+
description = " Defines a semantic relationship indicating that a detected anomaly
26+
(such as a deviation from expected operational behavior) was identified
27+
through the observation or analysis of a specific monitoring variable.
28+
This link establishes traceability between the anomaly instance and the
29+
physical variable that triggered its detection, "
30+
from_entity = "anomaly"
31+
to_entity = "monitoring_variable"

0 commit comments

Comments
 (0)