gql-core 0.2.0a1__tar.gz

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.
Files changed (112) hide show
  1. gql_core-0.2.0a1/LICENSE +176 -0
  2. gql_core-0.2.0a1/PKG-INFO +226 -0
  3. gql_core-0.2.0a1/README.md +190 -0
  4. gql_core-0.2.0a1/benchmark/__init__.py +0 -0
  5. gql_core-0.2.0a1/benchmark/cache/ldbc_snb_impls/postgres/scripts/load.py +78 -0
  6. gql_core-0.2.0a1/benchmark/cache/ldbc_snb_impls/postgres/scripts/test-db-connection.py +12 -0
  7. gql_core-0.2.0a1/benchmark/cache/ldbc_snb_impls/umbra/scripts/load.py +57 -0
  8. gql_core-0.2.0a1/benchmark/cache/ldbc_snb_impls/umbra/scripts/test-db-connection.py +12 -0
  9. gql_core-0.2.0a1/benchmark/gqlbench_eval.py +285 -0
  10. gql_core-0.2.0a1/benchmark/logical_reasoning.py +191 -0
  11. gql_core-0.2.0a1/benchmark/natural_queries.py +956 -0
  12. gql_core-0.2.0a1/benchmark/nl_to_gql.py +484 -0
  13. gql_core-0.2.0a1/benchmark/queries.py +141 -0
  14. gql_core-0.2.0a1/benchmark/query_suite.py +1527 -0
  15. gql_core-0.2.0a1/benchmark/run_nl_benchmark.py +287 -0
  16. gql_core-0.2.0a1/benchmark/run_suite_benchmark.py +385 -0
  17. gql_core-0.2.0a1/benchmark/snb/__init__.py +1 -0
  18. gql_core-0.2.0a1/benchmark/snb/download_sf01.py +66 -0
  19. gql_core-0.2.0a1/benchmark/snb/inventory.py +409 -0
  20. gql_core-0.2.0a1/benchmark/snb/loader.py +321 -0
  21. gql_core-0.2.0a1/benchmark/snb/oracle.py +366 -0
  22. gql_core-0.2.0a1/benchmark/snb/runner.py +371 -0
  23. gql_core-0.2.0a1/benchmark/snb/test_sf01_capacity.py +80 -0
  24. gql_core-0.2.0a1/benchmark/tck/__init__.py +1 -0
  25. gql_core-0.2.0a1/benchmark/tck/classifier.py +51 -0
  26. gql_core-0.2.0a1/benchmark/tck/fixture_loader.py +190 -0
  27. gql_core-0.2.0a1/benchmark/tck/gherkin_parser.py +912 -0
  28. gql_core-0.2.0a1/benchmark/tck/runner.py +267 -0
  29. gql_core-0.2.0a1/benchmark/tck/tck_adapter.py +782 -0
  30. gql_core-0.2.0a1/benchmark/vs_sqlite.py +340 -0
  31. gql_core-0.2.0a1/gql_core/__init__.py +185 -0
  32. gql_core-0.2.0a1/gql_core/ai.py +228 -0
  33. gql_core-0.2.0a1/gql_core/benchmark.py +402 -0
  34. gql_core-0.2.0a1/gql_core/builder.py +530 -0
  35. gql_core-0.2.0a1/gql_core/cli.py +369 -0
  36. gql_core-0.2.0a1/gql_core/errors.py +23 -0
  37. gql_core-0.2.0a1/gql_core/graph.py +449 -0
  38. gql_core-0.2.0a1/gql_core/inference/__init__.py +35 -0
  39. gql_core-0.2.0a1/gql_core/inference/engine.py +257 -0
  40. gql_core-0.2.0a1/gql_core/inference/rules.py +119 -0
  41. gql_core-0.2.0a1/gql_core/ingester.py +188 -0
  42. gql_core-0.2.0a1/gql_core/ir.py +901 -0
  43. gql_core-0.2.0a1/gql_core/mirror.py +220 -0
  44. gql_core-0.2.0a1/gql_core/ontology/__init__.py +22 -0
  45. gql_core-0.2.0a1/gql_core/ontology/model.py +75 -0
  46. gql_core-0.2.0a1/gql_core/ontology/schema.py +246 -0
  47. gql_core-0.2.0a1/gql_core/physical/__init__.py +16 -0
  48. gql_core-0.2.0a1/gql_core/physical/engine.py +231 -0
  49. gql_core-0.2.0a1/gql_core/physical/evaluator.py +1610 -0
  50. gql_core-0.2.0a1/gql_core/physical/operators.py +500 -0
  51. gql_core-0.2.0a1/gql_core/query/__init__.py +0 -0
  52. gql_core-0.2.0a1/gql_core/query/ast.py +211 -0
  53. gql_core-0.2.0a1/gql_core/query/cypher_temporal.py +1357 -0
  54. gql_core-0.2.0a1/gql_core/query/executor.py +2098 -0
  55. gql_core-0.2.0a1/gql_core/query/grammar.lark +216 -0
  56. gql_core-0.2.0a1/gql_core/query/parser.py +1002 -0
  57. gql_core-0.2.0a1/gql_core/query/planner.py +218 -0
  58. gql_core-0.2.0a1/gql_core/query/semantic.py +1017 -0
  59. gql_core-0.2.0a1/gql_core/query/static_types.py +387 -0
  60. gql_core-0.2.0a1/gql_core/registry.py +283 -0
  61. gql_core-0.2.0a1/gql_core/schema.py +27 -0
  62. gql_core-0.2.0a1/gql_core/temporal.py +508 -0
  63. gql_core-0.2.0a1/gql_core/types.py +172 -0
  64. gql_core-0.2.0a1/gql_core/validator.py +142 -0
  65. gql_core-0.2.0a1/gql_core/validator_ir.py +393 -0
  66. gql_core-0.2.0a1/gql_core.egg-info/PKG-INFO +226 -0
  67. gql_core-0.2.0a1/gql_core.egg-info/SOURCES.txt +110 -0
  68. gql_core-0.2.0a1/gql_core.egg-info/dependency_links.txt +1 -0
  69. gql_core-0.2.0a1/gql_core.egg-info/entry_points.txt +2 -0
  70. gql_core-0.2.0a1/gql_core.egg-info/requires.txt +14 -0
  71. gql_core-0.2.0a1/gql_core.egg-info/top_level.txt +5 -0
  72. gql_core-0.2.0a1/graph/__init__.py +0 -0
  73. gql_core-0.2.0a1/graph/store.py +424 -0
  74. gql_core-0.2.0a1/ingestion/__init__.py +0 -0
  75. gql_core-0.2.0a1/ingestion/cricsheet_parser.py +499 -0
  76. gql_core-0.2.0a1/ingestion/ids.py +98 -0
  77. gql_core-0.2.0a1/ingestion/validator.py +142 -0
  78. gql_core-0.2.0a1/pyproject.toml +72 -0
  79. gql_core-0.2.0a1/query/__init__.py +0 -0
  80. gql_core-0.2.0a1/query/ast.py +95 -0
  81. gql_core-0.2.0a1/query/executor.py +562 -0
  82. gql_core-0.2.0a1/query/grammar.lark +90 -0
  83. gql_core-0.2.0a1/query/parser.py +277 -0
  84. gql_core-0.2.0a1/query/planner.py +209 -0
  85. gql_core-0.2.0a1/query/semantic.py +241 -0
  86. gql_core-0.2.0a1/setup.cfg +4 -0
  87. gql_core-0.2.0a1/tests/test_adapters_and_ai.py +134 -0
  88. gql_core-0.2.0a1/tests/test_audit_regressions.py +356 -0
  89. gql_core-0.2.0a1/tests/test_benchmark.py +153 -0
  90. gql_core-0.2.0a1/tests/test_benchmark_runner.py +123 -0
  91. gql_core-0.2.0a1/tests/test_benchmark_smoke.py +80 -0
  92. gql_core-0.2.0a1/tests/test_boolean_and_quantifiers.py +237 -0
  93. gql_core-0.2.0a1/tests/test_examples.py +33 -0
  94. gql_core-0.2.0a1/tests/test_executor.py +262 -0
  95. gql_core-0.2.0a1/tests/test_executor_gaps.py +268 -0
  96. gql_core-0.2.0a1/tests/test_ids.py +76 -0
  97. gql_core-0.2.0a1/tests/test_ingester.py +124 -0
  98. gql_core-0.2.0a1/tests/test_logical_reasoning.py +211 -0
  99. gql_core-0.2.0a1/tests/test_mirror.py +87 -0
  100. gql_core-0.2.0a1/tests/test_natural_queries.py +397 -0
  101. gql_core-0.2.0a1/tests/test_ontology_and_inference.py +154 -0
  102. gql_core-0.2.0a1/tests/test_operator_benchmarks.py +147 -0
  103. gql_core-0.2.0a1/tests/test_parser.py +221 -0
  104. gql_core-0.2.0a1/tests/test_parser_grammar.py +113 -0
  105. gql_core-0.2.0a1/tests/test_regression.py +826 -0
  106. gql_core-0.2.0a1/tests/test_relational_and_set_algebra.py +212 -0
  107. gql_core-0.2.0a1/tests/test_release_gate_remediation.py +443 -0
  108. gql_core-0.2.0a1/tests/test_store.py +114 -0
  109. gql_core-0.2.0a1/tests/test_tck_harness_integrity.py +298 -0
  110. gql_core-0.2.0a1/tests/test_temporal_and_collections.py +132 -0
  111. gql_core-0.2.0a1/tests/test_typed_ir_and_validation.py +134 -0
  112. gql_core-0.2.0a1/tests/test_validator.py +220 -0
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,226 @@
1
+ Metadata-Version: 2.4
2
+ Name: gql-core
3
+ Version: 0.2.0a1
4
+ Summary: Experimental embedded property-graph query and typed reasoning engine for Python
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/qasimmughal03/knowledge-graoh-with-formal-query
7
+ Project-URL: Source, https://github.com/qasimmughal03/knowledge-graoh-with-formal-query
8
+ Project-URL: Documentation, https://github.com/qasimmughal03/knowledge-graoh-with-formal-query/blob/feat/implementation/docs/UNIFIED_DOCUMENTATION.md
9
+ Project-URL: Issues, https://github.com/qasimmughal03/knowledge-graoh-with-formal-query/issues
10
+ Keywords: graph,property-graph,query-engine,cypher,ontology,inference
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Database
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: lark>=1.2.2
24
+ Requires-Dist: pyyaml>=6.0.2
25
+ Requires-Dist: requests>=2.32.3
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=8.3.0; extra == "dev"
28
+ Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
29
+ Requires-Dist: networkx>=3.0; extra == "dev"
30
+ Requires-Dist: build>=1.2.2; extra == "dev"
31
+ Requires-Dist: twine>=5.1.1; extra == "dev"
32
+ Provides-Extra: benchmark
33
+ Requires-Dist: zstandard>=0.23.0; extra == "benchmark"
34
+ Requires-Dist: psutil>=5.9.0; extra == "benchmark"
35
+ Dynamic: license-file
36
+
37
+ # GQL-Core
38
+
39
+ **Embedded graph querying and typed logical reasoning for Python.**
40
+
41
+ GQL-Core is an experimental in-memory property-graph engine. Work with labeled nodes and relationships, execute a Cypher-inspired query language, build validated queries through a typed Python API, and derive relationships using declarative inference rules—without a separate database server.
42
+
43
+ **Version:** `0.2.0a1` · **Stage:** public alpha candidate · **License:** Apache-2.0 · **Python:** 3.11+
44
+
45
+ > **Alpha software.** GQL-Core is not a production database, a complete ISO/IEC 39075:2024 implementation, or a certified openCypher implementation. External compatibility scores describe a specific pinned test corpus, not universal query correctness.
46
+
47
+ ## Highlights
48
+
49
+ - **Graph storage:** in-memory nodes, directed relationships, multi-label nodes, properties, adjacency and label indexes.
50
+ - **Declarative queries:** matching, filtering, path traversal, grouping, sorting, `WITH`, `UNWIND`, selected updates, and built-in expressions.
51
+ - **Typed query plans:** compose `Scan`, `Expand`, `Filter`, `Project`, joins, set operators, quantified predicates, and aggregation through `PlanBuilder`.
52
+ - **Ontology reasoning:** explicit subtype, inverse, symmetric, transitive, and relationship-composition inference rules, with provenance.
53
+ - **Optional natural-language interface:** translate questions to query text using a configured LLM backend; formal execution itself does not require an LLM.
54
+ - **Reproducible evaluation:** openCypher TCK compatibility harness, LDBC SNB-derived workload, and pytest regression suite.
55
+
56
+ ## Install
57
+
58
+ The alpha is available from this repository. **Do not assume that `gql-core` is already published on PyPI.**
59
+
60
+ ```bash
61
+ git clone https://github.com/qasimmughal03/knowledge-graoh-with-formal-query.git
62
+ cd knowledge-graoh-with-formal-query
63
+ git checkout feat/implementation
64
+ python -m pip install -e .
65
+ gql-core --version
66
+ ```
67
+
68
+ For contributors:
69
+
70
+ ```bash
71
+ python -m pip install -e ".[dev,benchmark]"
72
+ ```
73
+
74
+ The runtime uses Lark, PyYAML, and Requests. NetworkX integration is optional. The `ask()` interface needs a compatible, available LLM service or client; it is not an offline heuristic answering system.
75
+
76
+ ## Quickstart: Python API
77
+
78
+ ```python
79
+ from gql_core import Edge, Node, PropertyGraph, run
80
+
81
+ graph = PropertyGraph()
82
+ graph.add_node(Node(id="alice", label="Person", props={"name": "Alice"}))
83
+ graph.add_node(Node(id="bob", label="Person", props={"name": "Bob"}))
84
+ graph.add_edge(Edge(id="e1", label="KNOWS", src="alice", dst="bob"))
85
+
86
+ rows = run(
87
+ "MATCH (a:Person)-[:KNOWS]->(b:Person) "
88
+ "WHERE a.name = 'Alice' RETURN b.name AS friend",
89
+ graph,
90
+ )
91
+ print(rows) # [{'friend': 'Bob'}]
92
+ ```
93
+
94
+ A runnable version is in [`examples/quickstart.py`](examples/quickstart.py).
95
+
96
+ ### Typed query plans
97
+
98
+ For LLM agents and Python applications, structured plans can be validated independently of text-query generation.
99
+
100
+ ```python
101
+ from gql_core import PlanBuilder, eq, execute_plan, lit, prop
102
+
103
+ plan = (
104
+ PlanBuilder.scan("p", "Person")
105
+ .filter(eq(prop("p", "name"), lit("Alice")))
106
+ .project((prop("p", "name"), "name"))
107
+ .build()
108
+ )
109
+ result = execute_plan(plan, graph)
110
+ print(result["rows"]) # [{'name': 'Alice'}]
111
+ ```
112
+
113
+ A standalone typed plan script is in [`examples/example_b_typed_plan.py`](examples/example_b_typed_plan.py).
114
+
115
+ ### Ontology inference
116
+
117
+ Derive new graph relationships declaratively using Datalog-style rules without modifying source facts:
118
+
119
+ ```python
120
+ from gql_core.inference import InferenceEngine, make_transitive_rule
121
+
122
+ # Derive transitive relationships: if A PART_OF B and B PART_OF C => A PART_OF C
123
+ engine = InferenceEngine()
124
+ engine.add_rule(make_transitive_rule("PART_OF"))
125
+
126
+ facts_by_rel, derived_facts = engine.infer(graph)
127
+ engine.materialize(graph) # Materializes inferred edges back into the graph
128
+ ```
129
+
130
+ A standalone inference script is in [`examples/example_c_ontology_inference.py`](examples/example_c_ontology_inference.py).
131
+
132
+ See the [typed query API](docs/TYPED_QUERY_API.md), [operator reference](docs/LOGICAL_OPERATOR_SPEC.md), and [ontology/inference guide](docs/INFERENCE_ENGINE.md).
133
+
134
+ ## Quickstart: CLI
135
+
136
+ A small example dataset is included so this command runs after installing the package from a repository checkout:
137
+
138
+ ```bash
139
+ gql-core query --data examples/sample_graph.json \
140
+ "MATCH (p:Person) RETURN p.name AS name ORDER BY name ASC"
141
+ ```
142
+
143
+ Available commands: `query`, `ask`, `validate`, `ingest`, `mirror`, `benchmark`, and `version`. Use `gql-core --help` for the authoritative argument list. The CLI command is **`query`**, not `run`.
144
+
145
+ For the natural-language command, set up an Ollama-compatible backend or supply a client through the Python API. `gql-core ask` does not automatically provide a hosted model.
146
+
147
+ ## Project structure
148
+
149
+ | Directory/module | Purpose |
150
+ | --- | --- |
151
+ | `gql_core/graph.py` | `PropertyGraph`, `Node`, `Edge`, `Path`, graph adapters |
152
+ | `gql_core/query/` | Grammar, parser, semantic validation, query execution |
153
+ | `gql_core/ir.py`, `builder.py` | Typed expressions, logical operators, fluent plan building |
154
+ | `gql_core/physical/` | Expression evaluation and physical execution |
155
+ | `gql_core/ontology/`, `inference/` | Typed ontology schemas and rule-based inference |
156
+ | `gql_core/ai.py` | Optional question-to-query translation |
157
+ | `benchmark/tck/` | openCypher compatibility checking |
158
+ | `benchmark/snb/` | LDBC social-network workload support |
159
+ | `examples/` | Standalone quickstart and domain examples |
160
+ | `docs/` | Technical contracts, architecture, benchmark and release reports |
161
+
162
+ ### Graph adapters
163
+
164
+ Use `PropertyGraph.from_records(nodes, edges)`, `PropertyGraph.from_edges(...)`, or `PropertyGraph.from_networkx(G)` (requires `networkx`). For the CLI's graph JSON format, see [`examples/sample_graph.json`](examples/sample_graph.json).
165
+
166
+ `from_dict` expects an object containing `nodes` and `edges` arrays; it is **not** an adjacency-dictionary adapter.
167
+
168
+ ## Supported functionality and boundaries
169
+
170
+ GQL-Core implements a substantial, evolving subset of Cypher-like patterns and expressions, including multi-clause pipelines and mutations. Its typed plan API additionally exposes relational algebra and graph reasoning primitives. **The two APIs do not have identical coverage.**
171
+
172
+ Not all openCypher syntax is supported. In particular, the release documents exclude certain nested correlated `EXISTS` text expressions and relationship-type disjunctions. Consult [the supported query contract](docs/SUPPORTED_QUERY_CONTRACT.md) for exact syntax and behavior.
173
+
174
+ Execution semantics include relationship trail uniqueness, three-valued Boolean logic, null propagation, and bag/multiset behavior where applicable. The graph is held in memory; it does not provide database durability, transactional isolation, or distributed execution. Concurrent mutations require application-level synchronization.
175
+
176
+ ## Benchmarks and correctness
177
+
178
+ The latest repository [release correctness report](docs/RELEASE_CORRECTNESS_REPORT.md) documents results on the pinned openCypher TCK `2024.3` corpus:
179
+
180
+ | Reported evaluation | Result |
181
+ | --- | ---: |
182
+ | Expanded TCK scenarios, including Scenario Outlines | 3,897 |
183
+ | Scenarios classified as supported | 3,879 |
184
+ | Strict scenario passes in that subset | **3,879 / 3,879** |
185
+ | Explicitly excluded scenarios | 18 |
186
+ | Project unit/regression tests | **341 / 341** |
187
+ | Official LDBC SNB SF0.1 query parameter cases | **4 / 4** across **2 official query types** |
188
+
189
+ **Interpretation:** These are version- and harness-scoped results reported by the project, not ISO certification, complete Cypher conformance, or evidence of production reliability. The LDBC study is **unaudited**, covers a limited read-query subset, and reports adapted additional queries separately from official equivalent operations.
190
+
191
+ The latest reported SF0.1 graph contains 327,588 nodes and 1,477,965 relationships. Measurements depend on the exact dataset, machine, source commit, and workload; see [LDBC coverage](docs/LDBC_QUERY_COVERAGE.md) before comparing latency.
192
+
193
+ The TCK repository and large benchmark datasets are external assets, not bundled in the Python wheel. See [packaging and verification](docs/PACKAGING.md) for how to run checks. Do not compare TCK correctness percentages with LDBC query latency.
194
+
195
+ ## Build and release verification
196
+
197
+ ```bash
198
+ python -m pip install -e ".[dev,benchmark]"
199
+ python -m pytest tests/
200
+ python -m build
201
+ python -m twine check dist/*
202
+ ```
203
+
204
+ The test suite uses upstream TCK fixtures; see [`docs/PACKAGING.md`](docs/PACKAGING.md) for the required preparation and wheel smoke test. CI verifies the distribution in an isolated Python environment. Uploading to TestPyPI or PyPI is a **separate manual step**, not part of CI.
205
+
206
+ ## Documentation
207
+
208
+ - [Unified architecture and verification report](docs/UNIFIED_DOCUMENTATION.md)
209
+ - [Quickstart walkthrough](docs/QUICKSTART.md)
210
+ - [Python API reference](docs/API_REFERENCE.md)
211
+ - [Supported textual query contract](docs/SUPPORTED_QUERY_CONTRACT.md)
212
+ - [Typed Python query API](docs/TYPED_QUERY_API.md)
213
+ - [Ontology and inference](docs/INFERENCE_ENGINE.md)
214
+ - [Logical operator specification](docs/LOGICAL_OPERATOR_SPEC.md)
215
+ - [Release correctness report](docs/RELEASE_CORRECTNESS_REPORT.md)
216
+ - [TCK scenario failures and methodology](docs/TCK_FAILURE_ANALYSIS.md)
217
+ - [Packaging and release checklist](docs/PACKAGING.md)
218
+ - [Release notes (v0.2.0a1)](docs/RELEASE_NOTES_0.2.0a1.md)
219
+
220
+ ## Contributing
221
+
222
+ Open an issue with a minimal graph, the exact query/plan, expected output, actual output, Python version, and relevant stack trace. New operators and bug fixes should come with regression tests and, where applicable, a compatibility scenario.
223
+
224
+ ## License
225
+
226
+ [Apache License 2.0](LICENSE). GQL-Core is an independent project. Referencing ISO, openCypher, Neo4j, or LDBC does not imply affiliation or official certification.
@@ -0,0 +1,190 @@
1
+ # GQL-Core
2
+
3
+ **Embedded graph querying and typed logical reasoning for Python.**
4
+
5
+ GQL-Core is an experimental in-memory property-graph engine. Work with labeled nodes and relationships, execute a Cypher-inspired query language, build validated queries through a typed Python API, and derive relationships using declarative inference rules—without a separate database server.
6
+
7
+ **Version:** `0.2.0a1` · **Stage:** public alpha candidate · **License:** Apache-2.0 · **Python:** 3.11+
8
+
9
+ > **Alpha software.** GQL-Core is not a production database, a complete ISO/IEC 39075:2024 implementation, or a certified openCypher implementation. External compatibility scores describe a specific pinned test corpus, not universal query correctness.
10
+
11
+ ## Highlights
12
+
13
+ - **Graph storage:** in-memory nodes, directed relationships, multi-label nodes, properties, adjacency and label indexes.
14
+ - **Declarative queries:** matching, filtering, path traversal, grouping, sorting, `WITH`, `UNWIND`, selected updates, and built-in expressions.
15
+ - **Typed query plans:** compose `Scan`, `Expand`, `Filter`, `Project`, joins, set operators, quantified predicates, and aggregation through `PlanBuilder`.
16
+ - **Ontology reasoning:** explicit subtype, inverse, symmetric, transitive, and relationship-composition inference rules, with provenance.
17
+ - **Optional natural-language interface:** translate questions to query text using a configured LLM backend; formal execution itself does not require an LLM.
18
+ - **Reproducible evaluation:** openCypher TCK compatibility harness, LDBC SNB-derived workload, and pytest regression suite.
19
+
20
+ ## Install
21
+
22
+ The alpha is available from this repository. **Do not assume that `gql-core` is already published on PyPI.**
23
+
24
+ ```bash
25
+ git clone https://github.com/qasimmughal03/knowledge-graoh-with-formal-query.git
26
+ cd knowledge-graoh-with-formal-query
27
+ git checkout feat/implementation
28
+ python -m pip install -e .
29
+ gql-core --version
30
+ ```
31
+
32
+ For contributors:
33
+
34
+ ```bash
35
+ python -m pip install -e ".[dev,benchmark]"
36
+ ```
37
+
38
+ The runtime uses Lark, PyYAML, and Requests. NetworkX integration is optional. The `ask()` interface needs a compatible, available LLM service or client; it is not an offline heuristic answering system.
39
+
40
+ ## Quickstart: Python API
41
+
42
+ ```python
43
+ from gql_core import Edge, Node, PropertyGraph, run
44
+
45
+ graph = PropertyGraph()
46
+ graph.add_node(Node(id="alice", label="Person", props={"name": "Alice"}))
47
+ graph.add_node(Node(id="bob", label="Person", props={"name": "Bob"}))
48
+ graph.add_edge(Edge(id="e1", label="KNOWS", src="alice", dst="bob"))
49
+
50
+ rows = run(
51
+ "MATCH (a:Person)-[:KNOWS]->(b:Person) "
52
+ "WHERE a.name = 'Alice' RETURN b.name AS friend",
53
+ graph,
54
+ )
55
+ print(rows) # [{'friend': 'Bob'}]
56
+ ```
57
+
58
+ A runnable version is in [`examples/quickstart.py`](examples/quickstart.py).
59
+
60
+ ### Typed query plans
61
+
62
+ For LLM agents and Python applications, structured plans can be validated independently of text-query generation.
63
+
64
+ ```python
65
+ from gql_core import PlanBuilder, eq, execute_plan, lit, prop
66
+
67
+ plan = (
68
+ PlanBuilder.scan("p", "Person")
69
+ .filter(eq(prop("p", "name"), lit("Alice")))
70
+ .project((prop("p", "name"), "name"))
71
+ .build()
72
+ )
73
+ result = execute_plan(plan, graph)
74
+ print(result["rows"]) # [{'name': 'Alice'}]
75
+ ```
76
+
77
+ A standalone typed plan script is in [`examples/example_b_typed_plan.py`](examples/example_b_typed_plan.py).
78
+
79
+ ### Ontology inference
80
+
81
+ Derive new graph relationships declaratively using Datalog-style rules without modifying source facts:
82
+
83
+ ```python
84
+ from gql_core.inference import InferenceEngine, make_transitive_rule
85
+
86
+ # Derive transitive relationships: if A PART_OF B and B PART_OF C => A PART_OF C
87
+ engine = InferenceEngine()
88
+ engine.add_rule(make_transitive_rule("PART_OF"))
89
+
90
+ facts_by_rel, derived_facts = engine.infer(graph)
91
+ engine.materialize(graph) # Materializes inferred edges back into the graph
92
+ ```
93
+
94
+ A standalone inference script is in [`examples/example_c_ontology_inference.py`](examples/example_c_ontology_inference.py).
95
+
96
+ See the [typed query API](docs/TYPED_QUERY_API.md), [operator reference](docs/LOGICAL_OPERATOR_SPEC.md), and [ontology/inference guide](docs/INFERENCE_ENGINE.md).
97
+
98
+ ## Quickstart: CLI
99
+
100
+ A small example dataset is included so this command runs after installing the package from a repository checkout:
101
+
102
+ ```bash
103
+ gql-core query --data examples/sample_graph.json \
104
+ "MATCH (p:Person) RETURN p.name AS name ORDER BY name ASC"
105
+ ```
106
+
107
+ Available commands: `query`, `ask`, `validate`, `ingest`, `mirror`, `benchmark`, and `version`. Use `gql-core --help` for the authoritative argument list. The CLI command is **`query`**, not `run`.
108
+
109
+ For the natural-language command, set up an Ollama-compatible backend or supply a client through the Python API. `gql-core ask` does not automatically provide a hosted model.
110
+
111
+ ## Project structure
112
+
113
+ | Directory/module | Purpose |
114
+ | --- | --- |
115
+ | `gql_core/graph.py` | `PropertyGraph`, `Node`, `Edge`, `Path`, graph adapters |
116
+ | `gql_core/query/` | Grammar, parser, semantic validation, query execution |
117
+ | `gql_core/ir.py`, `builder.py` | Typed expressions, logical operators, fluent plan building |
118
+ | `gql_core/physical/` | Expression evaluation and physical execution |
119
+ | `gql_core/ontology/`, `inference/` | Typed ontology schemas and rule-based inference |
120
+ | `gql_core/ai.py` | Optional question-to-query translation |
121
+ | `benchmark/tck/` | openCypher compatibility checking |
122
+ | `benchmark/snb/` | LDBC social-network workload support |
123
+ | `examples/` | Standalone quickstart and domain examples |
124
+ | `docs/` | Technical contracts, architecture, benchmark and release reports |
125
+
126
+ ### Graph adapters
127
+
128
+ Use `PropertyGraph.from_records(nodes, edges)`, `PropertyGraph.from_edges(...)`, or `PropertyGraph.from_networkx(G)` (requires `networkx`). For the CLI's graph JSON format, see [`examples/sample_graph.json`](examples/sample_graph.json).
129
+
130
+ `from_dict` expects an object containing `nodes` and `edges` arrays; it is **not** an adjacency-dictionary adapter.
131
+
132
+ ## Supported functionality and boundaries
133
+
134
+ GQL-Core implements a substantial, evolving subset of Cypher-like patterns and expressions, including multi-clause pipelines and mutations. Its typed plan API additionally exposes relational algebra and graph reasoning primitives. **The two APIs do not have identical coverage.**
135
+
136
+ Not all openCypher syntax is supported. In particular, the release documents exclude certain nested correlated `EXISTS` text expressions and relationship-type disjunctions. Consult [the supported query contract](docs/SUPPORTED_QUERY_CONTRACT.md) for exact syntax and behavior.
137
+
138
+ Execution semantics include relationship trail uniqueness, three-valued Boolean logic, null propagation, and bag/multiset behavior where applicable. The graph is held in memory; it does not provide database durability, transactional isolation, or distributed execution. Concurrent mutations require application-level synchronization.
139
+
140
+ ## Benchmarks and correctness
141
+
142
+ The latest repository [release correctness report](docs/RELEASE_CORRECTNESS_REPORT.md) documents results on the pinned openCypher TCK `2024.3` corpus:
143
+
144
+ | Reported evaluation | Result |
145
+ | --- | ---: |
146
+ | Expanded TCK scenarios, including Scenario Outlines | 3,897 |
147
+ | Scenarios classified as supported | 3,879 |
148
+ | Strict scenario passes in that subset | **3,879 / 3,879** |
149
+ | Explicitly excluded scenarios | 18 |
150
+ | Project unit/regression tests | **341 / 341** |
151
+ | Official LDBC SNB SF0.1 query parameter cases | **4 / 4** across **2 official query types** |
152
+
153
+ **Interpretation:** These are version- and harness-scoped results reported by the project, not ISO certification, complete Cypher conformance, or evidence of production reliability. The LDBC study is **unaudited**, covers a limited read-query subset, and reports adapted additional queries separately from official equivalent operations.
154
+
155
+ The latest reported SF0.1 graph contains 327,588 nodes and 1,477,965 relationships. Measurements depend on the exact dataset, machine, source commit, and workload; see [LDBC coverage](docs/LDBC_QUERY_COVERAGE.md) before comparing latency.
156
+
157
+ The TCK repository and large benchmark datasets are external assets, not bundled in the Python wheel. See [packaging and verification](docs/PACKAGING.md) for how to run checks. Do not compare TCK correctness percentages with LDBC query latency.
158
+
159
+ ## Build and release verification
160
+
161
+ ```bash
162
+ python -m pip install -e ".[dev,benchmark]"
163
+ python -m pytest tests/
164
+ python -m build
165
+ python -m twine check dist/*
166
+ ```
167
+
168
+ The test suite uses upstream TCK fixtures; see [`docs/PACKAGING.md`](docs/PACKAGING.md) for the required preparation and wheel smoke test. CI verifies the distribution in an isolated Python environment. Uploading to TestPyPI or PyPI is a **separate manual step**, not part of CI.
169
+
170
+ ## Documentation
171
+
172
+ - [Unified architecture and verification report](docs/UNIFIED_DOCUMENTATION.md)
173
+ - [Quickstart walkthrough](docs/QUICKSTART.md)
174
+ - [Python API reference](docs/API_REFERENCE.md)
175
+ - [Supported textual query contract](docs/SUPPORTED_QUERY_CONTRACT.md)
176
+ - [Typed Python query API](docs/TYPED_QUERY_API.md)
177
+ - [Ontology and inference](docs/INFERENCE_ENGINE.md)
178
+ - [Logical operator specification](docs/LOGICAL_OPERATOR_SPEC.md)
179
+ - [Release correctness report](docs/RELEASE_CORRECTNESS_REPORT.md)
180
+ - [TCK scenario failures and methodology](docs/TCK_FAILURE_ANALYSIS.md)
181
+ - [Packaging and release checklist](docs/PACKAGING.md)
182
+ - [Release notes (v0.2.0a1)](docs/RELEASE_NOTES_0.2.0a1.md)
183
+
184
+ ## Contributing
185
+
186
+ Open an issue with a minimal graph, the exact query/plan, expected output, actual output, Python version, and relevant stack trace. New operators and bug fixes should come with regression tests and, where applicable, a compatibility scenario.
187
+
188
+ ## License
189
+
190
+ [Apache License 2.0](LICENSE). GQL-Core is an independent project. Referencing ISO, openCypher, Neo4j, or LDBC does not imply affiliation or official certification.
File without changes
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import os
4
+ import psycopg
5
+ import re
6
+ import time
7
+
8
+ class PostgresDbLoader():
9
+
10
+ def __init__(self):
11
+ self.database = os.environ.get("POSTGRES_DB", "ldbcsnb")
12
+ self.endpoint = os.environ.get("POSTGRES_HOST", "localhost")
13
+ self.port = int(os.environ.get("POSTGRES_PORT", 5432))
14
+ self.user = os.environ.get("POSTGRES_USER", "postgres")
15
+ self.password = os.environ.get("POSTGRES_PASSWORD", "mysecretpassword")
16
+
17
+
18
+ def run_script(self, conn, filename):
19
+
20
+ with open(filename, "r") as f:
21
+ try:
22
+ queries_file = f.read()
23
+ # strip comments
24
+ queries_file = re.sub(r"(\n|^)--.*", "", queries_file)
25
+ queries = queries_file.split(";")
26
+ for query in queries:
27
+ if query.isspace():
28
+ continue
29
+
30
+ sql_statement = re.findall(r"^((CREATE|INSERT|DROP|DELETE|SELECT|COPY|ALTER) [A-Za-z0-9_ ]*)", query, re.MULTILINE|re.IGNORECASE)
31
+ print(f"{sql_statement[0][0].strip()} ...")
32
+ start = time.time()
33
+ cur = conn.cursor()
34
+ cur.execute(query)
35
+ conn.commit()
36
+ end = time.time()
37
+ duration = end - start
38
+ print(f"-> {duration:.4f} seconds")
39
+ except Exception:
40
+ print(f"Error trying to execute query: {query};")
41
+ raise
42
+
43
+
44
+ def vacuum(self, conn):
45
+ conn.autocommit=True
46
+ conn.cursor().execute("ANALYZE")
47
+ conn.autocommit=False
48
+
49
+
50
+ def main(self):
51
+ with psycopg.connect(
52
+ dbname=self.database,
53
+ host=self.endpoint,
54
+ user=self.user,
55
+ password=self.password,
56
+ port=self.port
57
+ ) as conn:
58
+ print("Loading initial data set")
59
+ self.run_script(conn, "ddl/schema.sql")
60
+ self.run_script(conn, "ddl/load.sql")
61
+
62
+ print("Adding indexes and constraints")
63
+ self.run_script(conn, "ddl/schema_constraints.sql")
64
+ self.run_script(conn, "ddl/schema_foreign_keys.sql")
65
+
66
+ print("Vacuuming")
67
+ self.vacuum(conn)
68
+ conn.commit()
69
+ print("Loaded initial snapshot")
70
+
71
+ def load_script(self, filename):
72
+ with open(filename, "r") as f:
73
+ return f.read()
74
+
75
+
76
+ if __name__ == "__main__":
77
+ PGLoader = PostgresDbLoader()
78
+ PGLoader.main()