prograph 1.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prograph/__init__.py +36 -0
- prograph/__main__.py +5 -0
- prograph/_version.py +375 -0
- prograph/cli/__init__.py +1 -0
- prograph/cli/_iri_utils.py +124 -0
- prograph/cli/emit_genie_space.py +107 -0
- prograph/cli/generate_views.py +140 -0
- prograph/cli/main.py +420 -0
- prograph/cli/schema_inferrer.py +746 -0
- prograph/cli/ttl_loader.py +289 -0
- prograph/cli/upload_genie_space.py +84 -0
- prograph/config/__init__.py +27 -0
- prograph/config/yaml_config.py +848 -0
- prograph/demos/__init__.py +14 -0
- prograph/demos/turbofan/README.md +74 -0
- prograph/demos/turbofan/SCENARIO.md +209 -0
- prograph/demos/turbofan/__init__.py +75 -0
- prograph/demos/turbofan/create_tables.sql +206 -0
- prograph/demos/turbofan/data/engine-instances.ttl +1123 -0
- prograph/demos/turbofan/data/sensor-timeseries.csv +90 -0
- prograph/demos/turbofan/demo.py +162 -0
- prograph/demos/turbofan/genie_qa_notebook.py +434 -0
- prograph/demos/turbofan/graph.yaml +1098 -0
- prograph/demos/turbofan/instance_graph_demo.py +32 -0
- prograph/demos/turbofan/load.py +223 -0
- prograph/demos/turbofan/mapping.r2rml.ttl +991 -0
- prograph/demos/turbofan/ontology/engine-maintenance.ttl +606 -0
- prograph/demos/turbofan/payload-shapes.ttl +33 -0
- prograph/demos/turbofan/queries/example-queries.sparql +215 -0
- prograph/demos/turbofan/shapes.ttl +75 -0
- prograph/demos/turbofan/tables.py +106 -0
- prograph/demos/turbofan/turbofan_schema.py +393 -0
- prograph/demos/turbofan/validation_demo.py +153 -0
- prograph/describe.py +231 -0
- prograph/endpoint/__init__.py +12 -0
- prograph/endpoint/app.py +722 -0
- prograph/endpoint/cli.py +280 -0
- prograph/endpoint/credentials.py +240 -0
- prograph/endpoint/engines.py +418 -0
- prograph/endpoint/negotiate.py +101 -0
- prograph/endpoint/results.py +181 -0
- prograph/endpoint/service.py +31 -0
- prograph/engine.py +2718 -0
- prograph/execution.py +455 -0
- prograph/executors/__init__.py +6 -0
- prograph/executors/base.py +11 -0
- prograph/executors/databricks_sql_executor.py +51 -0
- prograph/executors/duckdb_executor.py +24 -0
- prograph/executors/mysql_executor.py +20 -0
- prograph/executors/oracle_executor.py +24 -0
- prograph/executors/pandas_executor.py +72 -0
- prograph/executors/postgresql_executor.py +35 -0
- prograph/executors/spark_executor.py +88 -0
- prograph/executors/sqlserver_executor.py +35 -0
- prograph/extras/__init__.py +1 -0
- prograph/extras/graphql/__init__.py +33 -0
- prograph/extras/graphql/execute.py +25 -0
- prograph/extras/graphql/schema.py +314 -0
- prograph/extras/instance_graph.py +559 -0
- prograph/genie/__init__.py +83 -0
- prograph/genie/databricks_uploader.py +306 -0
- prograph/genie/deploy.py +393 -0
- prograph/genie/formats.py +414 -0
- prograph/genie/instruction_generator.py +375 -0
- prograph/genie/sample_query_generator.py +256 -0
- prograph/genie/shacl_views.py +318 -0
- prograph/genie/space_emitter.py +329 -0
- prograph/genie/view_generator.py +628 -0
- prograph/genie/view_writer.py +172 -0
- prograph/graph/__init__.py +1 -0
- prograph/graph/ansi_session.py +348 -0
- prograph/graph/databricks_sql_graph.py +300 -0
- prograph/graph/drivers.py +143 -0
- prograph/graph/duckdb_graph.py +68 -0
- prograph/graph/mysql_graph.py +38 -0
- prograph/graph/oracle_graph.py +285 -0
- prograph/graph/pandas_graph.py +343 -0
- prograph/graph/postgresql_graph.py +644 -0
- prograph/graph/spark_graph.py +556 -0
- prograph/graph/sql_graph.py +83 -0
- prograph/graph/sqlserver_graph.py +72 -0
- prograph/hints.py +95 -0
- prograph/logging.py +550 -0
- prograph/mcp/__init__.py +29 -0
- prograph/mcp/__main__.py +180 -0
- prograph/mcp/bootstrap.py +98 -0
- prograph/mcp/server.py +601 -0
- prograph/mcp/sparql.py +397 -0
- prograph/mcp/tools.py +504 -0
- prograph/nlp/__init__.py +79 -0
- prograph/nlp/client.py +305 -0
- prograph/nlp/databricks_tools.py +369 -0
- prograph/nlp/graph_context.py +313 -0
- prograph/nlp/interface.py +652 -0
- prograph/nlp/prompts/__init__.py +19 -0
- prograph/nlp/prompts/examples.py +258 -0
- prograph/nlp/prompts/system.py +239 -0
- prograph/nlp/providers/__init__.py +14 -0
- prograph/nlp/providers/anthropic.py +274 -0
- prograph/nlp/providers/databricks.py +312 -0
- prograph/nlp/providers/openai.py +203 -0
- prograph/nlp/schema_context.py +78 -0
- prograph/ontology/__init__.py +53 -0
- prograph/ontology/alignment.py +542 -0
- prograph/ontology/hierarchy.py +310 -0
- prograph/ontology/imports.py +587 -0
- prograph/ontology/layer.py +991 -0
- prograph/ontology/skos.py +61 -0
- prograph/owl/__init__.py +27 -0
- prograph/owl/defined_classes.py +323 -0
- prograph/parameters.py +242 -0
- prograph/parser/__init__.py +1 -0
- prograph/parser/cypher/CypherLexer.py +836 -0
- prograph/parser/cypher/CypherListener.py +966 -0
- prograph/parser/cypher/CypherParser.py +10854 -0
- prograph/parser/cypher/CypherVisitor.py +543 -0
- prograph/parser/cypher/__init__.py +1 -0
- prograph/parser/sparql/SparqlLexer.py +801 -0
- prograph/parser/sparql/SparqlParser.py +10146 -0
- prograph/parser/sparql/SparqlParserListener.py +1056 -0
- prograph/parser/sparql/SparqlParserVisitor.py +593 -0
- prograph/parser/sparql/__init__.py +8 -0
- prograph/plan/__init__.py +3 -0
- prograph/plan/ir/__init__.py +1 -0
- prograph/plan/ir/casts.py +338 -0
- prograph/plan/ir/consistency.py +397 -0
- prograph/plan/ir/construct.py +90 -0
- prograph/plan/ir/cost.py +234 -0
- prograph/plan/ir/cypher_answer.py +1081 -0
- prograph/plan/ir/cypher_apoc.py +717 -0
- prograph/plan/ir/cypher_apoc_convert.py +505 -0
- prograph/plan/ir/cypher_apoc_date.py +845 -0
- prograph/plan/ir/cypher_apoc_map.py +496 -0
- prograph/plan/ir/cypher_apoc_meta.py +384 -0
- prograph/plan/ir/cypher_apoc_path.py +597 -0
- prograph/plan/ir/cypher_apoc_procedures.py +163 -0
- prograph/plan/ir/cypher_apoc_text.py +785 -0
- prograph/plan/ir/cypher_front.py +5474 -0
- prograph/plan/ir/cypher_functions.py +565 -0
- prograph/plan/ir/cypher_lists.py +935 -0
- prograph/plan/ir/cypher_maps.py +370 -0
- prograph/plan/ir/cypher_mixed.py +604 -0
- prograph/plan/ir/cypher_ontology.py +226 -0
- prograph/plan/ir/cypher_procedures.py +191 -0
- prograph/plan/ir/cypher_runtime_errors.py +107 -0
- prograph/plan/ir/cypher_temporal.py +1357 -0
- prograph/plan/ir/cypher_temporal_arith.py +339 -0
- prograph/plan/ir/cypher_values.py +546 -0
- prograph/plan/ir/cypher_write.py +612 -0
- prograph/plan/ir/dataset.py +643 -0
- prograph/plan/ir/dates.py +102 -0
- prograph/plan/ir/entry.py +992 -0
- prograph/plan/ir/expr.py +260 -0
- prograph/plan/ir/facts.py +1171 -0
- prograph/plan/ir/fresh.py +291 -0
- prograph/plan/ir/freshness.py +625 -0
- prograph/plan/ir/identity.py +797 -0
- prograph/plan/ir/java_datetime.py +265 -0
- prograph/plan/ir/java_regex.py +391 -0
- prograph/plan/ir/join_order.py +39 -0
- prograph/plan/ir/key_checks.py +433 -0
- prograph/plan/ir/keys.py +454 -0
- prograph/plan/ir/lower.py +5323 -0
- prograph/plan/ir/ops.py +619 -0
- prograph/plan/ir/owl_rl.py +1119 -0
- prograph/plan/ir/owl_rl_rules.py +725 -0
- prograph/plan/ir/profiles.py +694 -0
- prograph/plan/ir/ql.py +987 -0
- prograph/plan/ir/rdfs.py +342 -0
- prograph/plan/ir/rewrite.py +1782 -0
- prograph/plan/ir/saturate.py +339 -0
- prograph/plan/ir/semantics.py +103 -0
- prograph/plan/ir/slot.py +509 -0
- prograph/plan/ir/sparql_front.py +3418 -0
- prograph/plan/ir/strings.py +534 -0
- prograph/plan/ir/term_functions.py +274 -0
- prograph/plan/ir/terms.py +84 -0
- prograph/plan/ir/xpath_regex.py +264 -0
- prograph/plan/run_record.py +65 -0
- prograph/plan/sql/__init__.py +21 -0
- prograph/plan/sql/dialect.py +3726 -0
- prograph/plan/sql/mysql_serializer.py +103 -0
- prograph/plan/sql/names.py +65 -0
- prograph/plan/sql/oracle_serializer.py +306 -0
- prograph/plan/sql/pg_serializer.py +501 -0
- prograph/plan/sql/rel_algebra.py +781 -0
- prograph/plan/sql/sql_serializer.py +1419 -0
- prograph/plan/sql/sqlserver_serializer.py +603 -0
- prograph/provenance.py +222 -0
- prograph/r2rml/__init__.py +48 -0
- prograph/r2rml/catalog.py +259 -0
- prograph/r2rml/compile.py +372 -0
- prograph/r2rml/direct.py +140 -0
- prograph/r2rml/export.py +495 -0
- prograph/r2rml/model.py +180 -0
- prograph/r2rml/parser.py +546 -0
- prograph/r2rml/schema.py +120 -0
- prograph/read_only.py +122 -0
- prograph/results.py +157 -0
- prograph/rules/__init__.py +168 -0
- prograph/rules/__main__.py +32 -0
- prograph/schema/__init__.py +60 -0
- prograph/schema/change_set.py +50 -0
- prograph/schema/collations.py +198 -0
- prograph/schema/compile_schema.py +388 -0
- prograph/schema/context.py +845 -0
- prograph/schema/examples.py +234 -0
- prograph/schema/iri.py +817 -0
- prograph/schema/literals.py +94 -0
- prograph/schema/lpg_view.py +617 -0
- prograph/schema/mapping.py +1803 -0
- prograph/schema/maps_schema.py +40 -0
- prograph/schema/naming.py +77 -0
- prograph/schema/query_sources.py +59 -0
- prograph/schema/rows.py +215 -0
- prograph/schema/source_map.py +1103 -0
- prograph/schema/store_view.py +459 -0
- prograph/schema/types.py +569 -0
- prograph/schema/xsd.py +569 -0
- prograph/shacl/__init__.py +30 -0
- prograph/shacl/dqv.py +58 -0
- prograph/shacl/generate.py +255 -0
- prograph/shacl/report.py +138 -0
- prograph/shacl/validator.py +164 -0
- prograph/store.py +1737 -0
- prograph/utils/__init__.py +6 -0
- prograph/utils/exceptions.py +308 -0
- prograph/utils/helpers.py +126 -0
- prograph/warnings.py +46 -0
- prograph/writes.py +369 -0
- prograph-1.3.3.dist-info/METADATA +281 -0
- prograph-1.3.3.dist-info/RECORD +237 -0
- prograph-1.3.3.dist-info/WHEEL +5 -0
- prograph-1.3.3.dist-info/entry_points.txt +3 -0
- prograph-1.3.3.dist-info/licenses/LICENSE +201 -0
- prograph-1.3.3.dist-info/licenses/NOTICE +10 -0
- prograph-1.3.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
"""Turbofan engine predictive maintenance schema mapping for ProGraph.
|
|
2
|
+
|
|
3
|
+
Defines the graph schema for turbofan engine health monitoring.
|
|
4
|
+
|
|
5
|
+
Node labels: 53 over 10 tables. Five shared tables carry a ``type``
|
|
6
|
+
discriminator; each has an abstract parent label plus one label per
|
|
7
|
+
concrete type (41 concrete labels, 5 parents). Five more tables hold one
|
|
8
|
+
label each. Two labels are queries (``HighWearComponent``: a wear index of
|
|
9
|
+
0.7 or more; ``CriticalPathComponent``: degradation propagating to two
|
|
10
|
+
things or more), the classes the ontology states as subclasses of
|
|
11
|
+
``Component`` with no axiom an OWL profile applies.
|
|
12
|
+
|
|
13
|
+
- Engine: turbofan engine instances
|
|
14
|
+
- Modules (shared table), parent ``Module`` + concrete types:
|
|
15
|
+
FanModule, LPC, HPC, CombustionChamber, HPT, LPT, ExhaustNozzle,
|
|
16
|
+
AccessoryGearbox, OilSystem, FuelSystem
|
|
17
|
+
(``LPC``, ``HPC``, ``LPT`` and ``HPT`` abbreviate the ontology's
|
|
18
|
+
LowPressureCompressor, HighPressureCompressor, LowPressureTurbine and
|
|
19
|
+
HighPressureTurbine; ``load.add_rdf_mappings`` gives them those class
|
|
20
|
+
IRIs)
|
|
21
|
+
- Components (shared table), parent ``Component`` + concrete types:
|
|
22
|
+
Blade, Disk, Shaft, Bearing, Seal, Combustor, FuelNozzle, OilPump,
|
|
23
|
+
OilFilter, HeatExchanger, FADEC, Vane
|
|
24
|
+
- Sensors (shared table), parent ``Sensor`` + concrete types:
|
|
25
|
+
VibrationSensor, TemperatureSensor, PressureSensor, SpeedSensor,
|
|
26
|
+
OilDebrisSensor, FlowSensor
|
|
27
|
+
- SensorReading: time-series sensor observations
|
|
28
|
+
- DegradationModes (shared table), parent ``DegradationMode`` +
|
|
29
|
+
concrete types: Erosion, Corrosion, FatigueCracking, ThermalDegradation,
|
|
30
|
+
ForeignObjectDamage, WearAbrasion, SealLeakage, CarbonBuildup
|
|
31
|
+
- MaintenanceActions (shared table), parent ``MaintenanceAction``
|
|
32
|
+
+ concrete types: BoroscopeInspection, OilAnalysis, BlendRepair,
|
|
33
|
+
Replacement, ScheduledOverhaul
|
|
34
|
+
- Fleet, Aircraft, OperatingEnvironment
|
|
35
|
+
|
|
36
|
+
A parent is a NodeMapping without ``filter_predicate``: it covers every
|
|
37
|
+
row in the shared table, so relationship endpoints can name the parent
|
|
38
|
+
(``start_node_label='Module'``) instead of every concrete subtype.
|
|
39
|
+
|
|
40
|
+
Relationship types: 17, one table each, 29 mappings. A type that
|
|
41
|
+
connects several label pairs gets one mapping per pair over the same
|
|
42
|
+
table (``MONITORS`` runs from a sensor to a component or a module).
|
|
43
|
+
|
|
44
|
+
- IS_PART_OF, DOWNSTREAM_OF, CONNECTED_TO, DRIVES_SHAFT, SUPPLIES_FLUID_TO
|
|
45
|
+
- MONITORS, INSTALLED_ON, HAS_READING
|
|
46
|
+
- EXHIBITS_DEGRADATION, SUSCEPTIBLE_TO, INDICATED_BY, PROPAGATES_TO
|
|
47
|
+
- PERFORMED_ON, ADDRESSES_DEGRADATION
|
|
48
|
+
- INSTALLED_ON_AIRCRAFT, BELONGS_TO_FLEET, OPERATES_IN
|
|
49
|
+
|
|
50
|
+
Every mapping is ``mutable=True``: the action layer (ProAct) writes a
|
|
51
|
+
label's properties through ``engine.set_properties``, and OWL RL writes its
|
|
52
|
+
inferred rows (types, transitive and symmetric edges) only into mappings
|
|
53
|
+
marked mutable (the two query labels are not).
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
from prograph.schema import GraphSchema, NodeMapping, RelationshipMapping
|
|
57
|
+
|
|
58
|
+
# The components whose wear index is 0.7 or more (HighWearComponent).
|
|
59
|
+
HIGH_WEAR_QUERY = "SELECT id FROM components WHERE wear_index >= 0.7"
|
|
60
|
+
# The components that propagate degradation to two things or more (CriticalPathComponent).
|
|
61
|
+
CRITICAL_PATH_QUERY = ("SELECT start_id AS id FROM propagates_to GROUP BY start_id "
|
|
62
|
+
"HAVING COUNT(DISTINCT end_id) >= 2")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def create_turbofan_schema() -> GraphSchema:
|
|
66
|
+
"""Create the turbofan engine graph schema.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
GraphSchema configured for engine predictive maintenance
|
|
70
|
+
"""
|
|
71
|
+
schema = GraphSchema()
|
|
72
|
+
|
|
73
|
+
# ======================================================================
|
|
74
|
+
# Node Mappings
|
|
75
|
+
# ======================================================================
|
|
76
|
+
|
|
77
|
+
# --- Engines ----------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
schema.add_node_mapping(NodeMapping(
|
|
80
|
+
source_table='engines',
|
|
81
|
+
label='Engine',
|
|
82
|
+
id_column='id',
|
|
83
|
+
mutable=True,
|
|
84
|
+
property_columns={
|
|
85
|
+
'label': 'label',
|
|
86
|
+
'serial_number': 'serial_number',
|
|
87
|
+
'total_cycles_since_new': 'total_cycles_since_new',
|
|
88
|
+
'total_hours_since_new': 'total_hours_since_new',
|
|
89
|
+
'cycles_since_last_overhaul': 'cycles_since_last_overhaul',
|
|
90
|
+
'hours_since_last_overhaul': 'hours_since_last_overhaul',
|
|
91
|
+
'wear_index': 'wear_index',
|
|
92
|
+
}
|
|
93
|
+
))
|
|
94
|
+
|
|
95
|
+
# --- Modules (shared table, discriminated by type) --------------------
|
|
96
|
+
#
|
|
97
|
+
# A NodeMapping without ``filter_predicate`` on a shared table acts as
|
|
98
|
+
# the *abstract parent*. It covers every row regardless of subtype.
|
|
99
|
+
# Lets OWL views over the parent class resolve directly, and lets
|
|
100
|
+
# relationship endpoints reference the parent (`start_node_label='Module'`)
|
|
101
|
+
# without having to enumerate every concrete subtype.
|
|
102
|
+
|
|
103
|
+
_MODULE_PROPS = {
|
|
104
|
+
'label': 'label',
|
|
105
|
+
'serial_number': 'serial_number',
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
schema.add_node_mapping(NodeMapping(
|
|
109
|
+
source_table='modules',
|
|
110
|
+
label='Module',
|
|
111
|
+
id_column='id',
|
|
112
|
+
mutable=True,
|
|
113
|
+
property_columns=dict(_MODULE_PROPS),
|
|
114
|
+
))
|
|
115
|
+
|
|
116
|
+
for module_type in [
|
|
117
|
+
'FanModule', 'LPC', 'HPC', 'CombustionChamber', 'HPT', 'LPT',
|
|
118
|
+
'ExhaustNozzle', 'AccessoryGearbox', 'OilSystem', 'FuelSystem',
|
|
119
|
+
]:
|
|
120
|
+
schema.add_node_mapping(NodeMapping(
|
|
121
|
+
source_table='modules',
|
|
122
|
+
label=module_type,
|
|
123
|
+
id_column='id',
|
|
124
|
+
mutable=True,
|
|
125
|
+
property_columns=dict(_MODULE_PROPS),
|
|
126
|
+
filter_predicate={'type': module_type},
|
|
127
|
+
))
|
|
128
|
+
|
|
129
|
+
# --- Components (shared table, discriminated by type) -----------------
|
|
130
|
+
|
|
131
|
+
_COMPONENT_PROPS = {
|
|
132
|
+
'label': 'label',
|
|
133
|
+
'serial_number': 'serial_number',
|
|
134
|
+
'wear_index': 'wear_index',
|
|
135
|
+
'total_cycles_since_new': 'total_cycles_since_new',
|
|
136
|
+
'cycles_since_last_overhaul': 'cycles_since_last_overhaul',
|
|
137
|
+
'remaining_useful_life_cycles': 'remaining_useful_life_cycles',
|
|
138
|
+
'scheduled_interval': 'scheduled_interval',
|
|
139
|
+
'mean_time_between_failures': 'mean_time_between_failures',
|
|
140
|
+
'has_health_state': 'has_health_state',
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
schema.add_node_mapping(NodeMapping(
|
|
144
|
+
source_table='components',
|
|
145
|
+
label='Component',
|
|
146
|
+
id_column='id',
|
|
147
|
+
mutable=True,
|
|
148
|
+
property_columns=dict(_COMPONENT_PROPS),
|
|
149
|
+
))
|
|
150
|
+
|
|
151
|
+
for component_type in [
|
|
152
|
+
'Blade', 'Disk', 'Shaft', 'Bearing', 'Seal', 'Combustor',
|
|
153
|
+
'FuelNozzle', 'OilPump', 'OilFilter', 'HeatExchanger', 'FADEC',
|
|
154
|
+
'Vane',
|
|
155
|
+
]:
|
|
156
|
+
schema.add_node_mapping(NodeMapping(
|
|
157
|
+
source_table='components',
|
|
158
|
+
label=component_type,
|
|
159
|
+
id_column='id',
|
|
160
|
+
mutable=True,
|
|
161
|
+
property_columns=dict(_COMPONENT_PROPS),
|
|
162
|
+
filter_predicate={'type': component_type},
|
|
163
|
+
))
|
|
164
|
+
|
|
165
|
+
# Two classes the ontology defines by values, which no OWL profile applies (a datatype restriction, a
|
|
166
|
+
# min cardinality): their members are a query's rows, so SQL answers them.
|
|
167
|
+
schema.add_node_mapping(NodeMapping(
|
|
168
|
+
source_table='high_wear_components', # the query's name: no table of the database
|
|
169
|
+
label='HighWearComponent',
|
|
170
|
+
id_column='id',
|
|
171
|
+
source_query=HIGH_WEAR_QUERY,
|
|
172
|
+
))
|
|
173
|
+
schema.add_node_mapping(NodeMapping(
|
|
174
|
+
source_table='critical_path_components',
|
|
175
|
+
label='CriticalPathComponent',
|
|
176
|
+
id_column='id',
|
|
177
|
+
source_query=CRITICAL_PATH_QUERY,
|
|
178
|
+
))
|
|
179
|
+
|
|
180
|
+
# --- Sensors (shared table, discriminated by type) --------------------
|
|
181
|
+
|
|
182
|
+
_SENSOR_PROPS = {
|
|
183
|
+
'label': 'label',
|
|
184
|
+
'sensor_id': 'sensor_id',
|
|
185
|
+
'nominal_min': 'nominal_min',
|
|
186
|
+
'nominal_max': 'nominal_max',
|
|
187
|
+
'caution_threshold': 'caution_threshold',
|
|
188
|
+
'warning_threshold': 'warning_threshold',
|
|
189
|
+
'critical_threshold': 'critical_threshold',
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
schema.add_node_mapping(NodeMapping(
|
|
193
|
+
source_table='sensors',
|
|
194
|
+
label='Sensor',
|
|
195
|
+
id_column='id',
|
|
196
|
+
mutable=True,
|
|
197
|
+
property_columns=dict(_SENSOR_PROPS),
|
|
198
|
+
))
|
|
199
|
+
|
|
200
|
+
for sensor_type in [
|
|
201
|
+
'VibrationSensor', 'TemperatureSensor', 'PressureSensor',
|
|
202
|
+
'SpeedSensor', 'OilDebrisSensor', 'FlowSensor',
|
|
203
|
+
]:
|
|
204
|
+
schema.add_node_mapping(NodeMapping(
|
|
205
|
+
source_table='sensors',
|
|
206
|
+
label=sensor_type,
|
|
207
|
+
id_column='id',
|
|
208
|
+
mutable=True,
|
|
209
|
+
property_columns=dict(_SENSOR_PROPS),
|
|
210
|
+
filter_predicate={'type': sensor_type},
|
|
211
|
+
))
|
|
212
|
+
|
|
213
|
+
# --- Sensor Readings --------------------------------------------------
|
|
214
|
+
|
|
215
|
+
schema.add_node_mapping(NodeMapping(
|
|
216
|
+
source_table='sensor_readings',
|
|
217
|
+
label='SensorReading',
|
|
218
|
+
id_column='id',
|
|
219
|
+
mutable=True,
|
|
220
|
+
property_columns={
|
|
221
|
+
'reading_timestamp': 'reading_timestamp',
|
|
222
|
+
'reading_value': 'reading_value',
|
|
223
|
+
'reading_unit': 'reading_unit',
|
|
224
|
+
}
|
|
225
|
+
))
|
|
226
|
+
|
|
227
|
+
# --- Degradation Modes (shared table, discriminated by type) ----------
|
|
228
|
+
|
|
229
|
+
_DEGRADATION_PROPS = {
|
|
230
|
+
'label': 'label',
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
schema.add_node_mapping(NodeMapping(
|
|
234
|
+
source_table='degradation_modes',
|
|
235
|
+
label='DegradationMode',
|
|
236
|
+
id_column='id',
|
|
237
|
+
mutable=True,
|
|
238
|
+
property_columns=dict(_DEGRADATION_PROPS),
|
|
239
|
+
))
|
|
240
|
+
|
|
241
|
+
for degradation_type in [
|
|
242
|
+
'Erosion', 'Corrosion', 'FatigueCracking', 'ThermalDegradation',
|
|
243
|
+
'ForeignObjectDamage', 'WearAbrasion', 'SealLeakage', 'CarbonBuildup',
|
|
244
|
+
]:
|
|
245
|
+
schema.add_node_mapping(NodeMapping(
|
|
246
|
+
source_table='degradation_modes',
|
|
247
|
+
label=degradation_type,
|
|
248
|
+
id_column='id',
|
|
249
|
+
mutable=True,
|
|
250
|
+
property_columns=dict(_DEGRADATION_PROPS),
|
|
251
|
+
filter_predicate={'type': degradation_type},
|
|
252
|
+
))
|
|
253
|
+
|
|
254
|
+
# --- Maintenance Actions (shared table, discriminated by type) --------
|
|
255
|
+
|
|
256
|
+
_MAINTENANCE_PROPS = {
|
|
257
|
+
'label': 'label',
|
|
258
|
+
'comment': 'comment',
|
|
259
|
+
'maintenance_date': 'maintenance_date',
|
|
260
|
+
'maintenance_cost': 'maintenance_cost',
|
|
261
|
+
'maintenance_downtime_hours': 'maintenance_downtime_hours',
|
|
262
|
+
'finding': 'finding',
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
schema.add_node_mapping(NodeMapping(
|
|
266
|
+
source_table='maintenance_actions',
|
|
267
|
+
label='MaintenanceAction',
|
|
268
|
+
id_column='id',
|
|
269
|
+
mutable=True,
|
|
270
|
+
property_columns=dict(_MAINTENANCE_PROPS),
|
|
271
|
+
))
|
|
272
|
+
|
|
273
|
+
for action_type in [
|
|
274
|
+
'BoroscopeInspection', 'OilAnalysis', 'BlendRepair', 'Replacement',
|
|
275
|
+
'ScheduledOverhaul',
|
|
276
|
+
]:
|
|
277
|
+
schema.add_node_mapping(NodeMapping(
|
|
278
|
+
source_table='maintenance_actions',
|
|
279
|
+
label=action_type,
|
|
280
|
+
id_column='id',
|
|
281
|
+
mutable=True,
|
|
282
|
+
property_columns=dict(_MAINTENANCE_PROPS),
|
|
283
|
+
filter_predicate={'type': action_type},
|
|
284
|
+
))
|
|
285
|
+
|
|
286
|
+
# --- Fleets -----------------------------------------------------------
|
|
287
|
+
|
|
288
|
+
schema.add_node_mapping(NodeMapping(
|
|
289
|
+
source_table='fleets',
|
|
290
|
+
label='Fleet',
|
|
291
|
+
id_column='id',
|
|
292
|
+
mutable=True,
|
|
293
|
+
property_columns={
|
|
294
|
+
'label': 'label',
|
|
295
|
+
}
|
|
296
|
+
))
|
|
297
|
+
|
|
298
|
+
# --- Aircraft ---------------------------------------------------------
|
|
299
|
+
|
|
300
|
+
schema.add_node_mapping(NodeMapping(
|
|
301
|
+
source_table='aircraft',
|
|
302
|
+
label='Aircraft',
|
|
303
|
+
id_column='id',
|
|
304
|
+
mutable=True,
|
|
305
|
+
property_columns={
|
|
306
|
+
'label': 'label',
|
|
307
|
+
}
|
|
308
|
+
))
|
|
309
|
+
|
|
310
|
+
# --- Operating Environments -------------------------------------------
|
|
311
|
+
|
|
312
|
+
schema.add_node_mapping(NodeMapping(
|
|
313
|
+
source_table='operating_environments',
|
|
314
|
+
label='OperatingEnvironment',
|
|
315
|
+
id_column='id',
|
|
316
|
+
mutable=True,
|
|
317
|
+
property_columns={
|
|
318
|
+
'label': 'label',
|
|
319
|
+
}
|
|
320
|
+
))
|
|
321
|
+
|
|
322
|
+
# ======================================================================
|
|
323
|
+
# Relationship Mappings
|
|
324
|
+
# ======================================================================
|
|
325
|
+
#
|
|
326
|
+
# One table per relationship type, columns ``start_id`` / ``end_id``.
|
|
327
|
+
# Several types connect more than one pair of labels (a sensor monitors
|
|
328
|
+
# a component or a whole module; a maintenance action is performed on a
|
|
329
|
+
# component, a module or the engine), so a type gets one mapping per
|
|
330
|
+
# endpoint pair, all over the same table. The pairs listed are the ones
|
|
331
|
+
# the instance data (data/engine-instances.ttl) contains.
|
|
332
|
+
|
|
333
|
+
_RELATIONSHIPS = [
|
|
334
|
+
# (rel_type, start label, end label)
|
|
335
|
+
# Mereological: module -> engine, component -> module or engine
|
|
336
|
+
('IS_PART_OF', 'Module', 'Engine'),
|
|
337
|
+
('IS_PART_OF', 'Component', 'Module'),
|
|
338
|
+
('IS_PART_OF', 'Component', 'Engine'),
|
|
339
|
+
# Gas path ordering
|
|
340
|
+
('DOWNSTREAM_OF', 'Module', 'Module'),
|
|
341
|
+
# Physical adjacency
|
|
342
|
+
('CONNECTED_TO', 'Module', 'Module'),
|
|
343
|
+
('CONNECTED_TO', 'Component', 'Module'),
|
|
344
|
+
# Turbine drives compressor/fan via shaft
|
|
345
|
+
('DRIVES_SHAFT', 'Module', 'Module'),
|
|
346
|
+
('DRIVES_SHAFT', 'Component', 'Module'),
|
|
347
|
+
('DRIVES_SHAFT', 'Module', 'Component'),
|
|
348
|
+
# Oil/fuel supply
|
|
349
|
+
('SUPPLIES_FLUID_TO', 'Module', 'Module'),
|
|
350
|
+
('SUPPLIES_FLUID_TO', 'Module', 'Component'),
|
|
351
|
+
# Sensor observes a component or a module; the FADEC monitors the engine
|
|
352
|
+
('MONITORS', 'Sensor', 'Component'),
|
|
353
|
+
('MONITORS', 'Sensor', 'Module'),
|
|
354
|
+
('MONITORS', 'Component', 'Engine'),
|
|
355
|
+
# Sensor physical location
|
|
356
|
+
('INSTALLED_ON', 'Sensor', 'Component'),
|
|
357
|
+
('INSTALLED_ON', 'Sensor', 'Module'),
|
|
358
|
+
# Sensor -> readings
|
|
359
|
+
('HAS_READING', 'Sensor', 'SensorReading'),
|
|
360
|
+
# Active degradation
|
|
361
|
+
('EXHIBITS_DEGRADATION', 'Component', 'DegradationMode'),
|
|
362
|
+
# Known failure mode
|
|
363
|
+
('SUSCEPTIBLE_TO', 'Component', 'DegradationMode'),
|
|
364
|
+
# Which sensors detect degradation
|
|
365
|
+
('INDICATED_BY', 'DegradationMode', 'Sensor'),
|
|
366
|
+
# Degradation propagation paths
|
|
367
|
+
('PROPAGATES_TO', 'Component', 'Component'),
|
|
368
|
+
('PROPAGATES_TO', 'Component', 'Module'),
|
|
369
|
+
# Maintenance -> target
|
|
370
|
+
('PERFORMED_ON', 'MaintenanceAction', 'Component'),
|
|
371
|
+
('PERFORMED_ON', 'MaintenanceAction', 'Module'),
|
|
372
|
+
('PERFORMED_ON', 'MaintenanceAction', 'Engine'),
|
|
373
|
+
# Maintenance -> degradation
|
|
374
|
+
('ADDRESSES_DEGRADATION', 'MaintenanceAction', 'DegradationMode'),
|
|
375
|
+
# Engine -> Aircraft -> Fleet, Engine -> OperatingEnvironment
|
|
376
|
+
('INSTALLED_ON_AIRCRAFT', 'Engine', 'Aircraft'),
|
|
377
|
+
('BELONGS_TO_FLEET', 'Aircraft', 'Fleet'),
|
|
378
|
+
('OPERATES_IN', 'Engine', 'OperatingEnvironment'),
|
|
379
|
+
]
|
|
380
|
+
|
|
381
|
+
for rel_type, start_label, end_label in _RELATIONSHIPS:
|
|
382
|
+
schema.add_relationship_mapping(RelationshipMapping(
|
|
383
|
+
source_table=rel_type.lower(),
|
|
384
|
+
rel_type=rel_type,
|
|
385
|
+
start_node_label=start_label,
|
|
386
|
+
start_id_column='start_id',
|
|
387
|
+
end_node_label=end_label,
|
|
388
|
+
end_id_column='end_id',
|
|
389
|
+
property_columns={},
|
|
390
|
+
mutable=True,
|
|
391
|
+
))
|
|
392
|
+
|
|
393
|
+
return schema
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""Turbofan demo, SHACL validation of the engine's data.
|
|
2
|
+
|
|
3
|
+
Uses the schema and data of :mod:`prograph.demos.turbofan.demo`:
|
|
4
|
+
|
|
5
|
+
1. Build a turbofan engine with the demo ontology.
|
|
6
|
+
2. Inject a deliberately broken component (missing ``wearIndex``) to
|
|
7
|
+
show validation catching real data problems.
|
|
8
|
+
3. Run ``engine.validate_shapes(shapes.ttl)``, observe the
|
|
9
|
+
``ComponentShape`` violation on the broken row.
|
|
10
|
+
4. Fix the data, re-validate, observe ``conforms=True``.
|
|
11
|
+
|
|
12
|
+
This is the "before / fix / after" narrative for SHACL.
|
|
13
|
+
|
|
14
|
+
Run::
|
|
15
|
+
|
|
16
|
+
python -m prograph.demos.turbofan.validation_demo
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import sys
|
|
22
|
+
from dataclasses import dataclass
|
|
23
|
+
from typing import Dict
|
|
24
|
+
|
|
25
|
+
import pandas as pd
|
|
26
|
+
|
|
27
|
+
from prograph import ProGraph
|
|
28
|
+
from prograph.demos.turbofan import (
|
|
29
|
+
SHAPES_PATH,
|
|
30
|
+
TURBOFAN_BASE_IRI,
|
|
31
|
+
)
|
|
32
|
+
from prograph.demos.turbofan.demo import build_dataframes, rl_engine
|
|
33
|
+
from prograph.shacl import ValidationReport
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _inject_broken_component(dfs: Dict[str, pd.DataFrame]) -> Dict[str, pd.DataFrame]:
|
|
37
|
+
"""Add a component with a missing wearIndex.
|
|
38
|
+
|
|
39
|
+
Triggers the ComponentShape minCount violation. Doesn't touch the
|
|
40
|
+
propagation or monitoring graph, only the wear data is wrong.
|
|
41
|
+
"""
|
|
42
|
+
dfs = dict(dfs)
|
|
43
|
+
components = dfs["components"].copy()
|
|
44
|
+
components.loc[len(components)] = {"id": "broken-bearing-9999", "wear_index": float("nan")}
|
|
45
|
+
dfs["components"] = components
|
|
46
|
+
return dfs
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _fix_broken_component(connection) -> None:
|
|
50
|
+
"""Patch the broken row's wearIndex in the engine's table: the next ``validate_shapes`` call reads it.
|
|
51
|
+
(The OWL 2 RL facts the store holds do not read wear indexes.)"""
|
|
52
|
+
connection.execute("UPDATE components SET wear_index = 0.45 WHERE id = 'broken-bearing-9999'")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass
|
|
56
|
+
class ValidationDemoResults:
|
|
57
|
+
"""Reports from the three validation passes the demo runs."""
|
|
58
|
+
|
|
59
|
+
before_fix: ValidationReport
|
|
60
|
+
after_fix: ValidationReport
|
|
61
|
+
clean: ValidationReport
|
|
62
|
+
"""The same shapes over the clean data."""
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def run_validation_demo() -> ValidationDemoResults:
|
|
66
|
+
"""Run the full SHACL validation arc.
|
|
67
|
+
|
|
68
|
+
Returns the three :class:`ValidationReport` instances so callers
|
|
69
|
+
(tests, notebooks) can assert on them. The CLI ``main`` formats
|
|
70
|
+
them for a human reader.
|
|
71
|
+
"""
|
|
72
|
+
# ── Engine over deliberately broken data ───────────────────────────
|
|
73
|
+
# The ontology is an OWL 2 RL ontology: the engines reason under profile "rl", with an owned store.
|
|
74
|
+
import duckdb
|
|
75
|
+
connection = duckdb.connect()
|
|
76
|
+
engine = rl_engine(_inject_broken_component(build_dataframes()), connection)
|
|
77
|
+
|
|
78
|
+
before_fix = engine.validate_shapes(
|
|
79
|
+
str(SHAPES_PATH),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
_fix_broken_component(connection)
|
|
83
|
+
after_fix = engine.validate_shapes(
|
|
84
|
+
str(SHAPES_PATH),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# ── Comparison engine: the same shapes over the clean data ─────────
|
|
88
|
+
plain_engine = rl_engine()
|
|
89
|
+
clean = plain_engine.validate_shapes(
|
|
90
|
+
str(SHAPES_PATH),
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
return ValidationDemoResults(
|
|
94
|
+
before_fix=before_fix,
|
|
95
|
+
after_fix=after_fix,
|
|
96
|
+
clean=clean,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# ──────────────────────────────────────────────────────────────────────────
|
|
101
|
+
# CLI entry point
|
|
102
|
+
# ──────────────────────────────────────────────────────────────────────────
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _print_report(label: str, report: ValidationReport) -> None:
|
|
106
|
+
print(f"\n[{label}] {report.summary()}")
|
|
107
|
+
for v in report.violations:
|
|
108
|
+
# Strip the long IRI prefixes to keep terminal output readable.
|
|
109
|
+
# The constraint sits in a blank-node property shape, so name it by
|
|
110
|
+
# its path and constraint component.
|
|
111
|
+
focus = v.focus_node.split("/")[-1]
|
|
112
|
+
path = (v.result_path or "").split("#")[-1]
|
|
113
|
+
component = v.source_constraint_component.split("#")[-1]
|
|
114
|
+
print(
|
|
115
|
+
f" - {v.severity:<9} {focus:<22} {path} {component}: {v.message}"
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def main(argv=None) -> int:
|
|
120
|
+
argv = argv if argv is not None else sys.argv[1:]
|
|
121
|
+
print("Turbofan SHACL demo, validate engine state against shapes\n")
|
|
122
|
+
print(
|
|
123
|
+
"Loads ontology + synthetic instance data, then validates against "
|
|
124
|
+
"the two shapes in shapes.ttl.\n"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
results = run_validation_demo()
|
|
128
|
+
|
|
129
|
+
_print_report("broken data", results.before_fix)
|
|
130
|
+
_print_report("after fix", results.after_fix)
|
|
131
|
+
_print_report("clean data", results.clean)
|
|
132
|
+
|
|
133
|
+
print()
|
|
134
|
+
print(
|
|
135
|
+
"Interpretation:\n"
|
|
136
|
+
" * 'broken data' has one Violation (broken-bearing-9999 missing\n"
|
|
137
|
+
" its wearIndex) plus a Warning (low-wear-component, wear 0.10).\n"
|
|
138
|
+
" * 'after fix' conforms, the bad row now has a real wearIndex.\n"
|
|
139
|
+
" The Warning remains because it's advisory, not a failure:\n"
|
|
140
|
+
" strict SHACL semantics say only Violation-severity results\n"
|
|
141
|
+
" block conformance.\n"
|
|
142
|
+
" * 'clean data' conforms, with the same Warning.\n"
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
# Honest exit code: success if the before/after gap is real.
|
|
146
|
+
if results.before_fix.conforms or not results.after_fix.conforms:
|
|
147
|
+
print("WARNING: demo invariant violated; the fix did not change conformance.")
|
|
148
|
+
return 1
|
|
149
|
+
return 0
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
if __name__ == "__main__":
|
|
153
|
+
sys.exit(main())
|