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,163 @@
|
|
|
1
|
+
"""APOC Core's procedures in Cypher, as plans (rule cypher-apoc-procedures; design 261-apoc-procedures): a
|
|
2
|
+
procedure is not declared data (`cypher_procedures`); it computes from the graph, so each one here is a plan
|
|
3
|
+
built from the property-graph view and the source maps' homes, reached from `CALL apoc.x.y(...) YIELD ...`
|
|
4
|
+
by name. A builder takes the call's arguments (constants, or the node variable a path starts from) and gives
|
|
5
|
+
a plan whose columns are the procedure's outputs.
|
|
6
|
+
|
|
7
|
+
Built:
|
|
8
|
+
- apoc.meta.* (`cypher_apoc_meta`): schema, graph, stats, nodeTypeProperties, relTypeProperties, answered
|
|
9
|
+
from the view, a count from a COUNT over the maps' own scans, a property's type from the mapping's
|
|
10
|
+
declared type.
|
|
11
|
+
- apoc.path.* (`cypher_apoc_path`): subgraphNodes, subgraphAll, expand, expandConfig, spanningTree.
|
|
12
|
+
Refused by name: apoc.periodic.* (a write is one step), any other apoc.* procedure.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from dataclasses import dataclass
|
|
18
|
+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
|
|
19
|
+
|
|
20
|
+
from prograph.plan.ir import expr as E
|
|
21
|
+
from prograph.plan.ir import ops as O
|
|
22
|
+
from prograph.plan.ir.facts import NotBuilt
|
|
23
|
+
from prograph.rules import module_home
|
|
24
|
+
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from prograph.plan.ir.cypher_front import _Translator
|
|
27
|
+
|
|
28
|
+
module_home("cypher-apoc-procedures", "APOC Core's procedures in Cypher, as plans",
|
|
29
|
+
terms=("apoc.meta", "apoc.path", "apoc.periodic", "subgraphNodes", "subgraphAll", "expandConfig",
|
|
30
|
+
"spanningTree", "nodeTypeProperties", "relTypeProperties", "APOC procedure",
|
|
31
|
+
"relationshipFilter", "labelFilter"))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ApocProcedureError(NotBuilt):
|
|
35
|
+
"""An APOC procedure ProGraph does not translate, or a call of one it refuses by name."""
|
|
36
|
+
|
|
37
|
+
def __init__(self, procedure: str, why: str) -> None:
|
|
38
|
+
self.procedure = procedure
|
|
39
|
+
super().__init__(f"{procedure}: {why}")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass(frozen=True)
|
|
43
|
+
class Procedure:
|
|
44
|
+
"""A built APOC procedure: its name, its outputs as (name, type) pairs in APOC's order, the arities
|
|
45
|
+
its call takes, and its builder, `build(t, args, plan, var_of) -> plan`: the call's rows joined to the
|
|
46
|
+
rows before it (`plan`), each yielded output (`var_of`: output -> the variable it is yielded as) a new
|
|
47
|
+
variable of the translator `t`."""
|
|
48
|
+
name: str
|
|
49
|
+
outputs: Tuple[Tuple[str, str], ...]
|
|
50
|
+
arity: Tuple[int, ...]
|
|
51
|
+
build: Callable[..., Any]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
PROCEDURES: Dict[str, Procedure] = {}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def register(procedure: Procedure) -> None:
|
|
58
|
+
PROCEDURES[procedure.name] = procedure
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def lookup(name: str) -> Optional[Procedure]:
|
|
62
|
+
"""The built APOC procedure `name`, or None for a name outside `apoc.`; an apoc.* name no builder has
|
|
63
|
+
is refused by name."""
|
|
64
|
+
if not name.startswith("apoc."):
|
|
65
|
+
return None
|
|
66
|
+
_load()
|
|
67
|
+
found = PROCEDURES.get(name)
|
|
68
|
+
if found is not None:
|
|
69
|
+
return found
|
|
70
|
+
if name.startswith("apoc.periodic."):
|
|
71
|
+
raise ApocProcedureError(
|
|
72
|
+
name, "batched writes are not built: in ProGraph a write is one step (one statement, read once "
|
|
73
|
+
"and written once), so there is no batch to commit between; run the inner write as one "
|
|
74
|
+
"statement")
|
|
75
|
+
raise ApocProcedureError(name, "this APOC procedure is not built (apoc.meta.* and apoc.path.* are)")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _load() -> None:
|
|
79
|
+
if not PROCEDURES:
|
|
80
|
+
from prograph.plan.ir import cypher_apoc_meta, cypher_apoc_path # noqa: F401 (they register)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
_NONE = object()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _value(e: E.Expr) -> Any:
|
|
87
|
+
if isinstance(e, E.Const):
|
|
88
|
+
return e.value
|
|
89
|
+
if isinstance(e, E.Call) and e.name == "LIST":
|
|
90
|
+
parts = [_value(x) for x in e.args]
|
|
91
|
+
return _NONE if any(p is _NONE for p in parts) else parts
|
|
92
|
+
if isinstance(e, E.Call) and e.name == "MAP":
|
|
93
|
+
out = {}
|
|
94
|
+
for k, v in zip(e.args[0::2], e.args[1::2]):
|
|
95
|
+
value = _value(v)
|
|
96
|
+
if value is _NONE:
|
|
97
|
+
return _NONE
|
|
98
|
+
out[k.value] = value
|
|
99
|
+
return out
|
|
100
|
+
return _NONE
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def literal(e: E.Expr, procedure: str, what: str) -> Any:
|
|
104
|
+
"""The value of an argument written as a literal (a constant, or a map or list of them); a value read
|
|
105
|
+
at run time is a typed error."""
|
|
106
|
+
value = _value(e)
|
|
107
|
+
if value is _NONE:
|
|
108
|
+
raise ApocProcedureError(procedure, f"{what} must be written in the query (a constant); a value read "
|
|
109
|
+
"at run time would change which plan is built")
|
|
110
|
+
return value
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def finish(t: Any, plan: O.Op, op: O.Op, columns: Dict[str, str], var_of: Dict[str, str]) -> O.Op:
|
|
114
|
+
"""A procedure's rows `op` (its outputs in `columns`) as the yielded variables, joined to `plan`."""
|
|
115
|
+
for out, var in var_of.items():
|
|
116
|
+
op = O.Extend(op, var, E.Col(columns[out]))
|
|
117
|
+
op = O.Project(op, tuple(var_of.values()))
|
|
118
|
+
t.values |= set(var_of.values())
|
|
119
|
+
return op if isinstance(plan, O.Unit) else O.Join(plan, op)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def values(build: Callable[[Any, List[E.Expr]], Tuple[O.Op, Dict[str, str]]]) -> Callable[..., O.Op]:
|
|
123
|
+
"""A builder of a procedure whose outputs are values (no node or path): `build(t, args) -> (rows,
|
|
124
|
+
columns)`."""
|
|
125
|
+
def run(t: Any, args: List[E.Expr], plan: O.Op, var_of: Dict[str, str]) -> O.Op:
|
|
126
|
+
op, columns = build(t, args)
|
|
127
|
+
return finish(t, plan, op, columns, var_of)
|
|
128
|
+
return run
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def invoke(t: "_Translator", proc: Procedure, ctx: Any, plan: O.Op, standalone: bool) -> Any:
|
|
132
|
+
"""`CALL proc(args) [YIELD ...]` (in-query: the plan joined to the call's rows; standalone: a Query)."""
|
|
133
|
+
from prograph.plan.ir.cypher_front import Query, _aggregating
|
|
134
|
+
from prograph.plan.ir.cypher_procedures import Procedure as Declared, ProcedureError
|
|
135
|
+
if standalone:
|
|
136
|
+
t.prepare(ctx) # the translator's reads, which no clause before a standalone call set
|
|
137
|
+
explicit = ctx.oC_ExplicitProcedureInvocation()
|
|
138
|
+
if explicit is None and 0 not in proc.arity:
|
|
139
|
+
raise NotBuilt(f"{proc.name}: implicit arguments (they are the query's parameters)")
|
|
140
|
+
args: List[E.Expr] = []
|
|
141
|
+
for x in (explicit.oC_Expression() if explicit is not None else ()):
|
|
142
|
+
if _aggregating(x):
|
|
143
|
+
raise ProcedureError("InvalidAggregation: an aggregate in a procedure's argument")
|
|
144
|
+
args.append(t.expr(x))
|
|
145
|
+
if len(args) not in proc.arity:
|
|
146
|
+
raise ProcedureError(f"InvalidNumberOfArguments: {proc.name} takes {' or '.join(map(str, proc.arity))} "
|
|
147
|
+
f"argument(s), given {len(args)}")
|
|
148
|
+
declared = Declared(proc.name, (), proc.outputs, ())
|
|
149
|
+
items = ctx.oC_YieldItems()
|
|
150
|
+
if items is None and not standalone:
|
|
151
|
+
raise ProcedureError(f"UndefinedVariable: an in-query call of {proc.name} yields nothing")
|
|
152
|
+
pairs = t._yielded(declared, items) if items is not None else [(n, n) for n, _ in proc.outputs]
|
|
153
|
+
if standalone and items is not None and items.oC_Where() is not None:
|
|
154
|
+
raise NotBuilt("a standalone CALL's YIELD ... WHERE")
|
|
155
|
+
var_of = dict(pairs)
|
|
156
|
+
if len(set(var_of.values())) != len(pairs):
|
|
157
|
+
raise ProcedureError("VariableAlreadyBound: an output yielded twice")
|
|
158
|
+
out = proc.build(t, args, O.Unit() if standalone else plan, var_of)
|
|
159
|
+
if standalone:
|
|
160
|
+
return Query("select", O.Project(out, tuple(v for _, v in pairs)))
|
|
161
|
+
if items is not None and items.oC_Where() is not None:
|
|
162
|
+
out = t.where(out, items.oC_Where().oC_Expression())
|
|
163
|
+
return out
|