knowledgecomplex 0.1.0__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 (92) hide show
  1. knowledgecomplex-0.1.0/.github/workflows/ci.yml +28 -0
  2. knowledgecomplex-0.1.0/.github/workflows/docs.yml +24 -0
  3. knowledgecomplex-0.1.0/.github/workflows/publish.yml +30 -0
  4. knowledgecomplex-0.1.0/.gitignore +14 -0
  5. knowledgecomplex-0.1.0/ARCHITECTURE.md +267 -0
  6. knowledgecomplex-0.1.0/LICENSE +201 -0
  7. knowledgecomplex-0.1.0/PKG-INFO +442 -0
  8. knowledgecomplex-0.1.0/README.md +209 -0
  9. knowledgecomplex-0.1.0/docs/api/analysis.md +1 -0
  10. knowledgecomplex-0.1.0/docs/api/clique.md +1 -0
  11. knowledgecomplex-0.1.0/docs/api/codecs.md +1 -0
  12. knowledgecomplex-0.1.0/docs/api/diff.md +1 -0
  13. knowledgecomplex-0.1.0/docs/api/exceptions.md +3 -0
  14. knowledgecomplex-0.1.0/docs/api/filtration.md +1 -0
  15. knowledgecomplex-0.1.0/docs/api/graph.md +3 -0
  16. knowledgecomplex-0.1.0/docs/api/io.md +1 -0
  17. knowledgecomplex-0.1.0/docs/api/schema.md +3 -0
  18. knowledgecomplex-0.1.0/docs/api/viz.md +1 -0
  19. knowledgecomplex-0.1.0/docs/index.md +81 -0
  20. knowledgecomplex-0.1.0/docs/ontology.md +31 -0
  21. knowledgecomplex-0.1.0/examples/01_quickstart/_setup_data.py +34 -0
  22. knowledgecomplex-0.1.0/examples/01_quickstart/data/pipeline/instance.ttl +168 -0
  23. knowledgecomplex-0.1.0/examples/01_quickstart/data/pipeline/ontology.ttl +120 -0
  24. knowledgecomplex-0.1.0/examples/01_quickstart/data/pipeline/shapes.ttl +173 -0
  25. knowledgecomplex-0.1.0/examples/01_quickstart/output/geometric.png +0 -0
  26. knowledgecomplex-0.1.0/examples/01_quickstart/output/hasse.png +0 -0
  27. knowledgecomplex-0.1.0/examples/01_quickstart/quickstart.py +129 -0
  28. knowledgecomplex-0.1.0/examples/02_construction/construction.py +114 -0
  29. knowledgecomplex-0.1.0/examples/02_construction/output/geometric.png +0 -0
  30. knowledgecomplex-0.1.0/examples/02_construction/output/hasse.png +0 -0
  31. knowledgecomplex-0.1.0/examples/02_construction/output/hasse_star_alice.png +0 -0
  32. knowledgecomplex-0.1.0/examples/03_topology/topology_walkthrough.py +125 -0
  33. knowledgecomplex-0.1.0/examples/04_clique_inference/clique_inference.py +118 -0
  34. knowledgecomplex-0.1.0/examples/04_clique_inference/output/geometric.png +0 -0
  35. knowledgecomplex-0.1.0/examples/04_clique_inference/output/hasse.png +0 -0
  36. knowledgecomplex-0.1.0/examples/05_constraints/constraints.py +105 -0
  37. knowledgecomplex-0.1.0/examples/06_io_roundtrip/io_roundtrip.py +109 -0
  38. knowledgecomplex-0.1.0/examples/07_filtration/filtration_evolution.py +140 -0
  39. knowledgecomplex-0.1.0/examples/08_temporal_sweep/temporal_sweep.py +142 -0
  40. knowledgecomplex-0.1.0/examples/09_diff_sequence/diff_sequence.py +146 -0
  41. knowledgecomplex-0.1.0/examples/10_markdown_codec/markdown_codec.py +266 -0
  42. knowledgecomplex-0.1.0/examples/README.md +28 -0
  43. knowledgecomplex-0.1.0/knowledgecomplex/__init__.py +91 -0
  44. knowledgecomplex-0.1.0/knowledgecomplex/analysis.py +1177 -0
  45. knowledgecomplex-0.1.0/knowledgecomplex/audit.py +173 -0
  46. knowledgecomplex-0.1.0/knowledgecomplex/clique.py +399 -0
  47. knowledgecomplex-0.1.0/knowledgecomplex/codecs/__init__.py +9 -0
  48. knowledgecomplex-0.1.0/knowledgecomplex/codecs/markdown.py +220 -0
  49. knowledgecomplex-0.1.0/knowledgecomplex/diff.py +429 -0
  50. knowledgecomplex-0.1.0/knowledgecomplex/exceptions.py +38 -0
  51. knowledgecomplex-0.1.0/knowledgecomplex/filtration.py +226 -0
  52. knowledgecomplex-0.1.0/knowledgecomplex/graph.py +1107 -0
  53. knowledgecomplex-0.1.0/knowledgecomplex/io.py +167 -0
  54. knowledgecomplex-0.1.0/knowledgecomplex/ontologies/README.md +182 -0
  55. knowledgecomplex-0.1.0/knowledgecomplex/ontologies/__init__.py +24 -0
  56. knowledgecomplex-0.1.0/knowledgecomplex/ontologies/brand.py +67 -0
  57. knowledgecomplex-0.1.0/knowledgecomplex/ontologies/operations.py +44 -0
  58. knowledgecomplex-0.1.0/knowledgecomplex/ontologies/research.py +73 -0
  59. knowledgecomplex-0.1.0/knowledgecomplex/queries/boundary.sparql +17 -0
  60. knowledgecomplex-0.1.0/knowledgecomplex/queries/closure.sparql +18 -0
  61. knowledgecomplex-0.1.0/knowledgecomplex/queries/coboundary.sparql +16 -0
  62. knowledgecomplex-0.1.0/knowledgecomplex/queries/degree.sparql +12 -0
  63. knowledgecomplex-0.1.0/knowledgecomplex/queries/skeleton.sparql +17 -0
  64. knowledgecomplex-0.1.0/knowledgecomplex/queries/star.sparql +19 -0
  65. knowledgecomplex-0.1.0/knowledgecomplex/queries/vertices.sparql +13 -0
  66. knowledgecomplex-0.1.0/knowledgecomplex/resources/kc_core.ttl +140 -0
  67. knowledgecomplex-0.1.0/knowledgecomplex/resources/kc_core_shapes.ttl +191 -0
  68. knowledgecomplex-0.1.0/knowledgecomplex/schema.py +1142 -0
  69. knowledgecomplex-0.1.0/knowledgecomplex/viz.py +786 -0
  70. knowledgecomplex-0.1.0/mkdocs.yml +28 -0
  71. knowledgecomplex-0.1.0/pyproject.toml +33 -0
  72. knowledgecomplex-0.1.0/tests/__init__.py +0 -0
  73. knowledgecomplex-0.1.0/tests/test_analysis.py +408 -0
  74. knowledgecomplex-0.1.0/tests/test_audit.py +191 -0
  75. knowledgecomplex-0.1.0/tests/test_clique.py +236 -0
  76. knowledgecomplex-0.1.0/tests/test_codec.py +310 -0
  77. knowledgecomplex-0.1.0/tests/test_core_owl.py +92 -0
  78. knowledgecomplex-0.1.0/tests/test_core_shacl.py +202 -0
  79. knowledgecomplex-0.1.0/tests/test_diff.py +258 -0
  80. knowledgecomplex-0.1.0/tests/test_element.py +198 -0
  81. knowledgecomplex-0.1.0/tests/test_filtration.py +376 -0
  82. knowledgecomplex-0.1.0/tests/test_inheritance.py +604 -0
  83. knowledgecomplex-0.1.0/tests/test_io.py +205 -0
  84. knowledgecomplex-0.1.0/tests/test_knowledge_complex.py +168 -0
  85. knowledgecomplex-0.1.0/tests/test_partition.py +292 -0
  86. knowledgecomplex-0.1.0/tests/test_schema_builder.py +181 -0
  87. knowledgecomplex-0.1.0/tests/test_stress.py +514 -0
  88. knowledgecomplex-0.1.0/tests/test_topology.py +289 -0
  89. knowledgecomplex-0.1.0/tests/test_topology_constraints.py +198 -0
  90. knowledgecomplex-0.1.0/tests/test_uri_property.py +167 -0
  91. knowledgecomplex-0.1.0/tests/test_viz.py +341 -0
  92. knowledgecomplex-0.1.0/uv.lock +1778 -0
