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,215 @@
|
|
|
1
|
+
PREFIX : <http://example.org/engine-maintenance#>
|
|
2
|
+
PREFIX inst: <http://example.org/engine-maintenance/instances#>
|
|
3
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
4
|
+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
5
|
+
|
|
6
|
+
# =============================================================================
|
|
7
|
+
# Q1: Full part-whole hierarchy for an engine (uses OWL transitive inference)
|
|
8
|
+
# =============================================================================
|
|
9
|
+
# Note: With OWL reasoning, this returns components nested 2+ levels deep
|
|
10
|
+
# (e.g., blades inside modules inside the engine) via transitive isPartOf.
|
|
11
|
+
|
|
12
|
+
SELECT ?part ?partType ?label ?wearIndex
|
|
13
|
+
WHERE {
|
|
14
|
+
inst:engine-1001 :hasPart ?part .
|
|
15
|
+
?part a ?partType .
|
|
16
|
+
?partType rdfs:subClassOf* :PhysicalEntity .
|
|
17
|
+
OPTIONAL { ?part rdfs:label ?label }
|
|
18
|
+
OPTIONAL { ?part :wearIndex ?wearIndex }
|
|
19
|
+
}
|
|
20
|
+
ORDER BY DESC(?wearIndex)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# =============================================================================
|
|
24
|
+
# Q2: All high-wear components (uses OWL defined class HighWearComponent)
|
|
25
|
+
# =============================================================================
|
|
26
|
+
|
|
27
|
+
SELECT ?component ?label ?wear ?healthState
|
|
28
|
+
WHERE {
|
|
29
|
+
?component a :HighWearComponent .
|
|
30
|
+
?component rdfs:label ?label .
|
|
31
|
+
?component :wearIndex ?wear .
|
|
32
|
+
OPTIONAL {
|
|
33
|
+
?component :hasHealthState ?hs .
|
|
34
|
+
?hs a ?healthState .
|
|
35
|
+
?healthState rdfs:subClassOf :HealthState .
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
ORDER BY DESC(?wear)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# =============================================================================
|
|
42
|
+
# Q3: Sensors that have exceeded caution threshold (most recent reading)
|
|
43
|
+
# =============================================================================
|
|
44
|
+
|
|
45
|
+
SELECT ?sensor ?sensorLabel ?latestValue ?threshold ?unit
|
|
46
|
+
WHERE {
|
|
47
|
+
?sensor a/rdfs:subClassOf* :Sensor .
|
|
48
|
+
?sensor rdfs:label ?sensorLabel .
|
|
49
|
+
?sensor :cautionThreshold ?threshold .
|
|
50
|
+
?sensor :hasReading ?reading .
|
|
51
|
+
?reading :readingValue ?latestValue .
|
|
52
|
+
?reading :readingTimestamp ?ts .
|
|
53
|
+
?reading :readingUnit ?unit .
|
|
54
|
+
FILTER(?latestValue > ?threshold)
|
|
55
|
+
# Get only the most recent reading per sensor
|
|
56
|
+
FILTER NOT EXISTS {
|
|
57
|
+
?sensor :hasReading ?newer .
|
|
58
|
+
?newer :readingTimestamp ?ts2 .
|
|
59
|
+
FILTER(?ts2 > ?ts)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
ORDER BY DESC(?latestValue)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# =============================================================================
|
|
66
|
+
# Q4: Degradation propagation paths: what does bearing-1001-mid affect?
|
|
67
|
+
# =============================================================================
|
|
68
|
+
|
|
69
|
+
SELECT ?source ?target ?targetLabel ?targetWear
|
|
70
|
+
WHERE {
|
|
71
|
+
inst:bearing-1001-mid :propagatesTo+ ?target .
|
|
72
|
+
BIND(inst:bearing-1001-mid AS ?source)
|
|
73
|
+
?target rdfs:label ?targetLabel .
|
|
74
|
+
OPTIONAL { ?target :wearIndex ?targetWear }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# =============================================================================
|
|
79
|
+
# Q5: Full causal chain: from fuel nozzle carbon to HPT disk risk
|
|
80
|
+
# =============================================================================
|
|
81
|
+
|
|
82
|
+
SELECT ?step ?label ?degradation ?wear
|
|
83
|
+
WHERE {
|
|
84
|
+
{
|
|
85
|
+
BIND(inst:fuel-nozzle-1001-03 AS ?step)
|
|
86
|
+
} UNION {
|
|
87
|
+
inst:fuel-nozzle-1001-03 :propagatesTo+ ?step .
|
|
88
|
+
}
|
|
89
|
+
?step rdfs:label ?label .
|
|
90
|
+
OPTIONAL { ?step :exhibitsDegradation ?d . ?d rdfs:label ?degradation }
|
|
91
|
+
OPTIONAL { ?step :wearIndex ?wear }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
# =============================================================================
|
|
96
|
+
# Q6: Components approaching RUL limit (within 2000 cycles)
|
|
97
|
+
# =============================================================================
|
|
98
|
+
|
|
99
|
+
SELECT ?component ?label ?rul ?wear ?module
|
|
100
|
+
WHERE {
|
|
101
|
+
?component :remainingUsefulLifeCycles ?rul .
|
|
102
|
+
?component rdfs:label ?label .
|
|
103
|
+
?component :wearIndex ?wear .
|
|
104
|
+
?component :isPartOf ?mod .
|
|
105
|
+
?mod rdfs:label ?module .
|
|
106
|
+
FILTER(?rul < 2000)
|
|
107
|
+
}
|
|
108
|
+
ORDER BY ?rul
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
# =============================================================================
|
|
112
|
+
# Q7: Sensor trend: EGT over time (for charting)
|
|
113
|
+
# =============================================================================
|
|
114
|
+
|
|
115
|
+
SELECT ?timestamp ?value
|
|
116
|
+
WHERE {
|
|
117
|
+
inst:sensor-egt :hasReading ?r .
|
|
118
|
+
?r :readingTimestamp ?timestamp .
|
|
119
|
+
?r :readingValue ?value .
|
|
120
|
+
}
|
|
121
|
+
ORDER BY ?timestamp
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
# =============================================================================
|
|
125
|
+
# Q8: Desert environment susceptibility (OWL + PSL grounding)
|
|
126
|
+
# =============================================================================
|
|
127
|
+
|
|
128
|
+
SELECT ?component ?label ?degradationMode
|
|
129
|
+
WHERE {
|
|
130
|
+
inst:engine-1001 :operatesIn inst:env-desert .
|
|
131
|
+
?component :isPartOf+ inst:engine-1001 .
|
|
132
|
+
?component :susceptibleTo ?dm .
|
|
133
|
+
?dm a :Erosion .
|
|
134
|
+
?component rdfs:label ?label .
|
|
135
|
+
?dm rdfs:label ?degradationMode .
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
# =============================================================================
|
|
140
|
+
# Q9: Maintenance history for an engine
|
|
141
|
+
# =============================================================================
|
|
142
|
+
|
|
143
|
+
SELECT ?action ?actionType ?date ?target ?cost ?notes
|
|
144
|
+
WHERE {
|
|
145
|
+
?action :performedOn ?target .
|
|
146
|
+
?target :isPartOf* inst:engine-1001 .
|
|
147
|
+
?action a ?actionType .
|
|
148
|
+
?actionType rdfs:subClassOf* :MaintenanceAction .
|
|
149
|
+
?action :maintenanceDate ?date .
|
|
150
|
+
OPTIONAL { ?action :maintenanceCost ?cost }
|
|
151
|
+
OPTIONAL { ?action rdfs:comment ?notes }
|
|
152
|
+
}
|
|
153
|
+
ORDER BY DESC(?date)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
# =============================================================================
|
|
157
|
+
# Q10: Compare two engines: component wear side by side
|
|
158
|
+
# =============================================================================
|
|
159
|
+
|
|
160
|
+
SELECT ?componentType ?label1 ?wear1 ?label2 ?wear2
|
|
161
|
+
WHERE {
|
|
162
|
+
?c1 :isPartOf+ inst:engine-1001 .
|
|
163
|
+
?c1 a ?componentType .
|
|
164
|
+
?c1 rdfs:label ?label1 .
|
|
165
|
+
?c1 :wearIndex ?wear1 .
|
|
166
|
+
|
|
167
|
+
?c2 :isPartOf+ inst:engine-2001 .
|
|
168
|
+
?c2 a ?componentType .
|
|
169
|
+
?c2 rdfs:label ?label2 .
|
|
170
|
+
?c2 :wearIndex ?wear2 .
|
|
171
|
+
|
|
172
|
+
?componentType rdfs:subClassOf* :Component .
|
|
173
|
+
}
|
|
174
|
+
ORDER BY DESC(?wear1)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
# =============================================================================
|
|
178
|
+
# Q11: PSL inferred results: query the inferred named graph
|
|
179
|
+
# =============================================================================
|
|
180
|
+
|
|
181
|
+
SELECT ?component ?label ?healthState ?failureProb ?urgency ?action
|
|
182
|
+
FROM NAMED <urn:psl:inferred>
|
|
183
|
+
WHERE {
|
|
184
|
+
GRAPH <urn:psl:inferred> {
|
|
185
|
+
?component :hasHealthState ?healthState .
|
|
186
|
+
OPTIONAL { ?component :failureProbability ?failureProb }
|
|
187
|
+
OPTIONAL { ?component :maintenanceUrgency ?urgency }
|
|
188
|
+
OPTIONAL { ?component :requiresMaintenance ?action }
|
|
189
|
+
}
|
|
190
|
+
?component rdfs:label ?label .
|
|
191
|
+
}
|
|
192
|
+
ORDER BY DESC(?urgency)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
# =============================================================================
|
|
196
|
+
# Q12: Closed-loop: what changes after bearing replacement?
|
|
197
|
+
# (Run before and after the action layer mutation)
|
|
198
|
+
# =============================================================================
|
|
199
|
+
|
|
200
|
+
SELECT ?component ?label ?wear ?healthState ?urgency
|
|
201
|
+
WHERE {
|
|
202
|
+
{
|
|
203
|
+
inst:bearing-1001-mid :propagatesTo ?component .
|
|
204
|
+
} UNION {
|
|
205
|
+
BIND(inst:bearing-1001-mid AS ?component)
|
|
206
|
+
}
|
|
207
|
+
?component rdfs:label ?label .
|
|
208
|
+
?component :wearIndex ?wear .
|
|
209
|
+
OPTIONAL {
|
|
210
|
+
GRAPH <urn:psl:inferred> {
|
|
211
|
+
?component :hasHealthState ?healthState .
|
|
212
|
+
?component :maintenanceUrgency ?urgency .
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# Turbofan SHACL Shapes
|
|
3
|
+
#
|
|
4
|
+
# Validation constraints over the turbofan engine ontology, designed to
|
|
5
|
+
# exercise the SHACL validation end-to-end alongside the demo's
|
|
6
|
+
# OWL 2 RL+ entailment.
|
|
7
|
+
#
|
|
8
|
+
# IRI alignment: these shapes use the same namespace as the canonical
|
|
9
|
+
# turbofan ontology (engine-maintenance#), which the demo's mapping declares
|
|
10
|
+
# as its class and predicate IRIs, so `engine.validate_shapes` meets them.
|
|
11
|
+
#
|
|
12
|
+
# Two focused shapes cover the most common operational data-quality
|
|
13
|
+
# checks you'd want on a maintenance graph: required-property + range
|
|
14
|
+
# (ComponentShape) and a soft anomaly signal (LowWearAnomalyShape).
|
|
15
|
+
#
|
|
16
|
+
# Cross-class shapes that traverse entailed types (e.g.
|
|
17
|
+
# "every MonitoredComponent must have at least one Sensor that
|
|
18
|
+
# :monitors it") require the *shared-table* schema pattern: one
|
|
19
|
+
# `components` table with a `type` column, mapped via
|
|
20
|
+
# `filter_predicate`, so entailed and asserted types share an IRI.
|
|
21
|
+
# The full turbofan schema in `turbofan_schema.py` uses that pattern;
|
|
22
|
+
# this demo's mini-schema does not (it has one table per label for
|
|
23
|
+
# clarity), so we intentionally skip those shapes here. See the docs
|
|
24
|
+
# in `docs/guides/shacl.md` for the entailment-aware-shape pattern.
|
|
25
|
+
# =============================================================================
|
|
26
|
+
|
|
27
|
+
@prefix : <http://example.org/engine-maintenance#> .
|
|
28
|
+
@prefix sh: <http://www.w3.org/ns/shacl#> .
|
|
29
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# ----------------------------------------------------------------------------
|
|
33
|
+
# ComponentShape: every Component must have a wearIndex in [0.0, 1.0].
|
|
34
|
+
#
|
|
35
|
+
# Catches two kinds of data-quality problems at once:
|
|
36
|
+
# * missing wearIndex (an unmonitored part that slipped past ingest)
|
|
37
|
+
# * out-of-range wearIndex (a sensor or transform produced a wild value)
|
|
38
|
+
#
|
|
39
|
+
# Use case: data-quality gate before downstream analytics or
|
|
40
|
+
# reliability scoring runs.
|
|
41
|
+
# ----------------------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
:ComponentShape a sh:NodeShape ;
|
|
44
|
+
sh:targetClass :Component ;
|
|
45
|
+
sh:property [
|
|
46
|
+
sh:path :wearIndex ;
|
|
47
|
+
sh:minCount 1 ;
|
|
48
|
+
sh:minInclusive 0.0 ;
|
|
49
|
+
sh:maxInclusive 1.0 ;
|
|
50
|
+
sh:message "Component must have a wearIndex in [0.0, 1.0]"
|
|
51
|
+
] .
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# ----------------------------------------------------------------------------
|
|
55
|
+
# LowWearAnomalyShape: surfaces Components with implausibly-low wearIndex
|
|
56
|
+
# as a Warning (not a Violation).
|
|
57
|
+
#
|
|
58
|
+
# A wear index near zero on a deployed engine component is suspicious:
|
|
59
|
+
# either the part is brand-new (in which case it probably shouldn't be
|
|
60
|
+
# in the active inventory yet) or the wear sensor is stuck. Operations
|
|
61
|
+
# wants to be alerted but the data isn't broken: that's the
|
|
62
|
+
# Violation / Warning distinction.
|
|
63
|
+
#
|
|
64
|
+
# Use case: anomaly signal routed to ProAct as a low-priority data
|
|
65
|
+
# task rather than a hard fail.
|
|
66
|
+
# ----------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
:LowWearAnomalyShape a sh:NodeShape ;
|
|
69
|
+
sh:targetClass :Component ;
|
|
70
|
+
sh:property [
|
|
71
|
+
sh:path :wearIndex ;
|
|
72
|
+
sh:minExclusive 0.15 ;
|
|
73
|
+
sh:severity sh:Warning ;
|
|
74
|
+
sh:message "Component with wearIndex <= 0.15: verify sensor calibration"
|
|
75
|
+
] .
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""The turbofan demo as tables in a database, the way a mapping reads your
|
|
2
|
+
data (OBDA): no RDF is loaded, the mapping reads the rows.
|
|
3
|
+
|
|
4
|
+
from prograph import ProGraph
|
|
5
|
+
from prograph.demos.turbofan.tables import duckdb_connection, mapping
|
|
6
|
+
engine = ProGraph(schema=mapping(), connection=duckdb_connection())
|
|
7
|
+
|
|
8
|
+
`rl_engine()` is the same engine with the ontology, an OWL 2 RL ontology,
|
|
9
|
+
materialized into an owned store (`docs/reference/owl-rl.md`).
|
|
10
|
+
|
|
11
|
+
`write_tables(connection)` writes the same tables into a DuckDB connection
|
|
12
|
+
you hold. The rows are the instance data's (`load.load_frames`), one table
|
|
13
|
+
per entry of `create_tables.sql`. `MAPPING_PATH` is the R2RML mapping of the
|
|
14
|
+
turbofan schema (`turbofan_schema.py` with `load.add_rdf_mappings`),
|
|
15
|
+
exported with DuckDB's quoting; `tests/demos/test_turbofan_tables.py` keeps
|
|
16
|
+
it equal to a fresh export.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Any, Optional
|
|
23
|
+
|
|
24
|
+
MAPPING_PATH = Path(__file__).parent / "mapping.r2rml.ttl"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def write_tables(connection: Any) -> list:
|
|
28
|
+
"""Write the turbofan tables into a DuckDB connection; their names."""
|
|
29
|
+
from prograph.demos.turbofan.load import add_rdf_mappings, load_frames
|
|
30
|
+
from prograph.demos.turbofan.turbofan_schema import create_turbofan_schema
|
|
31
|
+
frames = load_frames(add_rdf_mappings(create_turbofan_schema()))
|
|
32
|
+
for name, frame in frames.items():
|
|
33
|
+
view = f"_turbofan_{name}"
|
|
34
|
+
connection.register(view, frame)
|
|
35
|
+
# A column of Python Decimals with room for 18 digits at the data's own places, not the width
|
|
36
|
+
# DuckDB infers from the values (DECIMAL(2,2) for 0.82, which no later 1.3 fits).
|
|
37
|
+
from decimal import Decimal
|
|
38
|
+
|
|
39
|
+
def column(c: str) -> str:
|
|
40
|
+
values = [v for v in frame[c].dropna() if isinstance(v, Decimal)]
|
|
41
|
+
if not values:
|
|
42
|
+
return f'"{c}"'
|
|
43
|
+
places = max(max(-v.as_tuple().exponent, 0) for v in values)
|
|
44
|
+
return f'CAST("{c}" AS DECIMAL(18, {places})) AS "{c}"'
|
|
45
|
+
columns = ", ".join(column(c) for c in frame.columns)
|
|
46
|
+
connection.execute(f'CREATE OR REPLACE TABLE "{name}" AS SELECT {columns} FROM "{view}"')
|
|
47
|
+
connection.unregister(view)
|
|
48
|
+
return sorted(frames)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def duckdb_connection(path: Optional[str] = None) -> Any:
|
|
52
|
+
"""A DuckDB connection (in memory, or a database file) holding the
|
|
53
|
+
turbofan tables."""
|
|
54
|
+
import duckdb
|
|
55
|
+
connection = duckdb.connect(path or ":memory:")
|
|
56
|
+
write_tables(connection)
|
|
57
|
+
return connection
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def mapping() -> Any:
|
|
61
|
+
"""The turbofan mapping as a GraphSchema: the demo's schema
|
|
62
|
+
(`turbofan_schema.py`) with the ontology's class and predicate IRIs
|
|
63
|
+
(`load.add_rdf_mappings`), over the tables `write_tables` writes."""
|
|
64
|
+
from prograph.demos.turbofan.load import add_rdf_mappings
|
|
65
|
+
from prograph.demos.turbofan.turbofan_schema import create_turbofan_schema
|
|
66
|
+
return add_rdf_mappings(create_turbofan_schema())
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def rl_engine(connection: Any = None) -> Any:
|
|
70
|
+
"""The turbofan engine with OWL 2 RL entailment: the tables of
|
|
71
|
+
`duckdb_connection()` (or the DuckDB `connection` you pass, which
|
|
72
|
+
`write_tables` has filled), the mapping, the ontology, and an owned
|
|
73
|
+
store on the same connection. The entailed facts (`MonitoredComponent`
|
|
74
|
+
members, the closure of `isPartOf`, `hasPart`, `connectedTo`) are
|
|
75
|
+
written to the store's RL graph when the engine is built; call
|
|
76
|
+
`engine.materialize_entailments()` after the tables change."""
|
|
77
|
+
from prograph import ProGraph
|
|
78
|
+
from prograph.demos.turbofan import ONTOLOGY_PATH
|
|
79
|
+
from prograph.ontology import OntologyLayer
|
|
80
|
+
from prograph.store import Store
|
|
81
|
+
connection = connection if connection is not None else duckdb_connection()
|
|
82
|
+
return ProGraph(
|
|
83
|
+
schema=mapping(),
|
|
84
|
+
connection=connection,
|
|
85
|
+
store=Store(connection),
|
|
86
|
+
# An OWL 2 RL ontology: the strict default refuses nothing under profile "rl".
|
|
87
|
+
ontology=OntologyLayer.from_owl(str(ONTOLOGY_PATH)),
|
|
88
|
+
profile="rl",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def r2rml() -> str:
|
|
93
|
+
"""The turbofan R2RML mapping, as Turtle text."""
|
|
94
|
+
return MAPPING_PATH.read_text()
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def export_r2rml(dialect: str = "duckdb") -> str:
|
|
98
|
+
"""The R2RML mapping of the turbofan schema, exported now. Its
|
|
99
|
+
rr:sqlQuery texts are written in `dialect`'s quoting: `"duckdb"` for
|
|
100
|
+
MAPPING_PATH, `"spark"` for a Databricks SQL warehouse."""
|
|
101
|
+
from prograph.demos.turbofan import TURBOFAN_VOCAB_IRI
|
|
102
|
+
from prograph.demos.turbofan.load import add_rdf_mappings
|
|
103
|
+
from prograph.demos.turbofan.turbofan_schema import create_turbofan_schema
|
|
104
|
+
from prograph.r2rml.export import to_r2rml, to_turtle
|
|
105
|
+
schema = add_rdf_mappings(create_turbofan_schema())
|
|
106
|
+
return to_turtle(to_r2rml(schema, dialect=dialect, prefixes={"": TURBOFAN_VOCAB_IRI}))
|