Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
446 changes: 446 additions & 0 deletions src/dackar/knowledge_graph/KG_class_test.ipynb

Large diffs are not rendered by default.

454 changes: 454 additions & 0 deletions src/dackar/knowledge_graph/KGconstruction.py

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions src/dackar/knowledge_graph/py2neo.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ def _create_relation(tx, l1, p1, l2, p2, lr, pr):
lr (str): relationship label
pr (dict, optional): attributes for relationship. Defaults to None.
"""
# Keep the MERGE parts, check node existance prior _create_relation
if pr is not None:
query = f"""
MERGE (l1:{l1} {{ {', '.join([f'{k}:"{v}"' for k, v in p1.items()])} }})
MERGE (l2:{l2} {{ {', '.join([f'{k}:"{v}"' for k, v in p2.items()])} }})
MATCH (l1:{l1} {{ {', '.join([f'{k}:"{v}"' for k, v in p1.items()])} }})
MATCH (l2:{l2} {{ {', '.join([f'{k}:"{v}"' for k, v in p2.items()])} }})
MERGE (l1)-[r:{lr} {{ {', '.join([f'{k}: ${k}' for k in pr.keys()])} }} ]->(l2)
"""
tx.run(query, **pr)
else:
query = f"""
MERGE (l1:{l1} {{ {', '.join([f'{k}:"{v}"' for k, v in p1.items()])} }})
MERGE (l2:{l2} {{ {', '.join([f'{k}:"{v}"' for k, v in p2.items()])} }})
MATCH (l1:{l1} {{ {', '.join([f'{k}:"{v}"' for k, v in p1.items()])} }})
MATCH (l2:{l2} {{ {', '.join([f'{k}:"{v}"' for k, v in p2.items()])} }})
MERGE (l1)-[r:{lr}]->(l2)
"""
# print(query)
tx.run(query)

def find_nodes(self, label, properties=None):
Expand Down Expand Up @@ -278,7 +278,7 @@ def load_dataframe_for_nodes(self, df, labels, properties):
"""
assert set(properties).issubset(set(df.columns))
for _, row in df.iterrows():
self.create_node(labels, row.to_dict())
self.create_node(labels, row[properties].to_dict())

