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,32 @@
|
|
|
1
|
+
"""engine-2001's whole graph, two ways: by following the ontology's part-of relation, and by a SHACL payload shape.
|
|
2
|
+
|
|
3
|
+
python -m prograph.demos.turbofan.instance_graph_demo [turtle|json-ld|json] [follow|follow+sensors|shape]
|
|
4
|
+
|
|
5
|
+
docs/demos/turbofan-instance-graph.md explains the ways and where they differ.
|
|
6
|
+
"""
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
import time
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from prograph.demos.turbofan.load import TURBOFAN_INSTANCE_IRI, build_engine
|
|
13
|
+
from prograph.extras.instance_graph import instance_graph
|
|
14
|
+
|
|
15
|
+
# ^:isPartOf: what is part of the engine (transitive in the ontology, so followed to its closure);
|
|
16
|
+
# ^:installedOn: the sensors installed on any of them
|
|
17
|
+
FOLLOW = {"follow": ["^:isPartOf"], "follow+sensors": ["^:isPartOf", "^:installedOn"]}
|
|
18
|
+
SHAPES = str(Path(__file__).with_name("payload-shapes.ttl"))
|
|
19
|
+
ROOT = TURBOFAN_INSTANCE_IRI + "engine-2001"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main(fmt: str = "turtle", mode: str = "follow") -> None:
|
|
23
|
+
engine = build_engine(with_ontology=True)
|
|
24
|
+
kwargs = {"follow": FOLLOW[mode]} if mode in FOLLOW else {"shapes": SHAPES}
|
|
25
|
+
start = time.time()
|
|
26
|
+
out = instance_graph(engine, ROOT, format=fmt, **kwargs)
|
|
27
|
+
print(json.dumps(out, indent=2) if fmt == "json" else out)
|
|
28
|
+
print(f"# {mode}, {fmt}: {time.time() - start:.1f} s", file=sys.stderr)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if __name__ == "__main__":
|
|
32
|
+
main(*sys.argv[1:3])
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""Load the turbofan instance data into the full 51-label schema.
|
|
2
|
+
|
|
3
|
+
``turbofan_schema.py`` (and ``graph.yaml``) describe ten node tables and
|
|
4
|
+
seventeen relationship tables. ``ProGraph.from_config`` can only fill
|
|
5
|
+
them from a Spark catalog. This module fills them from the canonical
|
|
6
|
+
instance data (``data/engine-instances.ttl``) as pandas DataFrames, so the
|
|
7
|
+
full schema runs locally on DuckDB:
|
|
8
|
+
|
|
9
|
+
from prograph.demos.turbofan.load import build_engine
|
|
10
|
+
|
|
11
|
+
engine = build_engine()
|
|
12
|
+
engine.execute(
|
|
13
|
+
"MATCH (c:Component) WHERE c.wear_index >= 0.7 RETURN c.id",
|
|
14
|
+
return_type="list",
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
``build_engine`` also declares how the ontology's IRIs reach the tables,
|
|
18
|
+
so the SPARQL queries can use the ontology's own terms:
|
|
19
|
+
|
|
20
|
+
- each node's IRI is the instance IRI from the Turtle file
|
|
21
|
+
(``http://example.org/engine-maintenance/instances#<id>``);
|
|
22
|
+
- each camelCase ontology predicate (``:wearIndex``, ``:isPartOf``) maps
|
|
23
|
+
to its snake_case column or UPPER_SNAKE relationship type;
|
|
24
|
+
- ``rdfs:label`` and ``rdfs:comment`` map to the ``label`` and
|
|
25
|
+
``comment`` columns.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
import re
|
|
31
|
+
from typing import Any, Dict, Optional
|
|
32
|
+
|
|
33
|
+
import pandas as pd
|
|
34
|
+
|
|
35
|
+
from prograph.demos.turbofan import INSTANCES_PATH, ONTOLOGY_PATH, TURBOFAN_VOCAB_IRI
|
|
36
|
+
from prograph.demos.turbofan.turbofan_schema import create_turbofan_schema
|
|
37
|
+
from prograph.schema import GraphSchema, PredicateKind, PredicateMapping
|
|
38
|
+
from prograph.schema.naming import column_from_local_name
|
|
39
|
+
|
|
40
|
+
#: Namespace of the instance IRIs in ``data/engine-instances.ttl``.
|
|
41
|
+
TURBOFAN_INSTANCE_IRI = "http://example.org/engine-maintenance/instances#"
|
|
42
|
+
|
|
43
|
+
_RDFS = "http://www.w3.org/2000/01/rdf-schema#"
|
|
44
|
+
|
|
45
|
+
# The schema abbreviates four module classes of the ontology: the label is
|
|
46
|
+
# the schema's (Cypher's ``:HPC``), the class IRI the ontology's
|
|
47
|
+
# (``:HighPressureCompressor``).
|
|
48
|
+
_SCHEMA_LABEL = {
|
|
49
|
+
"LowPressureCompressor": "LPC",
|
|
50
|
+
"HighPressureCompressor": "HPC",
|
|
51
|
+
"LowPressureTurbine": "LPT",
|
|
52
|
+
"HighPressureTurbine": "HPT",
|
|
53
|
+
}
|
|
54
|
+
_ONTOLOGY_CLASS = {label: cls for cls, label in _SCHEMA_LABEL.items()}
|
|
55
|
+
|
|
56
|
+
def _camel(name: str) -> str:
|
|
57
|
+
if "_" not in name and not name.isupper():
|
|
58
|
+
return name # already camelCase (``wearIndex``): lowercasing it named another predicate
|
|
59
|
+
head, *rest = name.lower().split("_")
|
|
60
|
+
return head + "".join(part.title() for part in rest)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _local_name(iri: str) -> str:
|
|
64
|
+
return re.split(r"[#/]", str(iri))[-1]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _rel_key(name: str) -> str:
|
|
68
|
+
"""``IS_PART_OF``, ``ISPARTOF`` and ``isPartOf`` all give ``ISPARTOF``."""
|
|
69
|
+
return name.replace("_", "").upper()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def load_frames(schema: Optional[GraphSchema] = None) -> Dict[str, pd.DataFrame]:
|
|
73
|
+
"""Read ``engine-instances.ttl`` into one DataFrame per schema table.
|
|
74
|
+
|
|
75
|
+
Node tables get an ``id`` column (the IRI's local name), a ``type``
|
|
76
|
+
column on the five shared tables, and every property column the schema
|
|
77
|
+
declares for that table (null where the data has no value).
|
|
78
|
+
Relationship tables get ``start_id`` and ``end_id``. Needs rdflib.
|
|
79
|
+
"""
|
|
80
|
+
from prograph.cli.ttl_loader import load_ttl
|
|
81
|
+
|
|
82
|
+
schema = schema or create_turbofan_schema()
|
|
83
|
+
per_class = load_ttl([str(INSTANCES_PATH)])
|
|
84
|
+
|
|
85
|
+
table_of_label = {m.label: m.source_table for m in schema.node_mappings}
|
|
86
|
+
typed_tables = {
|
|
87
|
+
m.source_table for m in schema.node_mappings if m.filter_predicate
|
|
88
|
+
}
|
|
89
|
+
columns_of_table: Dict[str, list] = {}
|
|
90
|
+
for m in schema.node_mappings:
|
|
91
|
+
cols = columns_of_table.setdefault(m.source_table, ["id"])
|
|
92
|
+
if m.filter_predicate and "type" not in cols:
|
|
93
|
+
cols.append("type")
|
|
94
|
+
for col in m.property_columns.values():
|
|
95
|
+
if col not in cols:
|
|
96
|
+
cols.append(col)
|
|
97
|
+
rel_table_of_key = {
|
|
98
|
+
_rel_key(r.rel_type): r.source_table for r in schema.relationship_mappings
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
node_rows: Dict[str, list] = {t: [] for t in columns_of_table}
|
|
102
|
+
rel_rows: Dict[str, list] = {t: [] for t in rel_table_of_key.values()}
|
|
103
|
+
|
|
104
|
+
for name, frame in per_class.items():
|
|
105
|
+
if "_start_uri" in frame.columns:
|
|
106
|
+
table = rel_table_of_key.get(_rel_key(name))
|
|
107
|
+
if table is None:
|
|
108
|
+
continue
|
|
109
|
+
for start, end in zip(frame["_start_uri"], frame["_end_uri"]):
|
|
110
|
+
rel_rows[table].append(
|
|
111
|
+
{"start_id": _local_name(start), "end_id": _local_name(end)}
|
|
112
|
+
)
|
|
113
|
+
continue
|
|
114
|
+
label = _SCHEMA_LABEL.get(name, name)
|
|
115
|
+
table = table_of_label.get(label)
|
|
116
|
+
if table is None or "_uri" not in frame.columns:
|
|
117
|
+
continue
|
|
118
|
+
for record in frame.to_dict("records"):
|
|
119
|
+
row: Dict[str, Any] = {"id": _local_name(record.pop("_uri"))}
|
|
120
|
+
for col, value in record.items():
|
|
121
|
+
row[column_from_local_name(col)] = None if _missing(value) else value
|
|
122
|
+
if table in typed_tables:
|
|
123
|
+
row["type"] = label
|
|
124
|
+
node_rows[table].append(row)
|
|
125
|
+
|
|
126
|
+
frames: Dict[str, pd.DataFrame] = {}
|
|
127
|
+
for table, rows in node_rows.items():
|
|
128
|
+
cols = columns_of_table[table]
|
|
129
|
+
frame = pd.DataFrame(rows, columns=None if rows else cols)
|
|
130
|
+
for col in cols:
|
|
131
|
+
if col not in frame.columns:
|
|
132
|
+
frame[col] = pd.Series([None] * len(frame), dtype=object)
|
|
133
|
+
elif frame[col].dtype == "float64" and any(r.get(col) is not None for r in rows) and all(
|
|
134
|
+
isinstance(r.get(col), int) for r in rows if r.get(col) is not None):
|
|
135
|
+
# Integers with gaps stay integers (pandas reads them as floats): the ontology's ranges are
|
|
136
|
+
# xsd:integer, and a double there is outside its value space (an inconsistency, dt-not-type).
|
|
137
|
+
frame[col] = frame[col].astype("Int64")
|
|
138
|
+
frames[table] = frame[cols]
|
|
139
|
+
for table, rows in rel_rows.items():
|
|
140
|
+
frames[table] = pd.DataFrame(rows, columns=["start_id", "end_id"])
|
|
141
|
+
return frames
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _missing(value: Any) -> bool:
|
|
145
|
+
from prograph.schema.types import is_missing
|
|
146
|
+
return is_missing(value)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def add_rdf_mappings(schema: GraphSchema) -> GraphSchema:
|
|
150
|
+
"""Give the schema the IRIs of the turbofan Turtle files.
|
|
151
|
+
|
|
152
|
+
Sets each node mapping's ``iri_template`` to the instance namespace,
|
|
153
|
+
its ``class_iri`` to the ontology's class of its label (the label
|
|
154
|
+
itself, but for the four the schema abbreviates: ``HPC`` is
|
|
155
|
+
``:HighPressureCompressor``), and declares a
|
|
156
|
+
``PredicateMapping`` for each ontology predicate, so SPARQL written
|
|
157
|
+
against ``ontology/engine-maintenance.ttl`` resolves: a class or
|
|
158
|
+
predicate IRI names only what is published under it.
|
|
159
|
+
"""
|
|
160
|
+
for mapping in schema.node_mappings:
|
|
161
|
+
mapping.iri_template = TURBOFAN_INSTANCE_IRI + "{id}"
|
|
162
|
+
if not mapping.class_iri:
|
|
163
|
+
mapping.class_iri = TURBOFAN_VOCAB_IRI + _ONTOLOGY_CLASS.get(
|
|
164
|
+
mapping.label, mapping.label)
|
|
165
|
+
declared = set()
|
|
166
|
+
for mapping in schema.node_mappings:
|
|
167
|
+
for prop in mapping.property_columns:
|
|
168
|
+
if prop in ("label", "comment"):
|
|
169
|
+
iri = _RDFS + prop
|
|
170
|
+
else:
|
|
171
|
+
iri = TURBOFAN_VOCAB_IRI + _camel(prop)
|
|
172
|
+
# Declared for every label that has the property, so a subject
|
|
173
|
+
# the query does not type is any of them: declared once, for
|
|
174
|
+
# the first label, `?s rdfs:label ?l` answered for the two
|
|
175
|
+
# engines of the 66 labelled things.
|
|
176
|
+
declared.add(iri)
|
|
177
|
+
schema.add_predicate_mapping(PredicateMapping(
|
|
178
|
+
predicate_iri=iri,
|
|
179
|
+
kind=PredicateKind.DATATYPE,
|
|
180
|
+
node_label=mapping.label,
|
|
181
|
+
property_name=prop,
|
|
182
|
+
))
|
|
183
|
+
for rel in schema.relationship_mappings:
|
|
184
|
+
iri = TURBOFAN_VOCAB_IRI + _camel(rel.rel_type)
|
|
185
|
+
if iri in declared:
|
|
186
|
+
continue
|
|
187
|
+
declared.add(iri)
|
|
188
|
+
schema.add_predicate_mapping(PredicateMapping(
|
|
189
|
+
predicate_iri=iri,
|
|
190
|
+
kind=PredicateKind.OBJECT,
|
|
191
|
+
relationship_type=rel.rel_type,
|
|
192
|
+
))
|
|
193
|
+
return schema
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def build_engine(
|
|
197
|
+
with_ontology: bool = False,
|
|
198
|
+
**kwargs: Any,
|
|
199
|
+
):
|
|
200
|
+
"""A DuckDB engine over the full turbofan schema and instance data.
|
|
201
|
+
|
|
202
|
+
Args:
|
|
203
|
+
with_ontology: attach ``ontology/engine-maintenance.ttl``, an OWL 2
|
|
204
|
+
RL ontology (transitive properties, property chains, functional
|
|
205
|
+
properties): the engine is ``tables.rl_engine()``, the same data
|
|
206
|
+
as DuckDB tables with ``profile="rl"`` and an owned store.
|
|
207
|
+
**kwargs: passed to ``ProGraph`` (``backend``).
|
|
208
|
+
"""
|
|
209
|
+
from prograph import ProGraph
|
|
210
|
+
|
|
211
|
+
if with_ontology:
|
|
212
|
+
if kwargs.get("backend", "duckdb") != "duckdb" or set(kwargs) - {"backend"}:
|
|
213
|
+
raise ValueError("build_engine(with_ontology=True) is tables.rl_engine(): DuckDB tables, an owned store "
|
|
214
|
+
"and profile='rl', with no other setting")
|
|
215
|
+
from prograph.demos.turbofan.tables import rl_engine
|
|
216
|
+
return rl_engine()
|
|
217
|
+
schema = add_rdf_mappings(create_turbofan_schema())
|
|
218
|
+
kwargs.setdefault("backend", "duckdb")
|
|
219
|
+
return ProGraph(
|
|
220
|
+
schema=schema,
|
|
221
|
+
dataframes=load_frames(schema),
|
|
222
|
+
**kwargs,
|
|
223
|
+
)
|