@@ -0,0 +1,28 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.11", "3.12"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python ${{ matrix.python-version }}
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+
24
+ - name: Install package with all dependencies
25
+ run: pip install -e ".[dev,analysis,viz,viz-interactive]"
26
+
27
+ - name: Run tests
28
+ run: python -m pytest tests/ -v --tb=short
@@ -0,0 +1,24 @@
1
+ name: docs
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+
7
+ permissions:
8
+ contents: write
9
+
10
+ jobs:
11
+ deploy:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: "3.12"
19
+
20
+ - name: Install dependencies
21
+ run: pip install -e ".[docs]"
22
+
23
+ - name: Deploy docs
24
+ run: mkdocs gh-deploy --force
@@ -0,0 +1,30 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*.*.*"
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ environment: pypi
12
+ permissions:
13
+ id-token: write # required for trusted publishing
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - name: Set up Python
19
+ uses: actions/setup-python@v5
20
+ with:
21
+ python-version: "3.11"
22
+
23
+ - name: Install build tools
24
+ run: pip install hatchling build
25
+
26
+ - name: Build distribution
27
+ run: python -m build
28
+
29
+ - name: Publish to PyPI
30
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,14 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .venv/
7
+ venv/
8
+ .pytest_cache/
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+ *.egg
12
+ MANIFEST
13
+ htmlcov/
14
+ .coverage
@@ -0,0 +1,267 @@
1
+ # Architecture: knowledgecomplex
2
+
3
+ ## The 2×2 Responsibility Map
4
+
5
+ This is the central architectural constraint. Every rule in the system belongs to exactly one cell. The Python package exists to hide this table from the user.
6
+
7
+ | | **OWL** | **SHACL** |
8
+ |---|---|---|
9
+ | **Topological** | `kc:Element` base class; `kc:Vertex`, `kc:Edge`, `kc:Face` as subclasses. `kc:Edge` has exactly 2 `boundedBy` (Vertex); `kc:Face` has exactly 3 `boundedBy` (Edge). `kc:Complex` as collection of elements via `kc:hasElement`. | Boundary vertices are distinct; boundary edges of a face form a closed triangle; boundary-closure of a complex (all instance-level; require `sh:sparql`) |
10
+ | **Ontological** | Concrete subclasses and their allowed attributes; property domain/range declarations | Controlled vocabulary enforcement (e.g. `status ∈ {passing, failing, pending}`); attribute presence rules; co-occurrence constraints |
11
+
12
+ ### Why Both OWL and SHACL at Each Layer
13
+
14
+ **Topological layer:** OWL cardinality axioms enforce structural counts at the class level (reasoning over schema). SHACL is required for the closed-triangle constraint because OWL cannot express a constraint that references the *co-values* of three different property assertions on the same individual — this is a known expressivity boundary of OWL-DL. The `sh:sparql` constraint in `kc_core_shapes.ttl` is the explicit test of this boundary.
15
+
16
+ **Ontological layer:** OWL defines what attributes a concrete type *has* (property declarations, domain, range, subclass hierarchy). SHACL defines what values those attributes *must have* at the instance level (vocabulary constraints, cardinality on the concrete shape, required/optional). OWL cannot enforce controlled vocabulary on data properties at the instance level without enumerating individuals, which is inappropriate for string-valued attributes.
17
+
18
+ ---
19
+
20
+ ## Component Layers
21
+
22
+ ```
23
+ ┌─────────────────────────────────────────────────────┐
24
+ │ Application / Demo (user code) │
25
+ │ build_my_instance() | domain-specific queries │
26
+ │ Concrete elements: vertices, edges, faces │
27
+ ├─────────────────────────────────────────────────────┤
28
+ │ Domain Model (user code) │
29
+ │ build_my_schema() | domain SPARQL templates │
30
+ │ MyVertex, MyEdge, MyFace type definitions │
31
+ ├─────────────────────────────────────────────────────┤
32
+ │ knowledgecomplex Python Package │
33
+ │ SchemaBuilder DSL | KnowledgeComplex I/O │
34
+ │ (OWL + SHACL emit) | (rdflib graph + SPARQL) │
35
+ ├──────────────────────┬──────────────────────────────┤
36
+ │ kc_core.ttl │ kc_core_shapes.ttl │
37
+ │ (abstract OWL) │ (abstract SHACL) │
38
+ ├──────────────────────┴──────────────────────────────┤
39
+ │ rdflib | pyshacl | owlrl │
40
+ └─────────────────────────────────────────────────────┘
41
+ ```
42
+
43
+ The **domain model** layer sits between the core framework and the application. It defines domain-specific types and queries using the core's `SchemaBuilder` DSL. The application layer then instantiates that model with concrete data.
44
+
45
+ The static resources (`kc_core.ttl`, `kc_core_shapes.ttl`) are loaded once at `SchemaBuilder.__init__`. Model schema and shapes are merged into the same rdflib `Graph` objects at runtime.
46
+
47
+ ---
48
+
49
+ ## Abstraction Boundary: Core vs. Domain Models
50
+
51
+ The layers above are separated by a key abstraction boundary: the **core framework** (`knowledgecomplex/`) vs. **domain models** (user code). Everything inside the package boundary (core, static resources, libraries) is framework-owned and invariant. Everything outside (model definitions, instances) is user-authored.
52
+
53
+ ### Core Framework (`knowledgecomplex/`, prefixes `kc:` and `kcs:`)
54
+
55
+ - **Topological rule enforcement.** The Element/Vertex/Edge/Face hierarchy, cardinality axioms, distinctness, closed-triangle, and boundary-closure constraints. Static OWL and SHACL shipped with the package. Users cannot modify them.
56
+ - **Superstructure attributes.** `kc:uri` (optional, at-most-one) allows any element to reference a source file. Enforced by `kcs:ElementShape`.
57
+ - **Ontological rule authoring.** `SchemaBuilder` provides the DSL for declaring types, attributes, and vocabularies. It *generates* OWL classes and SHACL shapes on behalf of the domain model but does not itself define any domain types.
58
+ - **Instance management.** `KnowledgeComplex` loads the merged schema, manages the RDF graph, validates on every write, and executes named SPARQL queries.
59
+ - **Framework queries.** Generic SPARQL templates (`vertices`, `coboundary`) that work for any domain model.
60
+
61
+ ### Domain Models (user code, prefix `{namespace}:`)
62
+
63
+ - **Ontological rule enforcement.** The concrete OWL types and SHACL shapes generated by calling `SchemaBuilder.add_*_type()`.
64
+ - **Concrete complex authoring.** Instance data constructed via `KnowledgeComplex.add_*()` calls.
65
+ - **Domain queries.** Model-specific SPARQL templates.
66
+
67
+ ### The Type Inheritance Chain Crosses the Boundary
68
+
69
+ ```
70
+ kc:Element → kc:Vertex → aaa:spec → (instance "spec-001")
71
+ core core model application
72
+ ```
73
+
74
+ The core owns `Element → Vertex`; the model owns `Vertex → spec`; the application owns the instance `spec-001`. The boundary is at the subclass declaration — `add_vertex_type("spec")` is the model calling the core's authoring API to extend the core's type hierarchy.
75
+
76
+ ### Layer Ownership of the 2×2 Map
77
+
78
+ | | **OWL** | **SHACL** |
79
+ |---|---|---|
80
+ | **Topological** | Core owns (static `kc_core.ttl`) | Core owns (static `kc_core_shapes.ttl`) |
81
+ | **Ontological** | Domain model authors via `SchemaBuilder` → core generates | Domain model authors via `vocab()`/attributes → core generates |
82
+
83
+ Both ontological cells are *authored* by the domain model but *generated and managed* by the core. The domain model never touches OWL or SHACL directly.
84
+
85
+ ---
86
+
87
+ ## Key Design Decisions
88
+
89
+ ### DD1: Attributes over Subclasses (for Simple Domains)
90
+
91
+ For simple domain models, a single concrete type with a controlled-vocabulary attribute (e.g. `verification` with `status ∈ {passing, failing, pending}`) is preferred over two subclasses (`PassingVerification`, `FailingVerification`). The framework supports both patterns.
92
+
93
+ **Rationale:** The single-type-with-attribute pattern makes the data more inspectable before schema-level concerns are promoted. `promote_to_attribute()` supports the transition path from untyped patterns to typed attributes.
94
+
95
+ ### DD2: SPARQL Templates, Not Free Queries
96
+
97
+ All SPARQL is encapsulated as named template files. `KnowledgeComplex.query()` accepts only registered template names.
98
+
99
+ **Rationale:** Maintains API opacity, prevents arbitrary SPARQL from bypassing validation invariants, and makes the query surface explicit and testable.
100
+
101
+ ### DD3: Validation on Write
102
+
103
+ `add_vertex()`, `add_edge()`, and `add_face()` each trigger SHACL validation immediately and raise `ValidationError` on failure. Rollback removes all added triples on failure.
104
+
105
+ **Rationale:** Fail fast; keep the graph in a valid state at all times. Verification is not a batch post-processing step — it is enforced at assertion time.
106
+
107
+ ### DD4: Static Core Resources
108
+
109
+ `kc_core.ttl` and `kc_core_shapes.ttl` are static files shipped with the package, not generated at runtime.
110
+
111
+ **Rationale:** The topological rules are framework invariants, not user-configurable. Separating them from user schema makes the 2×2 boundary visible in the file system.
112
+
113
+ ### DD5: `dump_owl()` and `dump_shacl()` Merge Core and User Schema
114
+
115
+ Both dump methods return the full merged graph (core + user-defined), serialized as Turtle.
116
+
117
+ **Rationale:** The merged graph is what `pyshacl` and `owlrl` operate on. Showing the full graph makes the system inspectable and demonstrates that user types genuinely extend (not replace) the core ontology.
118
+
119
+ ### DD6: Shared-Domain Removal (`_set_owl_domain`)
120
+
121
+ When the same property name appears on multiple types, the OWL `rdfs:domain` assertion is removed (leaving no domain) rather than adding multiple domain values. SHACL shapes still enforce per-type constraints correctly via each type's `NodeShape`.
122
+
123
+ **Rationale:** Multiple `rdfs:domain` values trigger RDFS inference to classify any individual with that property as a member of *all* domain types — violating the type hierarchy. Removing domain resolves the conflict; SHACL handles the per-type enforcement.
124
+
125
+ ---
126
+
127
+ ## Known OWL Expressivity Limits (Design Seams)
128
+
129
+ | Constraint | OWL can express? | Resolution |
130
+ |---|---|---|
131
+ | Edge has exactly 2 boundary vertices | Yes (cardinality on `boundedBy`) | OWL cardinality axiom |
132
+ | Face has exactly 3 boundary edges | Yes (cardinality on `boundedBy`) | OWL cardinality axiom |
133
+ | Boundary vertices are distinct individuals | No (OWL open-world; same-as/different-from is individual-level) | SHACL `sh:sparql` (COUNT DISTINCT) |
134
+ | Boundary edges of a face form a closed triangle | No (requires co-reference across 3 property values) | SHACL `sh:sparql` constraint |
135
+ | Boundary-closure of a complex | No (requires co-reference across `hasElement` and `boundedBy` on different individuals) | SHACL `sh:sparql` constraint |
136
+ | Controlled vocabulary on data property | No (without `owl:oneOf` on individuals, impractical for strings) | SHACL `sh:in` |
137
+ | At-most-one `kc:uri` per element | Not enforced practically (open-world) | SHACL `sh:maxCount 1` in `ElementShape` |
138
+
139
+ These seams are documented as comments in the relevant `.ttl` files.
140
+
141
+ ---
142
+
143
+ ## Interoperability: Flexo MMS and OpenMBEE
144
+
145
+ Because knowledgecomplex stores all data as RDF and enforces constraints via standard W3C technologies (OWL, SHACL, SPARQL), it is natively compatible with [Flexo MMS](https://github.com/Open-MBEE/flexo-mms-deployment) — the Model Management System developed by the [OpenMBEE](https://www.openmbee.org/) community.
146
+
147
+ ### Why the fit is natural
148
+
149
+ Flexo MMS is a version-controlled model repository that speaks RDF natively. A KC instance graph is already a valid RDF dataset, so the integration path is direct:
150
+
151
+ | KC concept | MMS equivalent | Notes |
152
+ |---|---|---|
153
+ | `kc:Complex` (instance graph) | MMS model/branch | A KC export is a self-contained RDF graph that can be committed as an MMS model revision |
154
+ | `kc:boundedBy`, `kc:hasElement` | MMS element relationships | Topological structure is expressed as standard RDF triples |
155
+ | SHACL shapes (`kc_core_shapes.ttl` + user shapes) | MMS validation profiles | Shapes can be registered in MMS to enforce KC constraints on committed models |
156
+ | `kc:uri` | MMS element cross-references | Provides traceability from KC elements to external artifacts (files, documents, URIs) |
157
+ | JSON-LD export (`dump_graph(format="json-ld")`) | MMS ingest format | JSON-LD is the primary API format for Flexo MMS |
158
+
159
+ ### Integration patterns
160
+
161
+ **Push to MMS:** Export a KC instance via `kc.export()` or `dump_graph(format="json-ld")`, then commit to a Flexo MMS repository via its REST API. The OWL ontology and SHACL shapes can be committed alongside the instance data, enabling MMS-side validation.
162
+
163
+ **Pull from MMS:** Retrieve a model revision as JSON-LD from Flexo MMS, then load it into a KC instance via `load_graph(kc, "model.jsonld")`. The KC's SHACL verification (`kc.verify()`) ensures the imported data satisfies all topological and ontological constraints.
164
+
165
+ **Version control:** MMS provides branching, diffing, and merge capabilities at the RDF triple level. KC's `ComplexDiff` and `ComplexSequence` classes complement this by providing simplicial-complex-aware diffing (element-level adds/removes rather than triple-level changes).
166
+
167
+ ### What KC adds beyond MMS
168
+
169
+ Flexo MMS manages RDF models generically — it stores, versions, and queries them but does not enforce simplicial complex structure. KC adds the topological layer: boundary-closure, closed-triangle constraints, typed simplicial hierarchy, and algebraic topology computations (Betti numbers, Hodge decomposition). Together, MMS provides the model management infrastructure and KC provides the mathematical structure.
170
+
171
+ ### Reference
172
+
173
+ OpenMBEE (Open Model-Based Engineering Environment) is an open-source community developing tools for model-based systems engineering. Flexo MMS is its core model management system. See [openmbee.org](https://www.openmbee.org/) and [github.com/Open-MBEE](https://github.com/Open-MBEE).
174
+
175
+ ---
176
+
177
+ ## Deployment Architecture
178
+
179
+ The internal design described above (2x2 map, component layers, static resources) is the library's foundation. In practice, a knowledge complex is deployed through a stack of five layers, each building on the one below:
180
+
181
+ ```
182
+ ┌─────────────────────────────────────────────────────────────┐
183
+ │ 5. LLM Tool Integration │
184
+ │ Register KC operations as callable tools for a language │
185
+ │ model. The complex serves as a deterministic expert │
186
+ │ system — the LLM navigates, queries, and analyzes via │
187
+ │ tool calls; the KC guarantees topological correctness │
188
+ │ and returns structured, verifiable results. │
189
+ ├─────────────────────────────────────────────────────────────┤
190
+ │ 4. MCP Server │
191
+ │ Model Context Protocol server exposing KC as tools for │
192
+ │ AI assistants (Claude, etc.). Each KC operation becomes │
193
+ │ a tool: add_vertex, boundary, betti_numbers, audit, etc. │
194
+ ├─────────────────────────────────────────────────────────────┤
195
+ │ 3. Microservice (REST API) │
196
+ │ Python-hosted service exposing KC operations over HTTP. │
197
+ │ CRUD for elements, SPARQL query execution, SHACL │
198
+ │ verification, algebraic topology analysis, export/import.│
199
+ ├─────────────────────────────────────────────────────────────┤
200
+ │ 2. Concrete Knowledge Complex │
201
+ │ An instance using a specific ontology. Typed vertices, │
202
+ │ edges, and faces with attributes. SHACL-verified on │
203
+ │ every write. Serialized as RDF (Turtle, JSON-LD). │
204
+ │ Versioned via Flexo MMS or git. │
205
+ ├─────────────────────────────────────────────────────────────┤
206
+ │ 1. KC-Compatible Ontology │
207
+ │ OWL class hierarchy extending kc:Vertex/Edge/Face. │
208
+ │ SHACL shapes for attribute constraints. Publicly hosted │
209
+ │ at persistent URIs (w3id.org). Dereferenceable — tools │
210
+ │ can fetch the ontology and understand the type system. │
211
+ └─────────────────────────────────────────────────────────────┘
212
+ ```
213
+
214
+ ### Layer 1: Ontology
215
+
216
+ A KC-compatible ontology is an OWL ontology whose classes extend `kc:Vertex`, `kc:Edge`, and `kc:Face`, paired with SHACL shapes for instance-level constraints. Ontologies are authored via `SchemaBuilder` and exported as standard `.ttl` files. For public use, the ontology should be hosted at a persistent URI (e.g. `https://w3id.org/kc/`) so that other systems can dereference the IRI and retrieve the OWL/SHACL definitions. The `knowledgecomplex.ontologies` package ships three reference ontologies (operations, brand, research) as starting points.
217
+
218
+ ### Layer 2: Concrete Complex
219
+
220
+ A concrete knowledge complex is an RDF instance graph conforming to a specific ontology. It contains typed elements (vertices, edges, faces) with attributes, linked by `kc:boundedBy` and collected by `kc:hasElement`. SHACL verification enforces topological and ontological constraints on every write. The complex is serializable to Turtle, JSON-LD, or N-Triples and can be versioned via Flexo MMS or committed to a git repository as `.ttl` files.
221
+
222
+ ### Layer 3: Microservice
223
+
224
+ A Python-hosted HTTP service wraps the `KnowledgeComplex` API in a REST interface. Typical endpoints: element CRUD, named SPARQL queries, topological operations (boundary, star, closure), algebraic topology analysis (Betti numbers, Hodge decomposition, edge PageRank), SHACL verification and audit, and schema introspection. The service loads a schema at startup and manages one or more complex instances.
225
+
226
+ ### Layer 4: MCP Server
227
+
228
+ A [Model Context Protocol](https://modelcontextprotocol.io/) server exposes KC operations as tools that AI assistants can call. Each KC method becomes an MCP tool: `add_vertex`, `boundary`, `find_cliques`, `betti_numbers`, `audit`, etc. The MCP server is a thin adapter over the microservice or the library directly, translating between MCP tool calls and KC Python API calls.
229
+
230
+ ### Layer 5: LLM Tool Integration
231
+
232
+ The knowledge complex is registered as a set of callable tools for a language model. The LLM uses the complex as a **deterministic expert system** — it navigates the simplicial structure, retrieves typed elements and their attributes, runs topological queries, and performs algebraic topology analysis via tool calls. The KC guarantees that every result is topologically valid and SHACL-verified. The LLM provides natural language understanding and reasoning; the KC provides structured, auditable, mathematically rigorous retrieval.
233
+
234
+ This separation is key: the LLM handles ambiguity, intent, and synthesis; the KC handles structure, correctness, and computation. Neither replaces the other.
235
+
236
+ ---
237
+
238
+ ## Namespace Conventions
239
+
240
+ ```turtle
241
+ @prefix kc: <https://example.org/kc#> . # core framework
242
+ @prefix kcs: <https://example.org/kc/shape#> . # core shapes
243
+ @prefix aaa: <https://example.org/aaa#> . # user namespace (example)
244
+ @prefix aaas: <https://example.org/aaa/shape#> .# user shapes (example)
245
+ ```
246
+
247
+ User namespaces are set via `SchemaBuilder(namespace="aaa")`. The URI base `https://example.org/` is a placeholder for local development; a real deployment would use a dereferenceable IRI.
248
+
249
+ ---
250
+
251
+ ## File Inventory
252
+
253
+ | File | Layer | Purpose |
254
+ |---|---|---|
255
+ | `knowledgecomplex/resources/kc_core.ttl` | Abstract OWL | Topological backbone: classes, properties, cardinality axioms, `kc:uri` |
256
+ | `knowledgecomplex/resources/kc_core_shapes.ttl` | Abstract SHACL | Topological constraints: distinctness, closed-triangle, boundary-closure, `kc:uri` at-most-one |
257
+ | `knowledgecomplex/schema.py` | Python API — schema authoring | `SchemaBuilder` DSL: `add_*_type`, `dump_owl`, `dump_shacl`, `export`, `load` |
258
+ | `knowledgecomplex/graph.py` | Python API — instance I/O | `KnowledgeComplex`: `add_vertex`, `add_edge`, `add_face`, `query`, `dump_graph`, `export`, `load` |
259
+ | `knowledgecomplex/exceptions.py` | Public exceptions | `ValidationError`, `SchemaError`, `UnknownQueryError` |
260
+ | `knowledgecomplex/io.py` | Python API — serialization | `save_graph`, `load_graph`, `dump_graph` — multi-format file I/O (Turtle, JSON-LD, N-Triples) |
261
+ | `knowledgecomplex/viz.py` | Python API — visualization | Hasse diagrams (`plot_hasse`), geometric realization (`plot_geometric`), `to_networkx`, `verify_networkx` |
262
+ | `knowledgecomplex/analysis.py` | Python API — algebraic topology | `betti_numbers`, `euler_characteristic`, `hodge_laplacian`, `edge_pagerank` (optional: numpy, scipy) |
263
+ | `knowledgecomplex/clique.py` | Python API — clique inference | `find_cliques`, `infer_faces`, `fill_cliques` — flagification and typed face inference |
264
+ | `knowledgecomplex/filtration.py` | Python API — filtrations | `Filtration` — nested subcomplex sequences, birth tracking, `from_function` |
265
+ | `knowledgecomplex/diff.py` | Python API — diffs and sequences | `ComplexDiff`, `ComplexSequence` — time-varying complexes with SPARQL UPDATE export/import |
266
+ | `knowledgecomplex/codecs/markdown.py` | Codec — markdown files | `MarkdownCodec` — YAML frontmatter + section-based round-trip; `verify_documents` |
267
+ | `knowledgecomplex/queries/*.sparql` | Framework SPARQL | 7 templates: vertices, coboundary, boundary, star, closure, skeleton, degree |
@@ -0,0 +1,201 @@
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
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.