# Load csv function to create relations
def load_dataframe_for_relations(self, df, l1='sourceLabel', p1='sourceNodeId', l2='targetLabel', p2='targetNodeId', lr='relationshipType', pr=None):
Expand All @@ -297,17 +297,19 @@ def load_dataframe_for_relations(self, df, l1='sourceLabel', p1='sourceNodeId',
# for nodes. Future development need to be performed.
# label (l1/l2), properties (p1/p2), and relation label (lr), relation properties (pr)
valid = []

valid.extend([l1, l2, lr, p1, p2])
if pr is not None:
valid.extend(pr)

assert set(valid).issubset(set(df.columns))

with self.__driver.session() as session:
for _, row in df.iterrows():
l1_ = row[l1]
p1_ = {'nodeId': row[p1]}
p1_ = {p1: row[p1]}
l2_ = row[l2]
p2_ = {'nodeId': row[p2]}
p2_ = {p2: row[p2]}
lr_ = row[lr]
if pr is not None:
pr_ = row[pr].to_dict()
Expand Down
35 changes: 35 additions & 0 deletions src/dackar/knowledge_graph/schemas/conditionReportSchema.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
title = "Condition Report Graph Schema"
version = 1.0

# ====================
# Node
# ====================

[node.condition_report]
node_description = """Represents a structured report documenting an observed abnormal event or condition within
a plant or operational environment. This entity captures descriptive information provided
by plant staff, including the nature, context, and potential implications of the anomaly."""
node_properties = [{name = "date", type = "str", optional = false},
{name = "ID", type = "str", optional = false}]

# ====================
# Relations
# ====================

[relation.refers]
relation_description = """Indicates that a generalized nuclear-relevant entity such as materials, chemical elements
and compounds, chemical reactions, failure modes, degradation mechanisms, and components
across electrical, hydraulic, and mechanical systems has been explicitly referenced within
a condition report"""
from_entity = "condition_report"
to_entity = "nuclear_entity"
relation_properties = [{name = "date", type = "string", optional = false}]


[relation.mentions]
relation_description = """Indicates that a specific system, equipment, or component contained in the provided MBSE model
has been explicitly referenced within a condition report, establishing a contextual link between
the reported abnormal event or condition and the physical or functional asset involved."""
from_entity = "condition_report"
to_entity = "mbse_entity"

44 changes: 44 additions & 0 deletions src/dackar/knowledge_graph/schemas/customMbseSchema.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
title = "Custom MBSE Model Graph Schema"
version = "1.0"

# ====================
# Node Entities
# ====================

[entities.mbse_entity]
description = "Represents a specific MBSE component, equipment, or system"
properties = [
{ name = "label", type = "string"},
{ name = "ID", type = "string", optional = true},
]

# ====================
# Relationships
# ====================

[relationships.link]
description = "Represents a functional relationship between two entities—such as components equipment
or systems—where one entity influences, supports, or enables the operation, performance or
behavior of the other within a defined operational or engineering context."
from_entity = "mbse_entity"
to_entity = "mbse_entity"


[relationships.composition]
description = "Denotes a hierarchical or structural relationship in which one entity—such as a component,
equipment, or system—is a constituent part of another, indicating that the entities are
physically or logically assembled together to form a larger, integrated whole.
This link captures part-whole dependencies essential for understanding system architecture,
configuration, and functional decomposition."
from_entity = "mbse_entity"
to_entity = "mbse_entity"


[relationships.support]
description = "Indicates a non-hierarchical relationship in which one entity—such as a component, equipment,
or system—provides auxiliary functionality, infrastructure, or services that enable, enhance,
or maintain the operation of another entity. This link captures dependencies where the supporting
entity is not a direct part of the other, but is essential for its sustained performance, reliability,
or availability within a broader system context."
from_entity = "mbse_entity"
to_entity = "mbse_entity"
31 changes: 31 additions & 0 deletions src/dackar/knowledge_graph/schemas/monitoringSystemSchema.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
title = "Custom MBSE Model Graph Schema"
version = "1.0"

# ====================
# Node Entities
# ====================

[entities.monitoring_variable]
description = "Represents a measurable physical variable that is continuously or periodically recorded by monitoring
sensors from a specific component, equipment, or system. This entity captures dynamic operational
data that reflects the real-time or historical state of the asset, enabling monitoring, diagnostics,
performance analysis, and integration with predictive models or digital twins within engineering and
plant operations contexts."
properties = [
{ name = "label", type = "string", optional = true },
{ name = "ID", type = "string"},
]

# ====================
# Relationships
# ====================

[relationships.monitors]
description = "Defines a semantic relationship in which a monitoring variable is associated with the performance
monitoring of a specific component, equipment, or system. This relation captures the functional
linkage between sensor-derived data and the operational behavior of
the asset, enabling performance assessment, anomaly detection, and predictive maintenance.
It supports traceability between real-time or historical measurements and the physical or logical entities
they characterize within the system model."
from_entity = "monitoring_variable"
to_entity = "mbse_entity"
20 changes: 20 additions & 0 deletions src/dackar/knowledge_graph/schemas/nuclearEntitySchema.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
title = "Nuclear Entity Graph Schema"
version = "1.0"

# ====================
# Node Entities
# ====================

[entities.nuclear_entity]
description = "Represents a generalized nuclear-relevant entity that may be referenced in unstructured
text authored by plant personnel, encompassing a broad spectrum of technical and
operational subjects. These include materials, chemical elements and compounds, chemical
reactions, failure modes, degradation mechanisms, and components across electrical,
hydraulic, and mechanical systems."
properties = [
{ name = "class", type = "string"},
]




31 changes: 31 additions & 0 deletions src/dackar/knowledge_graph/schemas/numericPerfomanceSchema.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
title = "Custom MBSE Model Graph Schema"
version = "1.0"

# ====================
# Node Entities
# ====================

[entities.anomaly]
description = " Represents a specific occurrence of an anomaly (such as threshold
violations, signal deviations, or unexpected patterns) associated
with a particular component, equipment, or system that have been
detected by monitoring sensors coupled with an anomaly detection
algorithm. "

properties = [
{ name = "t_initial", type = "datetime"},
{ name = "t_final", type = "datetime", optional = true },
]

# ====================
# Relationships
# ====================

[relationships.detected_by]
description = " Defines a semantic relationship indicating that a detected anomaly
(such as a deviation from expected operational behavior) was identified
through the observation or analysis of a specific monitoring variable.
This link establishes traceability between the anomaly instance and the
physical variable that triggered its detection, "
from_entity = "anomaly"
to_entity = "monitoring_variable"
Loading