diff --git a/.gitignore b/.gitignore index bd8cc5b..4342234 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ venv/ MANIFEST htmlcov/ .coverage +site/ diff --git a/docs/api/parametric.md b/docs/api/parametric.md new file mode 100644 index 0000000..06225a9 --- /dev/null +++ b/docs/api/parametric.md @@ -0,0 +1,3 @@ +# Parametric Sequences + +::: knowledgecomplex.parametric diff --git a/docs/tutorial.md b/docs/tutorial.md index b62382b..3433318 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -254,7 +254,36 @@ filt[1] # set of element IDs at step 1 filt2 = Filtration.from_function(kc, lambda eid: some_score(eid)) ``` -## 7. Clique inference +## 7. Parametric sequences + +A `ParametricSequence` views a single complex through a parameterized filter. The complex holds all elements across all parameter values; the filter selects which are "active" at each value. Unlike a Filtration, subcomplexes can shrink — elements can appear and disappear. + +```python +from knowledgecomplex import ParametricSequence + +# Complex has people with active_from/active_until attributes +seq = ParametricSequence( + kc, + values=["Q1", "Q2", "Q3", "Q4"], + filter=lambda elem, t: elem.attrs.get("active_from", "0") <= t < elem.attrs.get("active_until", "9999"), +) + +seq["Q2"] # set of element IDs active at Q2 +seq.birth("carol") # "Q2" — first value where carol appears +seq.death("bob") # "Q3" — first value where bob disappears +seq.active_at("bob") # ["Q1", "Q2"] +seq.new_at(1) # elements appearing at Q2 +seq.removed_at(2) # elements disappearing at Q3 (bob left) +seq.is_monotone # False — people can leave +seq.subcomplex_at(0) # is the Q1 slice boundary-closed? + +for value, ids in seq: + print(f"{value}: {len(ids)} elements") +``` + +The complex is the territory; the parameterized filter is the map. + +## 8. Clique inference Discover higher-order structure hiding in the edge graph: @@ -271,7 +300,7 @@ added = infer_faces(kc, "coverage") preview = infer_faces(kc, "coverage", dry_run=True) ``` -## 8. Export and load +## 9. Export and load ```python # Export schema + instance to a directory @@ -292,7 +321,7 @@ save_graph(kc, "data.jsonld", format="json-ld") load_graph(kc, "data.ttl") # additive loading ``` -## 9. Verification and audit +## 10. Verification and audit ```python # Throwing verification @@ -317,7 +346,7 @@ report = audit_file("data/instance.ttl", shapes="data/shapes.ttl", ontology="data/ontology.ttl") ``` -## 10. Pre-built ontologies +## 11. Pre-built ontologies Three ontologies ship with the package: diff --git a/examples/08_temporal_sweep/temporal_sweep.py b/examples/08_temporal_sweep/temporal_sweep.py index c3ef8ba..e489980 100644 --- a/examples/08_temporal_sweep/temporal_sweep.py +++ b/examples/08_temporal_sweep/temporal_sweep.py @@ -69,74 +69,50 @@ print(f"Built timeline: {len(kc.element_ids())} total elements across all time") print() -# ── Manual parameterized sweep ───────────────────────────────────────────── +# ── Parameterized sweep using ParametricSequence ────────────────────────── -# Since we store active_from/active_until as string attributes, we can -# query for elements active at a specific time by comparing attribute values. +from knowledgecomplex import ParametricSequence + +def active_filter(elem, t): + """Element is active at time t if active_from <= t < active_until.""" + af = elem.attrs.get("active_from", "0") + au = elem.attrs.get("active_until", "9999") + return af <= t < au + +seq = ParametricSequence(kc, values=["1", "2", "3", "4", "5"], filter=active_filter) print("=== Active subcomplex at each quarter ===") -for t in ["1", "2", "3", "4", "5"]: - # Get active people at time t - active_people = set() - for pid in kc.element_ids(type="Person"): - elem = kc.element(pid) - af = elem.attrs.get("active_from", "0") - au = elem.attrs.get("active_until", "9999") - if af <= t < au: - active_people.add(pid) - - # Get active edges at time t - active_edges = set() - for eid in kc.element_ids(type="WorksWith"): - elem = kc.element(eid) - af = elem.attrs.get("active_from", "0") - au = elem.attrs.get("active_until", "9999") - if af <= t < au: - # Only include if both endpoints are active - boundary = kc.boundary(eid) - if boundary <= active_people: - active_edges.add(eid) - - # Get active faces - active_faces = set() - for fid in kc.element_ids(type="Squad"): - boundary = kc.boundary(fid) - if boundary <= active_edges: - active_faces.add(fid) - - active = active_people | active_edges | active_faces - is_sub = kc.is_subcomplex(active) - - print(f" Q{t}: {len(active_people)} people, " - f"{len(active_edges)} collabs, " - f"{len(active_faces)} squads " - f"(valid subcomplex: {is_sub})") - print(f" people: {sorted(active_people)}") - - # Show who's new and who left - if t != "1": - prev_t = str(int(t) - 1) - prev_people = set() - for pid in kc.element_ids(type="Person"): - elem = kc.element(pid) - af = elem.attrs.get("active_from", "0") - au = elem.attrs.get("active_until", "9999") - if af <= prev_t < au: - prev_people.add(pid) - joined = active_people - prev_people - left = prev_people - active_people - if joined: - print(f" joined: {sorted(joined)}") - if left: - print(f" left: {sorted(left)}") +for t, active in seq: + print(f" Q{t}: {len(active)} elements " + f"(valid subcomplex: {seq.subcomplex_at(seq.values.index(t))})") + print(f" {sorted(active)}") + + i = seq.values.index(t) + new = seq.new_at(i) + removed = seq.removed_at(i) + if new: + print(f" joined: {sorted(new)}") + if removed: + print(f" left: {sorted(removed)}") print() +# ── Lifecycle queries ────────────────────────────────────────────────────── + +print("=== Lifecycle ===") +for person in ["alice", "bob", "carol", "dave", "eve"]: + birth = seq.birth(person) + death = seq.death(person) + active = seq.active_at(person) + print(f" {person:6s} birth=Q{birth} death={'Q'+death if death else 'still active':14s} active={active}") +print() + # ── Key insight ──────────────────────────────────────────────────────────── -print("=== Key insight ===") -print(" This is NOT a filtration — the subcomplex at Q4 is not a superset") -print(" of Q3 (bob left). But each time-slice is a valid subcomplex,") -print(" and the full complex contains the complete history.") +print(f"=== Key insight ===") +print(f" is_monotone: {seq.is_monotone}") +print(f" This is NOT a filtration — bob leaves at Q3, so Q3 is not a") +print(f" superset of Q2. But the complex holds the complete history,") +print(f" and the parameterized filter slices it at any time.") print() -print(" The complex is the territory; the time-slice queries are the maps.") +print(f" The complex is the territory; the parameterized filter is the map.") print("Done.") diff --git a/knowledgecomplex/__init__.py b/knowledgecomplex/__init__.py index 68bfd20..f608819 100644 --- a/knowledgecomplex/__init__.py +++ b/knowledgecomplex/__init__.py @@ -11,6 +11,7 @@ from knowledgecomplex.schema import SchemaBuilder, vocab, text, TextDescriptor, Codec from knowledgecomplex.graph import KnowledgeComplex, Element from knowledgecomplex.filtration import Filtration +from knowledgecomplex.parametric import ParametricSequence from knowledgecomplex.exceptions import ValidationError, SchemaError, UnknownQueryError from knowledgecomplex.audit import AuditReport, AuditViolation, audit_file from knowledgecomplex.io import save_graph, load_graph, dump_graph @@ -60,6 +61,7 @@ "KnowledgeComplex", "Element", # Filtrations "Filtration", + "ParametricSequence", # Exceptions "ValidationError", "SchemaError", "UnknownQueryError", # File I/O diff --git a/knowledgecomplex/parametric.py b/knowledgecomplex/parametric.py new file mode 100644 index 0000000..cc09de6 --- /dev/null +++ b/knowledgecomplex/parametric.py @@ -0,0 +1,166 @@ +""" +knowledgecomplex.parametric — Parametric sequences over knowledge complexes. + +A ParametricSequence represents a single complex viewed through a +parameterized filter. Each parameter value selects a subcomplex — +the sequence of subcomplexes can grow, shrink, or change arbitrarily +as the parameter varies. + +Unlike :class:`~knowledgecomplex.filtration.Filtration`, which enforces +monotone nesting, a ParametricSequence is observational — it computes +slices lazily from a filter function. +""" + +from __future__ import annotations +from typing import Any, Callable, Iterator, TYPE_CHECKING + +if TYPE_CHECKING: + from knowledgecomplex.graph import KnowledgeComplex, Element + + +class ParametricSequence: + """ + A complex viewed through a parameterized filter. + + One complex holds all elements. A filter function decides which + elements are active at each parameter value. The result is a + sequence of subcomplexes indexed by parameter values. + + Parameters + ---------- + kc : KnowledgeComplex + The complex containing all elements. + values : list + Ordered parameter values (e.g. ``["Q1", "Q2", "Q3", "Q4"]``). + filter : Callable[[Element, value], bool] + Returns True if the element is active at the given parameter value. + + Example + ------- + >>> seq = ParametricSequence(kc, values=["1","2","3","4"], + ... filter=lambda elem, t: elem.attrs.get("active_from","0") <= t) + >>> seq[0] # element IDs active at "1" + >>> seq.birth("carol") # first value where carol appears + """ + + def __init__( + self, + kc: "KnowledgeComplex", + values: list, + filter: Callable[["Element", Any], bool], + ) -> None: + self._kc = kc + self._values = list(values) + self._filter = filter + self._cache: dict[int, frozenset[str]] = {} + + def _compute(self, index: int) -> frozenset[str]: + """Compute and cache the element set at a given index.""" + if index not in self._cache: + value = self._values[index] + ids = frozenset( + eid for eid in self._kc.element_ids() + if self._filter(self._kc.element(eid), value) + ) + self._cache[index] = ids + return self._cache[index] + + def __repr__(self) -> str: + return f"ParametricSequence(steps={len(self._values)}, monotone={self.is_monotone})" + + # --- Indexing --- + + def __getitem__(self, key: int | Any) -> set[str]: + if isinstance(key, int): + return set(self._compute(key)) + # Try to look up by parameter value + try: + index = self._values.index(key) + except ValueError: + raise KeyError(f"Parameter value {key!r} not in values list") + return set(self._compute(index)) + + def __len__(self) -> int: + return len(self._values) + + def __iter__(self) -> Iterator[tuple[Any, set[str]]]: + for i, value in enumerate(self._values): + yield value, set(self._compute(i)) + + # --- Properties --- + + @property + def complex(self) -> "KnowledgeComplex": + """The parent KnowledgeComplex.""" + return self._kc + + @property + def values(self) -> list: + """The ordered parameter values.""" + return list(self._values) + + @property + def is_monotone(self) -> bool: + """True if every step is a superset of the previous (filtration-like).""" + for i in range(1, len(self._values)): + if not (self._compute(i - 1) <= self._compute(i)): + return False + return True + + # --- Queries --- + + def birth(self, element_id: str) -> Any: + """Return the first parameter value where the element appears. + + Raises + ------ + ValueError + If the element does not appear at any parameter value. + """ + for i, value in enumerate(self._values): + if element_id in self._compute(i): + return value + raise ValueError(f"Element '{element_id}' not found at any parameter value") + + def death(self, element_id: str) -> Any | None: + """Return the first parameter value where the element disappears. + + Returns None if the element is present at all values after its birth, + or if it never appears. + """ + appeared = False + for i in range(len(self._values)): + present = element_id in self._compute(i) + if present: + appeared = True + elif appeared: + return self._values[i] + return None + + def active_at(self, element_id: str) -> list: + """Return the list of parameter values where the element is present.""" + return [ + self._values[i] + for i in range(len(self._values)) + if element_id in self._compute(i) + ] + + def new_at(self, index: int) -> set[str]: + """Return elements appearing at step index that were not in step index-1.""" + current = self._compute(index) + if index == 0: + return set(current) + previous = self._compute(index - 1) + return set(current - previous) + + def removed_at(self, index: int) -> set[str]: + """Return elements present at step index-1 that are absent at step index.""" + if index == 0: + return set() + current = self._compute(index) + previous = self._compute(index - 1) + return set(previous - current) + + def subcomplex_at(self, index: int) -> bool: + """Check if the slice at index is a valid subcomplex (closed under boundary).""" + return self._kc.is_subcomplex(set(self._compute(index))) diff --git a/mkdocs.yml b/mkdocs.yml index a92b11e..bcd241d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -30,6 +30,7 @@ nav: - Algebraic Topology: api/analysis.md - Clique Inference: api/clique.md - Filtrations: api/filtration.md + - Parametric Sequences: api/parametric.md - Diffs & Sequences: api/diff.md - File I/O: api/io.md - Codecs: api/codecs.md diff --git a/site/404.html b/site/404.html deleted file mode 100644 index a879d28..0000000 --- a/site/404.html +++ /dev/null @@ -1,703 +0,0 @@ - - - -
- - - - - - - - - - - - - - - - - -knowledgecomplex.analysis — Algebraic topology over knowledge complexes.
-Boundary matrices, Betti numbers, Hodge Laplacians, edge PageRank, -and Hodge decomposition of edge flows.
-Requires: numpy, scipy (install with pip install knowledgecomplex[analysis]).
BoundaryMatrices
-
-
-
- dataclass
-
-
-Boundary operators and element-to-index mappings.
- - - - - - - - -knowledgecomplex/analysis.py27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 | |
HodgeDecomposition
-
-
-
- dataclass
-
-
-Orthogonal decomposition of an edge flow.
- - - - - - - - -knowledgecomplex/analysis.py44 -45 -46 -47 -48 -49 | |
EdgeInfluence
-
-
-
- dataclass
-
-
-Influence measures for an edge's PageRank vector.
- - - - - - - - -knowledgecomplex/analysis.py52 -53 -54 -55 -56 -57 -58 -59 | |
SweepCut
-
-
-
- dataclass
-
-
-Result of a vertex sweep cut.
- - - - - - - - -knowledgecomplex/analysis.py62 -63 -64 -65 -66 -67 -68 -69 -70 -71 | |
EdgeSweepCut
-
-
-
- dataclass
-
-
-Result of an edge sweep cut.
- - - - - - - - -knowledgecomplex/analysis.py74 -75 -76 -77 -78 -79 -80 -81 -82 | |
HodgeAnalysisResults
-
-
-
- dataclass
-
-
-Complete Hodge analysis output.
- - - - - - - - -knowledgecomplex/analysis.py85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 | |
boundary_matrices(kc)
-
-Build the boundary operator matrices B1 (∂₁) and B2 (∂₂).
-B1 is (n_vertices × n_edges) with entries ±1 encoding which vertices -bound each edge. B2 is (n_edges × n_faces) with entries ±1 encoding -which edges bound each face.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- BoundaryMatrices
- |
-
-
-
-
- |
-
knowledgecomplex/analysis.py140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 -227 -228 -229 -230 -231 -232 -233 -234 | |
betti_numbers(kc)
-
-Compute Betti numbers [β₀, β₁, β₂] of the complex.
-β_k = nullity(∂k) - rank(∂{k+1})
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- list[int]
- |
-
-
-
- [β₀, β₁, β₂] - |
-
knowledgecomplex/analysis.py293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 -313 -314 -315 -316 -317 -318 -319 -320 -321 -322 -323 -324 -325 -326 | |
euler_characteristic(kc)
-
-Compute the Euler characteristic χ = V - E + F.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- int
- |
-
-
-
-
- |
-
knowledgecomplex/analysis.py329 -330 -331 -332 -333 -334 -335 -336 -337 -338 -339 -340 -341 -342 | |
hodge_laplacian(kc, weighted=False, weights=None)
-
-Compute the edge Hodge Laplacian L₁.
-Combinatorial (default): - L₁ = B1ᵀ W₀ B1 + B2 W₂ B2ᵀ
-where W₀ and W₂ are diagonal simplex weight matrices (identity when -weights is None).
-Degree-weighted: - L₁ = B1ᵀ D₀⁻¹ W₀ B1 + D₁⁻¹ B2 W₂ B2ᵀ
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- weighted
- |
-
- bool
- |
-
-
-
- If True, also apply degree normalization. - |
-
- False
- |
-
- weights
- |
-
- dict[str, float]
- |
-
-
-
- Map from element IDs to scalar weights. Missing elements default -to 1.0. Vertex weights enter W₀, face weights enter W₂. - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- csr_matrix
- |
-
-
-
- (n_edges, n_edges) - |
-
knowledgecomplex/analysis.py358 -359 -360 -361 -362 -363 -364 -365 -366 -367 -368 -369 -370 -371 -372 -373 -374 -375 -376 -377 -378 -379 -380 -381 -382 -383 -384 -385 -386 -387 -388 -389 -390 -391 -392 -393 -394 -395 -396 -397 -398 -399 -400 -401 -402 -403 -404 -405 -406 -407 -408 -409 -410 -411 -412 -413 -414 -415 -416 -417 -418 -419 | |
edge_pagerank(kc, edge_id, beta=0.1, weighted=False, weights=None)
-
-Compute personalized edge PageRank for a single edge.
-PR_e = (βI + L₁)⁻¹ χ_e
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- edge_id
- |
-
- str
- |
-
-
-
-
- |
- - required - | -
- beta
- |
-
- float
- |
-
-
-
-
- |
-
- 0.1
- |
-
- weighted
- |
-
- bool
- |
-
-
-
-
- |
-
- False
- |
-
- weights
- |
-
- dict[str, float]
- |
-
-
-
- Simplex weights (see hodge_laplacian). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- ndarray
- |
-
-
-
- (n_edges,) - |
-
knowledgecomplex/analysis.py426 -427 -428 -429 -430 -431 -432 -433 -434 -435 -436 -437 -438 -439 -440 -441 -442 -443 -444 -445 -446 -447 -448 -449 -450 -451 -452 -453 -454 -455 -456 -457 -458 -459 -460 | |
edge_pagerank_all(kc, beta=0.1, weighted=False, weights=None)
-
-Compute edge PageRank for all edges via matrix factorization.
-Factorizes (βI + L₁) once, then solves for each column of the identity. -Equivalent to computing (βI + L₁)⁻¹.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- beta
- |
-
- float
- |
-
-
-
-
- |
-
- 0.1
- |
-
- weighted
- |
-
- bool
- |
-
-
-
-
- |
-
- False
- |
-
- weights
- |
-
- dict[str, float]
- |
-
-
-
- Simplex weights (see hodge_laplacian). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- ndarray
- |
-
-
-
- (n_edges, n_edges) — column i is the PageRank vector for edge i. - |
-
knowledgecomplex/analysis.py463 -464 -465 -466 -467 -468 -469 -470 -471 -472 -473 -474 -475 -476 -477 -478 -479 -480 -481 -482 -483 -484 -485 -486 -487 -488 -489 -490 -491 -492 -493 -494 -495 -496 -497 -498 -499 -500 -501 -502 -503 -504 | |
hodge_decomposition(kc, flow, weights=None)
-
-Decompose an edge flow into gradient + curl + harmonic components.
-flow = gradient + curl + harmonic
-where: -- gradient ∈ im(W₀^{1/2} B1ᵀ) — vertex-driven flow -- curl ∈ im(W₂^{1/2} B2) — face-driven circulation -- harmonic ∈ ker(L₁) — topological cycles
-When weights is None, W₀ and W₂ are identity (standard decomposition).
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- flow
- |
-
- ndarray
- |
-
-
-
- (n_edges,) - |
- - required - | -
- weights
- |
-
- dict[str, float]
- |
-
-
-
- Simplex weights. Affects the inner product used for projection. - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- HodgeDecomposition
- |
-
-
-
-
- |
-
knowledgecomplex/analysis.py519 -520 -521 -522 -523 -524 -525 -526 -527 -528 -529 -530 -531 -532 -533 -534 -535 -536 -537 -538 -539 -540 -541 -542 -543 -544 -545 -546 -547 -548 -549 -550 -551 -552 -553 -554 -555 -556 -557 -558 -559 -560 -561 -562 -563 -564 -565 -566 -567 -568 -569 -570 -571 -572 -573 -574 | |
edge_influence(edge_id, pr_vector)
-
-Compute influence measures from a PageRank vector.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- edge_id
- |
-
- str
- |
-
-
-
-
- |
- - required - | -
- pr_vector
- |
-
- ndarray
- |
-
-
-
-
- |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- EdgeInfluence
- |
-
-
-
-
- |
-
knowledgecomplex/analysis.py601 -602 -603 -604 -605 -606 -607 -608 -609 -610 -611 -612 -613 -614 -615 -616 -617 -618 -619 -620 -621 -622 -623 | |
hodge_analysis(kc, beta=0.1, weighted=False, weights=None)
-
-Run complete Hodge analysis on a knowledge complex.
-Computes boundary matrices, Betti numbers, Hodge Laplacian, -edge PageRank for all edges, Hodge decomposition, and influence measures.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- beta
- |
-
- float
- |
-
-
-
-
- |
-
- 0.1
- |
-
- weighted
- |
-
- bool
- |
-
-
-
-
- |
-
- False
- |
-
- weights
- |
-
- dict[str, float]
- |
-
-
-
- Simplex weights (see hodge_laplacian). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- HodgeAnalysisResults
- |
-
-
-
-
- |
-
knowledgecomplex/analysis.py630 -631 -632 -633 -634 -635 -636 -637 -638 -639 -640 -641 -642 -643 -644 -645 -646 -647 -648 -649 -650 -651 -652 -653 -654 -655 -656 -657 -658 -659 -660 -661 -662 -663 -664 -665 -666 -667 -668 -669 -670 -671 -672 -673 -674 -675 | |
graph_laplacian(kc)
-
-Compute the normalized graph Laplacian L = I - D⁻¹A on the 1-skeleton.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- csr_matrix
- |
-
-
-
- (n_vertices, n_vertices) - |
-
knowledgecomplex/analysis.py682 -683 -684 -685 -686 -687 -688 -689 -690 -691 -692 -693 -694 -695 -696 -697 -698 -699 -700 -701 -702 -703 -704 -705 -706 -707 -708 -709 -710 -711 -712 -713 -714 -715 -716 -717 -718 -719 | |
approximate_pagerank(kc, seed, alpha=0.15, epsilon=0.0001)
-
-Compute approximate PageRank via the push algorithm.
-Follows Andersen-Chung-Lang (FOCS 2006). Uses lazy random walk -W = (I + D⁻¹A)/2. Maintains invariant p + pr(α, r) = pr(α, χ_seed).
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- seed
- |
-
- str
- |
-
-
-
- Starting vertex. - |
- - required - | -
- alpha
- |
-
- float
- |
-
-
-
- Teleportation constant (higher = more local). - |
-
- 0.15
- |
-
- epsilon
- |
-
- float
- |
-
-
-
- Convergence threshold: stops when max r(u)/d(u) < epsilon. - |
-
- 0.0001
- |
-
Returns:
-| Type | -Description | -
|---|---|
- tuple[dict[str, float], dict[str, float]]
- |
-
-
-
- (p, r) — approximate PageRank vector and residual. - |
-
knowledgecomplex/analysis.py750 -751 -752 -753 -754 -755 -756 -757 -758 -759 -760 -761 -762 -763 -764 -765 -766 -767 -768 -769 -770 -771 -772 -773 -774 -775 -776 -777 -778 -779 -780 -781 -782 -783 -784 -785 -786 -787 -788 -789 -790 -791 -792 -793 -794 -795 -796 -797 -798 -799 -800 -801 -802 -803 -804 -805 -806 -807 -808 -809 -810 -811 -812 -813 -814 -815 -816 -817 -818 -819 -820 -821 | |
heat_kernel_pagerank(kc, seed, t=5.0, num_terms=30)
-
-Compute heat kernel PageRank ρ_{t,seed} on the 1-skeleton.
-ρ_{t,u} = e^{-t} Σ_{k=0}^{N} (t^k / k!) χ_u W^k
-where W = D⁻¹A is the random walk transition matrix.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- seed
- |
-
- str
- |
-
-
-
- Starting vertex. - |
- - required - | -
- t
- |
-
- float
- |
-
-
-
- Heat parameter (temperature). Small t = local, large t = global. - |
-
- 5.0
- |
-
- num_terms
- |
-
- int
- |
-
-
-
- Number of terms in the Taylor expansion. - |
-
- 30
- |
-
Returns:
-| Type | -Description | -
|---|---|
- dict[str, float]
- |
-
-
-
- Mapping from vertex IDs to PageRank values. - |
-
knowledgecomplex/analysis.py828 -829 -830 -831 -832 -833 -834 -835 -836 -837 -838 -839 -840 -841 -842 -843 -844 -845 -846 -847 -848 -849 -850 -851 -852 -853 -854 -855 -856 -857 -858 -859 -860 -861 -862 -863 -864 -865 -866 -867 -868 -869 -870 -871 -872 -873 -874 -875 -876 -877 -878 -879 -880 -881 -882 -883 -884 -885 -886 -887 -888 -889 -890 -891 -892 -893 -894 -895 -896 | |
sweep_cut(kc, distribution, max_volume=None)
-
-Sweep a vertex distribution to find a cut with minimum conductance.
-Sorts vertices by p(v)/d(v) descending, computes conductance of each -prefix set, returns the cut with minimum conductance.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- distribution
- |
-
- dict[str, float]
- |
-
-
-
- Vertex distribution (e.g., from approximate_pagerank). - |
- - required - | -
- max_volume
- |
-
- int
- |
-
-
-
- Maximum volume for the small side of the cut. - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- SweepCut
- |
-
-
-
-
- |
-
knowledgecomplex/analysis.py903 -904 -905 -906 -907 -908 -909 -910 -911 -912 -913 -914 -915 -916 -917 -918 -919 -920 -921 -922 -923 -924 -925 -926 -927 -928 -929 -930 -931 -932 -933 -934 -935 -936 -937 -938 -939 -940 -941 -942 -943 -944 -945 -946 -947 -948 -949 -950 -951 -952 -953 -954 -955 -956 -957 -958 -959 -960 -961 -962 -963 -964 -965 -966 -967 -968 -969 -970 -971 -972 -973 -974 -975 -976 -977 -978 -979 -980 -981 | |
local_partition(kc, seed, target_conductance=0.5, target_volume=None, method='pagerank')
-
-Find a local partition near a seed vertex.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- seed
- |
-
- str
- |
-
-
-
- Starting vertex. - |
- - required - | -
- target_conductance
- |
-
- float
- |
-
-
-
- Target conductance for setting alpha/t. - |
-
- 0.5
- |
-
- target_volume
- |
-
- int
- |
-
-
-
- Maximum volume for the small side. - |
-
- None
- |
-
- method
- |
-
- str
- |
-
-
-
- "pagerank" — approximate PageRank (Andersen-Chung-Lang). -"heat_kernel" — heat kernel PageRank (Chung). - |
-
- 'pagerank'
- |
-
Returns:
-| Type | -Description | -
|---|---|
- SweepCut
- |
-
-
-
-
- |
-
knowledgecomplex/analysis.py988 - 989 - 990 - 991 - 992 - 993 - 994 - 995 - 996 - 997 - 998 - 999 -1000 -1001 -1002 -1003 -1004 -1005 -1006 -1007 -1008 -1009 -1010 -1011 -1012 -1013 -1014 -1015 -1016 -1017 -1018 -1019 -1020 -1021 -1022 -1023 -1024 -1025 -1026 -1027 -1028 -1029 -1030 | |
edge_sweep_cut(kc, edge_distribution, bm=None)
-
-Sweep an edge distribution to find an edge partition with minimum conductance.
-Sorts edges by |distribution(e)|/degree(e) descending, computes edge -conductance of each prefix. Edge conductance measures how many -vertex-boundary connections cross the partition.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- edge_distribution
- |
-
- ndarray
- |
-
-
-
- (n_edges,) vector of edge values. - |
- - required - | -
- bm
- |
-
- BoundaryMatrices
- |
-
-
-
- Pre-computed boundary matrices. - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- EdgeSweepCut
- |
-
-
-
-
- |
-
knowledgecomplex/analysis.py1037 -1038 -1039 -1040 -1041 -1042 -1043 -1044 -1045 -1046 -1047 -1048 -1049 -1050 -1051 -1052 -1053 -1054 -1055 -1056 -1057 -1058 -1059 -1060 -1061 -1062 -1063 -1064 -1065 -1066 -1067 -1068 -1069 -1070 -1071 -1072 -1073 -1074 -1075 -1076 -1077 -1078 -1079 -1080 -1081 -1082 -1083 -1084 -1085 -1086 -1087 -1088 -1089 -1090 -1091 -1092 -1093 -1094 -1095 -1096 -1097 -1098 -1099 -1100 -1101 -1102 -1103 -1104 -1105 -1106 -1107 -1108 -1109 -1110 -1111 -1112 -1113 -1114 -1115 -1116 -1117 -1118 -1119 -1120 -1121 | |
edge_local_partition(kc, seed_edge, t=5.0, beta=0.1, method='hodge_heat', weights=None)
-
-Find a local edge partition using the Hodge Laplacian.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- seed_edge
- |
-
- str
- |
-
-
-
- Starting edge. - |
- - required - | -
- t
- |
-
- float
- |
-
-
-
- Heat parameter (for hodge_heat method). - |
-
- 5.0
- |
-
- beta
- |
-
- float
- |
-
-
-
- Regularization (for hodge_pagerank method). - |
-
- 0.1
- |
-
- method
- |
-
- str
- |
-
-
-
- "hodge_heat" — e^{-tL₁} χ_e (heat kernel on edges). -"hodge_pagerank" — (βI + L₁)⁻¹ χ_e (existing edge PageRank). - |
-
- 'hodge_heat'
- |
-
- weights
- |
-
- dict[str, float]
- |
-
-
-
- Simplex weights. - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- EdgeSweepCut
- |
-
-
-
-
- |
-
knowledgecomplex/analysis.py1128 -1129 -1130 -1131 -1132 -1133 -1134 -1135 -1136 -1137 -1138 -1139 -1140 -1141 -1142 -1143 -1144 -1145 -1146 -1147 -1148 -1149 -1150 -1151 -1152 -1153 -1154 -1155 -1156 -1157 -1158 -1159 -1160 -1161 -1162 -1163 -1164 -1165 -1166 -1167 -1168 -1169 -1170 -1171 -1172 -1173 -1174 -1175 -1176 -1177 | |
knowledgecomplex.clique — Clique complex and flagification methods.
-Two workflows for inferring higher-order simplices from the edge graph:
-Generic exploration (fill_cliques)
- Discover what higher-order structure exists before knowing the semantics.
- Fill in generic simplices for all cliques up to a given order. Inspect
- what shows up, then decide what types to declare.
Typed inference (infer_faces)
- Once you've declared a face type with semantic meaning, fill in all
- instances of that type from the edge graph. The face type is required —
- you declare the type, then run inference to populate it.
find_cliques is a pure query that returns vertex cliques without
-modifying the complex.
Typical workflow::
-# Phase 1: Explore — what triangles exist?
-sb.add_face_type("_clique")
-kc = KnowledgeComplex(schema=sb)
-# ... add vertices and edges ...
-result = fill_cliques(kc, max_order=2)
-
-# Phase 2: Inspect
-for fid in result[2]:
- edge_types = {kc.element(e).type for e in kc.boundary(fid)}
- print(f"{fid}: {edge_types}")
-
-# Phase 3: Typed inference with a real schema
-sb2 = SchemaBuilder(namespace="ex")
-sb2.add_face_type("operation", attributes={...})
-kc2 = KnowledgeComplex(schema=sb2)
-# ... add vertices and edges ...
-infer_faces(kc2, "operation", edge_type="performs")
-
-
-
-
-
-
-
-
-
-
-
-find_cliques(kc, k=3, *, edge_type=None)
-
-Find all k-cliques of KC vertices in the edge graph.
-A k-clique is a set of k vertices where every pair is connected by -an edge. This is a pure query — it does not modify the complex.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- k
- |
-
- int
- |
-
-
-
- Clique size (default 3 for triangles). - |
-
- 3
- |
-
- edge_type
- |
-
- str
- |
-
-
-
- Only consider edges of this type when building the adjacency graph. - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- list[frozenset[str]]
- |
-
-
-
- Each element is a frozenset of k vertex IDs. - |
-
knowledgecomplex/clique.py103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 | |
infer_faces(kc, face_type, *, edge_type=None, id_prefix='face', dry_run=False)
-
-Infer and add faces of a declared type from 3-cliques in the edge graph.
-Finds all triangles (3-cliques of KC vertices), resolves the 3 boundary
-edges for each, and calls kc.add_face() with the specified type.
-Skips triangles that already have a face.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- face_type
- |
-
- str
- |
-
-
-
- A registered face type to assign to inferred faces. - |
- - required - | -
- edge_type
- |
-
- str
- |
-
-
-
- Only consider edges of this type when finding triangles. - |
-
- None
- |
-
- id_prefix
- |
-
- str
- |
-
-
-
- Prefix for auto-generated face IDs (e.g. |
-
- 'face'
- |
-
- dry_run
- |
-
- bool
- |
-
-
-
- If |
-
- False
- |
-
Returns:
-| Type | -Description | -
|---|---|
- list[str]
- |
-
-
-
- IDs of newly added (or would-be) faces. - |
-
Raises:
-| Type | -Description | -
|---|---|
- SchemaError
- |
-
-
-
- If face_type is not a registered face type. - |
-
knowledgecomplex/clique.py167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 -227 -228 -229 -230 -231 -232 -233 -234 -235 -236 -237 -238 -239 -240 -241 -242 | |
fill_cliques(kc, max_order=2, *, edge_type=None, id_prefix='clique')
-
-Fill generic simplices for all cliques up to max_order.
-Discovers what higher-order structure exists without requiring semantic
-type declarations. For k=2 (faces), uses the first declared face type.
-For k>2, uses _assert_element directly with the base kc:Element
-type — these are generic, untyped simplices.
This is an exploration tool. Once you've inspected the structure,
-declare typed face types and use :func:infer_faces for semantic
-inference.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- max_order
- |
-
- int
- |
-
-
-
- Maximum simplex dimension to fill (default 2 = faces). - |
-
- 2
- |
-
- edge_type
- |
-
- str
- |
-
-
-
- Only consider edges of this type when finding cliques. - |
-
- None
- |
-
- id_prefix
- |
-
- str
- |
-
-
-
- Prefix for auto-generated IDs. - |
-
- 'clique'
- |
-
Returns:
-| Type | -Description | -
|---|---|
- dict[int, list[str]]
- |
-
-
-
- Mapping from dimension to list of newly added element IDs.
-E.g. |
-
knowledgecomplex/clique.py248 -249 -250 -251 -252 -253 -254 -255 -256 -257 -258 -259 -260 -261 -262 -263 -264 -265 -266 -267 -268 -269 -270 -271 -272 -273 -274 -275 -276 -277 -278 -279 -280 -281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 -313 -314 -315 -316 -317 -318 -319 -320 -321 -322 -323 -324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 -335 -336 -337 -338 -339 -340 -341 -342 -343 | |
dry_run_check(kc, boundary_ids)
-
-Check if an element with this boundary already exists.
- - -knowledgecomplex/clique.py391 -392 -393 -394 -395 -396 -397 -398 -399 | |
knowledgecomplex.codecs.markdown — YAML-frontmatter + markdown codec.
-Implements the :class:~knowledgecomplex.schema.Codec protocol for
-knowledge complexes where each element is a markdown file with YAML
-frontmatter (structured metadata) and a markdown body with predefined
-section headers (prose content).
This follows the pattern used in production knowledge complexes authored
-in Obsidian — each element is a .md file, the YAML header holds
-structured attributes, and ## sections hold prose content.
Usage::
-from knowledgecomplex.codecs import MarkdownCodec
-
-codec = MarkdownCodec(
- frontmatter_attrs=["name", "author", "abstract"],
- section_attrs=["notes", "methodology"],
-)
-kc.register_codec("Paper", codec)
-
-# Compile: KC element -> markdown file at its URI
-kc.element("paper-1").compile()
-
-# Decompile: markdown file -> KC element attributes
-kc.element("paper-1").decompile()
-
-
-
-
-
-
-
-
-
-
-
-MarkdownCodec
-
-
-Codec for YAML-frontmatter + markdown files.
-Each element maps to a single .md file. Attributes are stored in
-two places:
YAML frontmatter (between --- delimiters): structured metadata
- fields like name, author, description. These map 1:1 to
- KC element attributes.
Markdown body sections (## Header blocks): prose content like
- notes or analysis. The section header becomes the attribute name
- (lowercased, spaces replaced with underscores), and the section body
- becomes the attribute value.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- frontmatter_attrs
- |
-
- list[str]
- |
-
-
-
- Attribute names stored in the YAML frontmatter. - |
- - required - | -
- section_attrs
- |
-
- list[str]
- |
-
-
-
- Attribute names stored as |
- - required - | -
knowledgecomplex/codecs/markdown.py40 - 41 - 42 - 43 - 44 - 45 - 46 - 47 - 48 - 49 - 50 - 51 - 52 - 53 - 54 - 55 - 56 - 57 - 58 - 59 - 60 - 61 - 62 - 63 - 64 - 65 - 66 - 67 - 68 - 69 - 70 - 71 - 72 - 73 - 74 - 75 - 76 - 77 - 78 - 79 - 80 - 81 - 82 - 83 - 84 - 85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 | |
compile(element)
-
-Write an element record to a markdown file at its URI.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- element
- |
-
- dict
- |
-
-
-
- Keys: |
- - required - | -
knowledgecomplex/codecs/markdown.py71 - 72 - 73 - 74 - 75 - 76 - 77 - 78 - 79 - 80 - 81 - 82 - 83 - 84 - 85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 -102 -103 -104 -105 -106 | |
decompile(uri)
-
-Read a markdown file and return attribute key-value pairs.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- uri
- |
-
- str
- |
-
-
-
- File URI ( |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- dict
- |
-
-
-
- Attribute key-value pairs (no |
-
knowledgecomplex/codecs/markdown.py108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 | |
verify_documents(kc, directory)
-
-Check consistency between KC elements and markdown files on disk.
-Verifies:
-.md file in the directory has a corresponding element.Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- directory
- |
-
- str or Path
- |
-
-
-
- Root directory containing the markdown files. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- list[str]
- |
-
-
-
- Discrepancy messages. Empty list means everything is consistent. - |
-
knowledgecomplex/codecs/markdown.py159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 | |
knowledgecomplex.diff — Complex diffs and sequences for time-varying complexes.
-A ComplexDiff records element additions and removals. It can be applied
-to a KnowledgeComplex to mutate it, exported to a SPARQL UPDATE string
-for interoperability with RDF-native systems (e.g. flexo MMS), or imported
-from a SPARQL UPDATE string received from a remote system.
A ComplexSequence wraps a base complex and an ordered list of diffs,
-representing a time series of complex states. Element ID sets at each step
-are computed by applying diffs cumulatively.
Example::
-diff = ComplexDiff()
-diff.add_vertex("eve", type="Person")
-diff.add_edge("e-ae", type="Link", vertices={"alice", "eve"})
-diff.remove("old-edge")
-
-diff.apply(kc) # mutate the complex
-sparql = diff.to_sparql(kc) # export as SPARQL UPDATE
-
-# Import a diff from a remote system
-remote_diff = ComplexDiff.from_sparql(sparql, kc)
-remote_diff.apply(kc2)
-
-
-
-
-
-
-
-
-
-
-
-ComplexDiff
-
-
-A set of element additions and removals that transform a complex.
-Build a diff by chaining add_vertex, add_edge, add_face,
-and remove calls. Then apply it to a KnowledgeComplex via
-:meth:apply, or export it to a SPARQL UPDATE string via :meth:to_sparql.
knowledgecomplex/diff.py39 - 40 - 41 - 42 - 43 - 44 - 45 - 46 - 47 - 48 - 49 - 50 - 51 - 52 - 53 - 54 - 55 - 56 - 57 - 58 - 59 - 60 - 61 - 62 - 63 - 64 - 65 - 66 - 67 - 68 - 69 - 70 - 71 - 72 - 73 - 74 - 75 - 76 - 77 - 78 - 79 - 80 - 81 - 82 - 83 - 84 - 85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 -227 -228 -229 -230 -231 -232 -233 -234 -235 -236 -237 -238 -239 -240 -241 -242 -243 -244 -245 -246 -247 -248 -249 -250 -251 -252 -253 -254 -255 -256 -257 -258 -259 -260 -261 -262 -263 -264 -265 -266 -267 -268 -269 -270 -271 -272 -273 -274 -275 -276 -277 -278 -279 -280 -281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 -313 -314 -315 -316 -317 -318 -319 -320 -321 -322 -323 -324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 -335 -336 -337 -338 -339 -340 -341 -342 -343 -344 -345 | |
additions
-
-
- property
-
-
-Element additions: list of dicts with id, type, kind, boundary, attrs.
- -removals
-
-
- property
-
-
-Element removals: list of element IDs.
- -add_vertex(id, type, uri=None, **attrs)
-
-Record a vertex addition.
- - -knowledgecomplex/diff.py63 -64 -65 -66 -67 -68 -69 -70 -71 | |
add_edge(id, type, vertices, uri=None, **attrs)
-
-Record an edge addition.
- - -knowledgecomplex/diff.py73 -74 -75 -76 -77 -78 -79 -80 -81 -82 | |
add_face(id, type, boundary, uri=None, **attrs)
-
-Record a face addition.
- - -knowledgecomplex/diff.py84 -85 -86 -87 -88 -89 -90 -91 -92 -93 | |
remove(id)
-
-Record an element removal.
- - -knowledgecomplex/diff.py95 -96 -97 -98 | |
apply(kc, validate=True)
-
-Apply this diff to a KnowledgeComplex.
-Removals are processed first (highest dimension first to avoid -boundary-closure violations), then additions.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- validate
- |
-
- bool
- |
-
-
-
- If True (default), run SHACL validation after all changes.
-Raises |
-
- True
- |
-
knowledgecomplex/diff.py102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 | |
to_sparql(kc)
-
-Export this diff as a SPARQL UPDATE string.
-Generates DELETE DATA blocks for removals and INSERT DATA
-blocks for additions, using the KC's namespace for IRI construction.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
- Used to read existing triples for removals and to resolve namespaces. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- str
- |
-
-
-
- A SPARQL UPDATE string. - |
-
knowledgecomplex/diff.py155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 | |
from_sparql(sparql, kc)
-
-
- classmethod
-
-
-Parse a SPARQL UPDATE string into a ComplexDiff.
-Extracts INSERT DATA and DELETE DATA blocks, parses their
-triple content, and reconstructs element additions and removals.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- sparql
- |
-
- str
- |
-
-
-
- SPARQL UPDATE string (as produced by :meth: |
- - required - | -
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
- Used to resolve namespaces and determine element kinds. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- ComplexDiff
- |
-
-
-
-
- |
-
knowledgecomplex/diff.py229 -230 -231 -232 -233 -234 -235 -236 -237 -238 -239 -240 -241 -242 -243 -244 -245 -246 -247 -248 -249 -250 -251 -252 -253 -254 -255 -256 -257 -258 -259 -260 -261 -262 -263 -264 -265 -266 -267 -268 -269 -270 -271 -272 -273 -274 -275 -276 -277 -278 -279 -280 -281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 -313 -314 -315 -316 -317 -318 -319 -320 -321 -322 -323 -324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 -335 -336 -337 -338 -339 | |
ComplexSequence
-
-
-A base complex + ordered list of diffs, representing a time series.
-Computes element ID sets at each step by applying diffs cumulatively
-to the base complex's element set. This is a lightweight representation
-that does not reconstruct full KnowledgeComplex instances at each step.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
- The base complex (state at step -1, before any diffs). - |
- - required - | -
- diffs
- |
-
- list[ComplexDiff]
- |
-
-
-
- Ordered sequence of diffs to apply. - |
- - required - | -
knowledgecomplex/diff.py359 -360 -361 -362 -363 -364 -365 -366 -367 -368 -369 -370 -371 -372 -373 -374 -375 -376 -377 -378 -379 -380 -381 -382 -383 -384 -385 -386 -387 -388 -389 -390 -391 -392 -393 -394 -395 -396 -397 -398 -399 -400 -401 -402 -403 -404 -405 -406 -407 -408 -409 -410 -411 -412 -413 -414 -415 -416 -417 -418 -419 -420 -421 -422 -423 -424 -425 -426 -427 -428 -429 | |
complex
-
-
- property
-
-
-The base KnowledgeComplex.
- -diffs
-
-
- property
-
-
-The ordered list of diffs.
- -__getitem__(index)
-
-Element IDs present at step index.
knowledgecomplex/diff.py404 -405 -406 | |
new_at(index)
-
-Elements added at step index (not present in previous step).
knowledgecomplex/diff.py412 -413 -414 -415 -416 -417 -418 | |
removed_at(index)
-
-Elements removed at step index (present in previous, absent now).
knowledgecomplex/diff.py420 -421 -422 -423 -424 -425 -426 | |
knowledgecomplex.exceptions — Public exception types.
-These are the only knowledgecomplex types that cross the API boundary on failure.
- - - - - - - - - - -ValidationError
-
-
-
- Bases: Exception
Raised when a SHACL validation check fails on write.
- - -Attributes:
-| Name | -Type | -Description | -
|---|---|---|
report |
-
- str
- |
-
-
-
- Human-readable SHACL validation report text. - |
-
knowledgecomplex/exceptions.py8 - 9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 | |
UnknownQueryError
-
-
-
- Bases: Exception
Raised when KnowledgeComplex.query() is called with an unregistered template name.
- - - - - - - - -knowledgecomplex/exceptions.py26 -27 -28 -29 -30 | |
SchemaError
-
-
-
- Bases: Exception
Raised when a SchemaBuilder method is called with invalid arguments, -e.g. referencing an undefined type.
- - - - - - - - -knowledgecomplex/exceptions.py33 -34 -35 -36 -37 -38 | |
knowledgecomplex.filtration — Filtrations over knowledge complexes.
-A filtration F = (C₀, C₁, …, Cₘ) is a nested sequence of subcomplexes -where each Cₚ is a valid simplicial complex (closed under boundary) and -Cₚ₋₁ ⊆ Cₚ. Filtrations are semantics-agnostic — they could represent -temporal evolution, thematic layers, trust levels, or any ordering.
- - - - - - - - - - -Filtration
-
-
-An indexed sequence of nested subcomplexes over a KnowledgeComplex.
-Each step is a valid subcomplex (closed under boundary) and each step -contains all elements from the previous step (monotone nesting).
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
- The parent complex that this filtration is defined over. - |
- - required - | -
------filt = Filtration(kc) -filt.append({"v1"}) -filt.append({"v1", "v2", "e12"}) -filt.append({"v1", "v2", "v3", "e12", "e23", "e13", "f123"}) -len(filt) -3 -filt.birth("e12") -1
-
knowledgecomplex/filtration.py18 - 19 - 20 - 21 - 22 - 23 - 24 - 25 - 26 - 27 - 28 - 29 - 30 - 31 - 32 - 33 - 34 - 35 - 36 - 37 - 38 - 39 - 40 - 41 - 42 - 43 - 44 - 45 - 46 - 47 - 48 - 49 - 50 - 51 - 52 - 53 - 54 - 55 - 56 - 57 - 58 - 59 - 60 - 61 - 62 - 63 - 64 - 65 - 66 - 67 - 68 - 69 - 70 - 71 - 72 - 73 - 74 - 75 - 76 - 77 - 78 - 79 - 80 - 81 - 82 - 83 - 84 - 85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 | |
complex
-
-
- property
-
-
-The parent KnowledgeComplex.
- -length
-
-
- property
-
-
-Number of steps in the filtration.
- -is_complete
-
-
- property
-
-
-True if the last step contains all elements in the complex.
- -append(ids)
-
-Append a subcomplex to the filtration.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- ids
- |
-
- set[str]
- |
-
-
-
- Element IDs forming the next step. Must be a valid subcomplex -and a superset of the previous step. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- Filtration (self, for chaining)
- |
-
-
-
-
- |
-
Raises:
-| Type | -Description | -
|---|---|
- ValueError
- |
-
-
-
- If ids is not a valid subcomplex or violates monotonicity. - |
-
knowledgecomplex/filtration.py67 - 68 - 69 - 70 - 71 - 72 - 73 - 74 - 75 - 76 - 77 - 78 - 79 - 80 - 81 - 82 - 83 - 84 - 85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 | |
append_closure(ids)
-
-Append the closure of a set of elements, unioned with the previous step.
-Takes the closure of ids (ensuring a valid subcomplex), unions it -with the previous step (ensuring monotonicity), and appends.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- ids
- |
-
- set[str]
- |
-
-
-
- Element IDs to close over. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- Filtration (self, for chaining)
- |
-
-
-
-
- |
-
knowledgecomplex/filtration.py103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 | |
from_function(kc, fn)
-
-
- classmethod
-
-
-Build a filtration by grouping elements by a function value.
-Calls fn(id) for every element in the complex, groups by return -value, sorts groups, and builds closure at each cumulative step.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
- The parent complex. - |
- - required - | -
- fn
- |
-
- Callable[[str], int | float]
- |
-
-
-
- Function mapping element IDs to filtration values. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- Filtration
- |
-
-
-
-
- |
-
knowledgecomplex/filtration.py125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 | |
birth(id)
-
-Return the index of the first step containing this element.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Element identifier. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- int
- |
-
-
-
-
- |
-
Raises:
-| Type | -Description | -
|---|---|
- ValueError
- |
-
-
-
- If the element does not appear in any step. - |
-
knowledgecomplex/filtration.py172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 | |
new_at(index)
-
-Return elements added at step index (Cₚ \ Cₚ₋₁).
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- index
- |
-
- int
- |
-
-
-
- Step index. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- set[str]
- |
-
-
-
-
- |
-
knowledgecomplex/filtration.py195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 | |
elements_at(index)
-
-Return all elements at step index (same as self[index]).
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- index
- |
-
- int
- |
-
-
-
- Step index. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- set[str]
- |
-
-
-
-
- |
-
knowledgecomplex/filtration.py213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 | |
knowledgecomplex.graph — KnowledgeComplex instance I/O.
-Public API. Never exposes rdflib, pyshacl, or owlrl objects.
-A KnowledgeComplex corresponds to a kc:Complex individual in the RDF graph. -Each add_vertex / add_edge / add_face call asserts the new element AND its -kc:hasElement membership in the complex. SHACL validation on every write -enforces both per-element constraints (EdgeShape, FaceShape) and -boundary-closure (ComplexShape): if a simplex is in the complex, all its -boundary elements must be too.
-This enforces the "slice rule": at every point during construction, the -elements added so far must form a valid complex. Concretely, an element's -boundary elements must already be members before it can be added. This is -a partial ordering — types can be interleaved as long as each element's -boundary predecessors are present (e.g., add v1, v2, edge(v1,v2), v3, -edge(v2,v3), ...). The simplest strategy is to add all vertices, then all -edges, then all faces, but this is not required.
-SPARQL queries are encapsulated as named templates. The framework provides -generic queries in knowledgecomplex/queries/; domain models can supply -additional query directories via the query_dirs parameter.
-The optional uri parameter on add_vertex / add_edge / add_face allows
-callers to attach a file URI to any element via the kc:uri property. This
-is particularly useful for domain applications where each element corresponds
-to an actual document file (e.g. file:///path/to/doc.md).
Element
-
-
-Lightweight proxy for an element in a KnowledgeComplex.
-Provides read-only access to element properties and compile/decompile -methods that delegate to the codec registered for this element's type. -Properties read live from the instance graph on each access.
- - - - - - - - -knowledgecomplex/graph.py85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 | |
compile()
-
-Write this element's record to the artifact at its URI.
- - -knowledgecomplex/graph.py135 -136 -137 -138 -139 -140 -141 -142 | |
decompile()
-
-Read the artifact at this element's URI and update attributes.
- - -knowledgecomplex/graph.py144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 | |
KnowledgeComplex
-
-
-Manage a knowledge complex instance: add elements, validate, query.
-Maps to a kc:Complex individual in the RDF graph. Each element added -via add_vertex / add_edge / add_face becomes a kc:hasElement member of -this complex. Boundary-closure is enforced by ComplexShape on every write -(the "slice rule": every prefix of the insertion sequence is a valid complex). -An element's boundary elements must be added before the element itself.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- schema
- |
-
- SchemaBuilder
- |
-
-
-
- A fully configured schema. The merged OWL + SHACL is loaded into -the internal graph at construction time. - |
- - required - | -
- query_dirs
- |
-
- list[Path]
- |
-
-
-
- Additional directories containing .sparql query templates -(e.g. from domain models). Merged with the framework's built-in queries. - |
-
- None
- |
-
------from knowledgecomplex import SchemaBuilder, KnowledgeComplex, vocab -sb = SchemaBuilder(namespace="aaa") -sb.add_vertex_type("spec") -sb.add_vertex_type("guidance") -sb.add_edge_type("verification", -... attributes={"status": vocab("passing", "failing", "pending")}) -kc = KnowledgeComplex(schema=sb) -kc.add_vertex("spec-001", type="spec", uri="file:///docs/spec-001.md") -kc.add_vertex("guidance-001", type="guidance") -kc.add_edge("ver-001", type="verification", -... vertices={"spec-001", "guidance-001"}, status="passing")
-
knowledgecomplex/graph.py174 - 175 - 176 - 177 - 178 - 179 - 180 - 181 - 182 - 183 - 184 - 185 - 186 - 187 - 188 - 189 - 190 - 191 - 192 - 193 - 194 - 195 - 196 - 197 - 198 - 199 - 200 - 201 - 202 - 203 - 204 - 205 - 206 - 207 - 208 - 209 - 210 - 211 - 212 - 213 - 214 - 215 - 216 - 217 - 218 - 219 - 220 - 221 - 222 - 223 - 224 - 225 - 226 - 227 - 228 - 229 - 230 - 231 - 232 - 233 - 234 - 235 - 236 - 237 - 238 - 239 - 240 - 241 - 242 - 243 - 244 - 245 - 246 - 247 - 248 - 249 - 250 - 251 - 252 - 253 - 254 - 255 - 256 - 257 - 258 - 259 - 260 - 261 - 262 - 263 - 264 - 265 - 266 - 267 - 268 - 269 - 270 - 271 - 272 - 273 - 274 - 275 - 276 - 277 - 278 - 279 - 280 - 281 - 282 - 283 - 284 - 285 - 286 - 287 - 288 - 289 - 290 - 291 - 292 - 293 - 294 - 295 - 296 - 297 - 298 - 299 - 300 - 301 - 302 - 303 - 304 - 305 - 306 - 307 - 308 - 309 - 310 - 311 - 312 - 313 - 314 - 315 - 316 - 317 - 318 - 319 - 320 - 321 - 322 - 323 - 324 - 325 - 326 - 327 - 328 - 329 - 330 - 331 - 332 - 333 - 334 - 335 - 336 - 337 - 338 - 339 - 340 - 341 - 342 - 343 - 344 - 345 - 346 - 347 - 348 - 349 - 350 - 351 - 352 - 353 - 354 - 355 - 356 - 357 - 358 - 359 - 360 - 361 - 362 - 363 - 364 - 365 - 366 - 367 - 368 - 369 - 370 - 371 - 372 - 373 - 374 - 375 - 376 - 377 - 378 - 379 - 380 - 381 - 382 - 383 - 384 - 385 - 386 - 387 - 388 - 389 - 390 - 391 - 392 - 393 - 394 - 395 - 396 - 397 - 398 - 399 - 400 - 401 - 402 - 403 - 404 - 405 - 406 - 407 - 408 - 409 - 410 - 411 - 412 - 413 - 414 - 415 - 416 - 417 - 418 - 419 - 420 - 421 - 422 - 423 - 424 - 425 - 426 - 427 - 428 - 429 - 430 - 431 - 432 - 433 - 434 - 435 - 436 - 437 - 438 - 439 - 440 - 441 - 442 - 443 - 444 - 445 - 446 - 447 - 448 - 449 - 450 - 451 - 452 - 453 - 454 - 455 - 456 - 457 - 458 - 459 - 460 - 461 - 462 - 463 - 464 - 465 - 466 - 467 - 468 - 469 - 470 - 471 - 472 - 473 - 474 - 475 - 476 - 477 - 478 - 479 - 480 - 481 - 482 - 483 - 484 - 485 - 486 - 487 - 488 - 489 - 490 - 491 - 492 - 493 - 494 - 495 - 496 - 497 - 498 - 499 - 500 - 501 - 502 - 503 - 504 - 505 - 506 - 507 - 508 - 509 - 510 - 511 - 512 - 513 - 514 - 515 - 516 - 517 - 518 - 519 - 520 - 521 - 522 - 523 - 524 - 525 - 526 - 527 - 528 - 529 - 530 - 531 - 532 - 533 - 534 - 535 - 536 - 537 - 538 - 539 - 540 - 541 - 542 - 543 - 544 - 545 - 546 - 547 - 548 - 549 - 550 - 551 - 552 - 553 - 554 - 555 - 556 - 557 - 558 - 559 - 560 - 561 - 562 - 563 - 564 - 565 - 566 - 567 - 568 - 569 - 570 - 571 - 572 - 573 - 574 - 575 - 576 - 577 - 578 - 579 - 580 - 581 - 582 - 583 - 584 - 585 - 586 - 587 - 588 - 589 - 590 - 591 - 592 - 593 - 594 - 595 - 596 - 597 - 598 - 599 - 600 - 601 - 602 - 603 - 604 - 605 - 606 - 607 - 608 - 609 - 610 - 611 - 612 - 613 - 614 - 615 - 616 - 617 - 618 - 619 - 620 - 621 - 622 - 623 - 624 - 625 - 626 - 627 - 628 - 629 - 630 - 631 - 632 - 633 - 634 - 635 - 636 - 637 - 638 - 639 - 640 - 641 - 642 - 643 - 644 - 645 - 646 - 647 - 648 - 649 - 650 - 651 - 652 - 653 - 654 - 655 - 656 - 657 - 658 - 659 - 660 - 661 - 662 - 663 - 664 - 665 - 666 - 667 - 668 - 669 - 670 - 671 - 672 - 673 - 674 - 675 - 676 - 677 - 678 - 679 - 680 - 681 - 682 - 683 - 684 - 685 - 686 - 687 - 688 - 689 - 690 - 691 - 692 - 693 - 694 - 695 - 696 - 697 - 698 - 699 - 700 - 701 - 702 - 703 - 704 - 705 - 706 - 707 - 708 - 709 - 710 - 711 - 712 - 713 - 714 - 715 - 716 - 717 - 718 - 719 - 720 - 721 - 722 - 723 - 724 - 725 - 726 - 727 - 728 - 729 - 730 - 731 - 732 - 733 - 734 - 735 - 736 - 737 - 738 - 739 - 740 - 741 - 742 - 743 - 744 - 745 - 746 - 747 - 748 - 749 - 750 - 751 - 752 - 753 - 754 - 755 - 756 - 757 - 758 - 759 - 760 - 761 - 762 - 763 - 764 - 765 - 766 - 767 - 768 - 769 - 770 - 771 - 772 - 773 - 774 - 775 - 776 - 777 - 778 - 779 - 780 - 781 - 782 - 783 - 784 - 785 - 786 - 787 - 788 - 789 - 790 - 791 - 792 - 793 - 794 - 795 - 796 - 797 - 798 - 799 - 800 - 801 - 802 - 803 - 804 - 805 - 806 - 807 - 808 - 809 - 810 - 811 - 812 - 813 - 814 - 815 - 816 - 817 - 818 - 819 - 820 - 821 - 822 - 823 - 824 - 825 - 826 - 827 - 828 - 829 - 830 - 831 - 832 - 833 - 834 - 835 - 836 - 837 - 838 - 839 - 840 - 841 - 842 - 843 - 844 - 845 - 846 - 847 - 848 - 849 - 850 - 851 - 852 - 853 - 854 - 855 - 856 - 857 - 858 - 859 - 860 - 861 - 862 - 863 - 864 - 865 - 866 - 867 - 868 - 869 - 870 - 871 - 872 - 873 - 874 - 875 - 876 - 877 - 878 - 879 - 880 - 881 - 882 - 883 - 884 - 885 - 886 - 887 - 888 - 889 - 890 - 891 - 892 - 893 - 894 - 895 - 896 - 897 - 898 - 899 - 900 - 901 - 902 - 903 - 904 - 905 - 906 - 907 - 908 - 909 - 910 - 911 - 912 - 913 - 914 - 915 - 916 - 917 - 918 - 919 - 920 - 921 - 922 - 923 - 924 - 925 - 926 - 927 - 928 - 929 - 930 - 931 - 932 - 933 - 934 - 935 - 936 - 937 - 938 - 939 - 940 - 941 - 942 - 943 - 944 - 945 - 946 - 947 - 948 - 949 - 950 - 951 - 952 - 953 - 954 - 955 - 956 - 957 - 958 - 959 - 960 - 961 - 962 - 963 - 964 - 965 - 966 - 967 - 968 - 969 - 970 - 971 - 972 - 973 - 974 - 975 - 976 - 977 - 978 - 979 - 980 - 981 - 982 - 983 - 984 - 985 - 986 - 987 - 988 - 989 - 990 - 991 - 992 - 993 - 994 - 995 - 996 - 997 - 998 - 999 -1000 -1001 -1002 -1003 -1004 -1005 -1006 -1007 -1008 -1009 -1010 -1011 -1012 -1013 -1014 -1015 -1016 -1017 -1018 -1019 -1020 -1021 -1022 -1023 -1024 -1025 -1026 -1027 -1028 -1029 -1030 -1031 -1032 -1033 -1034 -1035 -1036 -1037 -1038 -1039 -1040 -1041 -1042 -1043 -1044 -1045 -1046 -1047 -1048 -1049 -1050 -1051 -1052 -1053 -1054 -1055 -1056 -1057 -1058 -1059 -1060 -1061 -1062 -1063 -1064 -1065 -1066 -1067 -1068 -1069 -1070 -1071 -1072 -1073 -1074 -1075 -1076 -1077 -1078 -1079 -1080 -1081 -1082 -1083 -1084 -1085 -1086 -1087 -1088 -1089 -1090 -1091 -1092 -1093 -1094 -1095 -1096 -1097 -1098 -1099 -1100 -1101 -1102 -1103 -1104 -1105 -1106 -1107 | |
verify()
-
-Run SHACL verification on the current instance graph.
-Checks all topological and ontological constraints. Raises on failure.
-Use :meth:audit for a non-throwing alternative.
Raises:
-| Type | -Description | -
|---|---|
- ValidationError
- |
-
-
-
- If any SHACL constraint is violated. - |
-
knowledgecomplex/graph.py291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 | |
audit()
-
-Run SHACL verification and return a structured report.
-Unlike :meth:verify, this never raises — it returns an
-:class:~knowledgecomplex.audit.AuditReport with conforms,
-violations, and text fields.
Returns:
-| Type | -Description | -
|---|---|
- AuditReport
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py314 -315 -316 -317 -318 -319 -320 -321 -322 -323 -324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 | |
deferred_verification()
-
-Context manager that suppresses per-write SHACL verification.
-Inside the context, add_vertex, add_edge, and add_face
-skip SHACL checks. On exit, a single verification pass runs over
-the entire graph. If verification fails, ValidationError is raised.
This is much faster for bulk construction — one SHACL pass instead -of one per element.
- - -------with kc.deferred_verification(): -... kc.add_vertex("v1", type="Node") -... kc.add_vertex("v2", type="Node") -... kc.add_edge("e1", type="Link", vertices={"v1", "v2"})
-
knowledgecomplex/graph.py336 -337 -338 -339 -340 -341 -342 -343 -344 -345 -346 -347 -348 -349 -350 -351 -352 -353 -354 | |
add_vertex(id, type, uri=None, **attributes)
-
-Assert a vertex individual and add it to the complex.
-Asserts the vertex as an individual of the given type (subclass of -KC:Vertex), then asserts kc:hasElement on the complex. Validates via -SHACL. Vertices have empty boundary (k=0), so boundary-closure is -trivially satisfied.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Local identifier for the vertex. - |
- - required - | -
- type
- |
-
- str
- |
-
-
-
- Vertex type name (must be a registered subclass of KC:Vertex). - |
- - required - | -
- uri
- |
-
- str
- |
-
-
-
- Source file URI for this element (e.g. "file:///path/to/doc.md"). -Stored as kc:uri (xsd:anyURI). At-most-one per element. - |
-
- None
- |
-
- **attributes
- |
-
- Any
- |
-
-
-
- Additional attribute values for the vertex. - |
-
- {}
- |
-
Raises:
-| Type | -Description | -
|---|---|
- ValidationError
- |
-
-
-
- If SHACL validation fails after assertion. - |
-
knowledgecomplex/graph.py415 -416 -417 -418 -419 -420 -421 -422 -423 -424 -425 -426 -427 -428 -429 -430 -431 -432 -433 -434 -435 -436 -437 -438 -439 -440 -441 -442 -443 -444 -445 -446 -447 | |
add_edge(id, type, vertices, uri=None, **attributes)
-
-Assert an edge individual, link to boundary vertices, and add to complex.
-Asserts the edge as an individual of the given type (subclass of -KC:Edge), links it to exactly 2 boundary vertices via kc:boundedBy, -then asserts kc:hasElement on the complex. Validates via SHACL including: -- EdgeShape: exactly 2 distinct boundary vertices -- ComplexShape: boundary vertices must already be members of the complex
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Local identifier for the edge. - |
- - required - | -
- type
- |
-
- str
- |
-
-
-
- Edge type name (must be a registered subclass of KC:Edge). - |
- - required - | -
- vertices
- |
-
- set[str] | list[str]
- |
-
-
-
- Exactly 2 vertex IDs forming the boundary of this edge. -Unordered (edges are unoriented). - |
- - required - | -
- uri
- |
-
- str
- |
-
-
-
- Source file URI for this element. - |
-
- None
- |
-
- **attributes
- |
-
- Any
- |
-
-
-
- Attribute values (e.g. status="passing"). - |
-
- {}
- |
-
Raises:
-| Type | -Description | -
|---|---|
- ValueError
- |
-
-
-
- If len(vertices) != 2. - |
-
- ValidationError
- |
-
-
-
- If SHACL validation fails after assertion. - |
-
knowledgecomplex/graph.py449 -450 -451 -452 -453 -454 -455 -456 -457 -458 -459 -460 -461 -462 -463 -464 -465 -466 -467 -468 -469 -470 -471 -472 -473 -474 -475 -476 -477 -478 -479 -480 -481 -482 -483 -484 -485 -486 -487 -488 -489 | |
add_face(id, type, boundary, uri=None, **attributes)
-
-Assert a face individual, link to boundary edges, and add to complex.
-Asserts the face as an individual of the given type (subclass of -KC:Face), links it to exactly 3 boundary edges via kc:boundedBy, -then asserts kc:hasElement on the complex. Validates via SHACL including: -- FaceShape: exactly 3 boundary edges forming a closed triangle -- ComplexShape: boundary edges must already be members of the complex
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Local identifier for the face. - |
- - required - | -
- type
- |
-
- str
- |
-
-
-
- Face type name (must be a registered subclass of KC:Face). - |
- - required - | -
- boundary
- |
-
- list[str]
- |
-
-
-
- Exactly 3 edge IDs forming the boundary of this face. - |
- - required - | -
- uri
- |
-
- str
- |
-
-
-
- Source file URI for this element. - |
-
- None
- |
-
- **attributes
- |
-
- Any
- |
-
-
-
- Attribute values. - |
-
- {}
- |
-
Raises:
-| Type | -Description | -
|---|---|
- ValueError
- |
-
-
-
- If len(boundary) != 3. - |
-
- ValidationError
- |
-
-
-
- If SHACL validation fails after assertion. - |
-
knowledgecomplex/graph.py491 -492 -493 -494 -495 -496 -497 -498 -499 -500 -501 -502 -503 -504 -505 -506 -507 -508 -509 -510 -511 -512 -513 -514 -515 -516 -517 -518 -519 -520 -521 -522 -523 -524 -525 -526 -527 -528 -529 -530 | |
remove_element(id)
-
-Remove an element and all its triples from the complex.
-Removes the element's type assertion, boundary relations (both -directions), attributes, kc:uri, and kc:hasElement membership.
-No validation is performed after removal — the caller is responsible -for ensuring the resulting complex is valid (e.g. removing faces -before their boundary edges).
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Element identifier to remove. - |
- - required - | -
Raises:
-| Type | -Description | -
|---|---|
- ValueError
- |
-
-
-
- If no element with that ID exists. - |
-
knowledgecomplex/graph.py532 -533 -534 -535 -536 -537 -538 -539 -540 -541 -542 -543 -544 -545 -546 -547 -548 -549 -550 -551 -552 -553 -554 -555 -556 -557 -558 -559 -560 -561 -562 | |
query(template_name, **kwargs)
-
-Execute a named SPARQL template and return results as a DataFrame.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- template_name
- |
-
- str
- |
-
-
-
- Name of a registered query template (filename stem from -framework or model query directories). - |
- - required - | -
- **kwargs
- |
-
- Any
- |
-
-
-
- Substitution values for {placeholder} tokens in the template. - |
-
- {}
- |
-
Returns:
-| Type | -Description | -
|---|---|
- DataFrame
- |
-
-
-
- One row per SPARQL result binding. - |
-
Raises:
-| Type | -Description | -
|---|---|
- UnknownQueryError
- |
-
-
-
- If template_name is not registered. - |
-
knowledgecomplex/graph.py564 -565 -566 -567 -568 -569 -570 -571 -572 -573 -574 -575 -576 -577 -578 -579 -580 -581 -582 -583 -584 -585 -586 -587 -588 -589 -590 -591 -592 -593 -594 -595 -596 -597 -598 -599 -600 -601 -602 -603 -604 -605 -606 -607 -608 -609 -610 -611 -612 | |
query_ids(template_name, **kwargs)
-
-Execute a named SPARQL template and return the first column as element IDs.
-Like :meth:query but returns a set[str] of element IDs
-(namespace prefix stripped) instead of a DataFrame. Useful for
-obtaining subcomplexes from parameterized queries.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- template_name
- |
-
- str
- |
-
-
-
- Name of a registered query template. - |
- - required - | -
- **kwargs
- |
-
- Any
- |
-
-
-
- Substitution values for |
-
- {}
- |
-
Returns:
-| Type | -Description | -
|---|---|
- set[str]
- |
-
-
-
-
- |
-
Raises:
-| Type | -Description | -
|---|---|
- UnknownQueryError
- |
-
-
-
- If template_name is not registered. - |
-
knowledgecomplex/graph.py614 -615 -616 -617 -618 -619 -620 -621 -622 -623 -624 -625 -626 -627 -628 -629 -630 -631 -632 -633 -634 -635 -636 -637 -638 -639 -640 -641 -642 -643 -644 -645 | |
dump_graph()
-
-Return the instance graph as a Turtle string.
- - -knowledgecomplex/graph.py647 -648 -649 | |
export(path)
-
-Export the schema, queries, and instance graph to a directory.
-Writes ontology.ttl, shapes.ttl, queries/*.sparql, and instance.ttl.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- path
- |
-
- str | Path
- |
-
-
-
- Target directory. Created if it does not exist. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- Path
- |
-
-
-
- The export directory. - |
-
knowledgecomplex/graph.py651 -652 -653 -654 -655 -656 -657 -658 -659 -660 -661 -662 -663 -664 -665 -666 -667 -668 -669 -670 | |
load(path)
-
-
- classmethod
-
-
-Load a knowledge complex from a directory.
-Reads ontology.ttl and shapes.ttl to reconstruct the schema, -queries/*.sparql for query templates, and instance.ttl (if present) -for the instance graph.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- path
- |
-
- str | Path
- |
-
-
-
- Directory containing at minimum ontology.ttl and shapes.ttl. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- KnowledgeComplex
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py672 -673 -674 -675 -676 -677 -678 -679 -680 -681 -682 -683 -684 -685 -686 -687 -688 -689 -690 -691 -692 -693 -694 -695 -696 -697 -698 | |
element(id)
-
-Get an Element handle for the given element ID.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Local identifier of the element. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- Element
- |
-
-
-
-
- |
-
Raises:
-| Type | -Description | -
|---|---|
- ValueError
- |
-
-
-
- If no element with that ID exists in the graph. - |
-
knowledgecomplex/graph.py702 -703 -704 -705 -706 -707 -708 -709 -710 -711 -712 -713 -714 -715 -716 -717 -718 -719 -720 -721 -722 -723 | |
element_ids(type=None)
-
-List element IDs, optionally filtered by type (includes subtypes).
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- type
- |
-
- str
- |
-
-
-
- Filter to elements of this type or any subtype. - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- list[str]
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py725 -726 -727 -728 -729 -730 -731 -732 -733 -734 -735 -736 -737 -738 -739 -740 -741 -742 -743 -744 -745 -746 -747 -748 -749 -750 -751 -752 -753 -754 -755 -756 -757 -758 -759 -760 -761 -762 -763 -764 -765 -766 -767 -768 | |
elements(type=None)
-
-List Element handles, optionally filtered by type (includes subtypes).
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- type
- |
-
- str
- |
-
-
-
- Filter to elements of this type or any subtype. - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- list[Element]
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py770 -771 -772 -773 -774 -775 -776 -777 -778 -779 -780 -781 -782 -783 | |
is_subcomplex(ids)
-
-Check whether a set of element IDs forms a valid subcomplex.
-A set is a valid subcomplex iff it is closed under the boundary -operator: for every element in the set, all its boundary elements -are also in the set.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- ids
- |
-
- set[str]
- |
-
-
-
- Element identifiers to check. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- bool
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py785 -786 -787 -788 -789 -790 -791 -792 -793 -794 -795 -796 -797 -798 -799 -800 -801 -802 -803 -804 | |
boundary(id, *, type=None)
-
-Return ∂(id): the direct faces of element id via kc:boundedBy.
-For a vertex, returns the empty set. -For an edge, returns its 2 boundary vertices. -For a face, returns its 3 boundary edges.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Element identifier. - |
- - required - | -
- type
- |
-
- str
- |
-
-
-
- Filter results to this type (including subtypes). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- set[str]
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py839 -840 -841 -842 -843 -844 -845 -846 -847 -848 -849 -850 -851 -852 -853 -854 -855 -856 -857 -858 -859 -860 -861 -862 | |
coboundary(id, *, type=None)
-
-Return the cofaces of id: all simplices whose boundary contains id.
-Computes {τ ∈ K : id ∈ ∂(τ)} — the set of (k+1)-simplices that -have id as a boundary element. This is the combinatorial coface -relation, not the algebraic coboundary operator δ on cochains.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Element identifier. - |
- - required - | -
- type
- |
-
- str
- |
-
-
-
- Filter results to this type (including subtypes). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- set[str]
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py864 -865 -866 -867 -868 -869 -870 -871 -872 -873 -874 -875 -876 -877 -878 -879 -880 -881 -882 -883 -884 -885 -886 -887 -888 -889 -890 | |
star(id, *, type=None)
-
-Return St(id): all simplices containing id as a face (transitive coboundary + self).
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Element identifier. - |
- - required - | -
- type
- |
-
- str
- |
-
-
-
- Filter results to this type (including subtypes). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- set[str]
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py892 -893 -894 -895 -896 -897 -898 -899 -900 -901 -902 -903 -904 -905 -906 -907 -908 -909 -910 -911 | |
closure(ids, *, type=None)
-
-Return Cl(ids): the smallest subcomplex containing ids.
-Accepts a single ID or a set of IDs. When given a set, returns the -union of closures.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- ids
- |
-
- str or set[str]
- |
-
-
-
- Element identifier(s). - |
- - required - | -
- type
- |
-
- str
- |
-
-
-
- Filter results to this type (including subtypes). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- set[str]
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py913 -914 -915 -916 -917 -918 -919 -920 -921 -922 -923 -924 -925 -926 -927 -928 -929 -930 -931 -932 -933 -934 -935 -936 -937 -938 -939 -940 -941 -942 -943 -944 -945 -946 -947 -948 | |
closed_star(id, *, type=None)
-
-Return Cl(St(id)): the closure of the star.
-Always a valid subcomplex.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Element identifier. - |
- - required - | -
- type
- |
-
- str
- |
-
-
-
- Filter results to this type (including subtypes). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- set[str]
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py950 -951 -952 -953 -954 -955 -956 -957 -958 -959 -960 -961 -962 -963 -964 -965 -966 | |
link(id, *, type=None)
-
-Return Lk(id): Cl(St(id)) \ St(id).
-The link is the set of simplices in the closed star that do not -themselves contain id as a face.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Element identifier. - |
- - required - | -
- type
- |
-
- str
- |
-
-
-
- Filter results to this type (including subtypes). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- set[str]
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py968 -969 -970 -971 -972 -973 -974 -975 -976 -977 -978 -979 -980 -981 -982 -983 -984 -985 -986 -987 -988 -989 | |
skeleton(k)
-
-Return sk_k(K): all elements of dimension <= k.
-k=0: vertices only -k=1: vertices and edges -k=2: vertices, edges, and faces (everything)
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- k
- |
-
- int
- |
-
-
-
- Maximum dimension (0, 1, or 2). - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- set[str]
- |
-
-
-
-
- |
-
Raises:
-| Type | -Description | -
|---|---|
- ValueError
- |
-
-
-
- If k < 0 or k > 2. - |
-
knowledgecomplex/graph.py991 - 992 - 993 - 994 - 995 - 996 - 997 - 998 - 999 -1000 -1001 -1002 -1003 -1004 -1005 -1006 -1007 -1008 -1009 -1010 -1011 -1012 -1013 -1014 -1015 -1016 -1017 -1018 -1019 -1020 -1021 -1022 -1023 -1024 -1025 -1026 -1027 -1028 | |
degree(id)
-
-Return deg(id): the number of edges incident to vertex id.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- id
- |
-
- str
- |
-
-
-
- Vertex identifier. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- int
- |
-
-
-
-
- |
-
knowledgecomplex/graph.py1030 -1031 -1032 -1033 -1034 -1035 -1036 -1037 -1038 -1039 -1040 -1041 -1042 -1043 -1044 -1045 -1046 -1047 -1048 -1049 -1050 -1051 -1052 -1053 -1054 | |
register_codec(type_name, codec)
-
-Register a codec for the given type.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- type_name
- |
-
- str
- |
-
-
-
- Must be a registered type in the schema. - |
- - required - | -
- codec
- |
-
- Codec
- |
-
-
-
- Object implementing compile() and decompile(). - |
- - required - | -
knowledgecomplex/graph.py1058 -1059 -1060 -1061 -1062 -1063 -1064 -1065 -1066 -1067 -1068 -1069 -1070 -1071 -1072 -1073 -1074 -1075 | |
decompile_uri(type_name, uri)
-
-Decompile an artifact at a URI without adding it to the graph.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- type_name
- |
-
- str
- |
-
-
-
- The element type (used to resolve the codec). - |
- - required - | -
- uri
- |
-
- str
- |
-
-
-
- URI of the artifact to read. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- dict
- |
-
-
-
- Attribute key-value pairs. - |
-
knowledgecomplex/graph.py1088 -1089 -1090 -1091 -1092 -1093 -1094 -1095 -1096 -1097 -1098 -1099 -1100 -1101 -1102 -1103 -1104 -1105 -1106 -1107 | |
File-based import/export utilities for KnowledgeComplex.
- - -Functions:
-| Name | -Description | -
|---|---|
save_graph Serialize the instance graph to a file. |
-
-
-
-
- |
-
load_graph Parse a file into the instance graph |
-
-
-
-
- |
-
dump_graph Return the instance graph as a string in a given format. |
-
-
-
-
- |
-
.ttl) is the default format — human-readable and consistent
- with the ontology/shapes patterns used throughout the codebase.graph.parse() which
- adds triples to the existing graph. Load into a fresh
- KnowledgeComplex for a clean restore..trig) or N-Quads (.nq) — KnowledgeComplex uses a
- plain rdflib.Graph, not a ConjunctiveGraph.Adapted from discourse_graph.io (multi-agent-dg).
-save_graph(kc, path, format='turtle')
-
-Serialize kc._instance_graph to a file.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- 'KnowledgeComplex'
- |
-
-
-
- The |
- - required - | -
- path
- |
-
- 'Path | str'
- |
-
-
-
- Destination file path. The file is created or overwritten. - |
- - required - | -
- format
- |
-
- str
- |
-
-
-
- rdflib serialization format string. Defaults to |
-
- 'turtle'
- |
-
knowledgecomplex/io.py73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 | |
load_graph(kc, path, format=None, validate=False)
-
-Parse a file into kc._instance_graph (additive).
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- 'KnowledgeComplex'
- |
-
-
-
- The |
- - required - | -
- path
- |
-
- 'Path | str'
- |
-
-
-
- Source file path. - |
- - required - | -
- format
- |
-
- Optional[str]
- |
-
-
-
- rdflib serialization format string. When |
-
- None
- |
-
- validate
- |
-
- bool
- |
-
-
-
- If |
-
- False
- |
-
This operation is additive: existing triples in the instance graph
-are retained. For a clean restore, load into a freshly constructed
-KnowledgeComplex.
The instance graph includes TBox (ontology) triples. Loading a file -that was saved from a KC with the same schema is harmless — rdflib -deduplicates triples. Loading data from a different schema will merge -ontologies; the caller is responsible for schema compatibility.
-knowledgecomplex/io.py95 - 96 - 97 - 98 - 99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 | |
dump_graph(kc, format='turtle')
-
-Return the instance graph as a string in the requested format.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- 'KnowledgeComplex'
- |
-
-
-
- The |
- - required - | -
- format
- |
-
- str
- |
-
-
-
- rdflib serialization format string. Defaults to |
-
- 'turtle'
- |
-
Returns:
-| Type | -Description | -
|---|---|
- str
- |
-
-
-
- The serialized graph. - |
-
knowledgecomplex/io.py149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 | |
knowledgecomplex.schema — SchemaBuilder and vocab/text descriptors.
-Public API. Never exposes rdflib, pyshacl, or owlrl objects.
-Internal structure mirrors the 2x2 responsibility map: - {topological, ontological} x {OWL, SHACL}
-The core ontology defines KC:Element as the base class for all simplices, -with KC:Vertex (k=0), KC:Edge (k=1), KC:Face (k=2) as subclasses. -add_vertex_type / add_edge_type / add_face_type each declare a user type -as a subclass of the appropriate simplex class and write to both internal -OWL and SHACL graphs.
-dump_owl() and dump_shacl() return merged (core + user) Turtle strings.
- - - - - - - - - - -Codec
-
-
-
- Bases: Protocol
Bidirectional bridge between element records and artifacts at URIs.
-A codec pairs compile (map → territory) and decompile (territory → map) -for a given element type. Registered on KnowledgeComplex instances via -register_codec(), and inherited by child types.
- - - - - - - - -knowledgecomplex/schema.py39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 | |
compile(element)
-
-Write an element record to the artifact at its URI.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- element
- |
-
- dict
- |
-
-
-
- Keys: id, type, uri, plus all attribute key-value pairs. - |
- - required - | -
knowledgecomplex/schema.py49 -50 -51 -52 -53 -54 -55 -56 -57 -58 | |
decompile(uri)
-
-Read the artifact at a URI and return an attribute dict.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- uri
- |
-
- str
- |
-
-
-
- The URI of the artifact to read. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- dict
- |
-
-
-
- Attribute key-value pairs suitable for add_vertex/add_edge/add_face kwargs. - |
-
knowledgecomplex/schema.py60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 | |
VocabDescriptor
-
-
-
- dataclass
-
-
-Returned by vocab(). Carries the allowed string values for an attribute. -Generates both an OWL rdfs:comment annotation and a SHACL sh:in constraint -when passed to add_*_type().
- - - - - - - - -knowledgecomplex/schema.py77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 | |
TextDescriptor
-
-
-
- dataclass
-
-
-Returned by text(). Marks an attribute as a free-text string (no controlled vocabulary). -Generates an OWL DatatypeProperty with xsd:string range and a SHACL property shape -with sh:datatype xsd:string but no sh:in constraint.
- - - - - - - - -knowledgecomplex/schema.py120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 | |
SchemaBuilder
-
-
-Author a knowledge complex schema: vertex types, edge types, face types.
-Each add_*_type call declares a new OWL subclass of the appropriate -KC:Element subclass (Vertex, Edge, or Face) and creates a corresponding -SHACL node shape. Both OWL and SHACL graphs are maintained internally. -dump_owl() / dump_shacl() return the full merged Turtle strings.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- namespace
- |
-
- str
- |
-
-
-
- Short namespace token for user-defined classes and properties. -Used to build IRI prefix: https://example.org/{namespace}# - |
- - required - | -
------sb = SchemaBuilder(namespace="aaa") -sb.add_vertex_type("spec") -sb.add_edge_type("verification", -... attributes={"status": vocab("passing", "failing", "pending")}) -sb.add_face_type("assurance") -owl_ttl = sb.dump_owl() -shacl_ttl = sb.dump_shacl()
-
knowledgecomplex/schema.py165 - 166 - 167 - 168 - 169 - 170 - 171 - 172 - 173 - 174 - 175 - 176 - 177 - 178 - 179 - 180 - 181 - 182 - 183 - 184 - 185 - 186 - 187 - 188 - 189 - 190 - 191 - 192 - 193 - 194 - 195 - 196 - 197 - 198 - 199 - 200 - 201 - 202 - 203 - 204 - 205 - 206 - 207 - 208 - 209 - 210 - 211 - 212 - 213 - 214 - 215 - 216 - 217 - 218 - 219 - 220 - 221 - 222 - 223 - 224 - 225 - 226 - 227 - 228 - 229 - 230 - 231 - 232 - 233 - 234 - 235 - 236 - 237 - 238 - 239 - 240 - 241 - 242 - 243 - 244 - 245 - 246 - 247 - 248 - 249 - 250 - 251 - 252 - 253 - 254 - 255 - 256 - 257 - 258 - 259 - 260 - 261 - 262 - 263 - 264 - 265 - 266 - 267 - 268 - 269 - 270 - 271 - 272 - 273 - 274 - 275 - 276 - 277 - 278 - 279 - 280 - 281 - 282 - 283 - 284 - 285 - 286 - 287 - 288 - 289 - 290 - 291 - 292 - 293 - 294 - 295 - 296 - 297 - 298 - 299 - 300 - 301 - 302 - 303 - 304 - 305 - 306 - 307 - 308 - 309 - 310 - 311 - 312 - 313 - 314 - 315 - 316 - 317 - 318 - 319 - 320 - 321 - 322 - 323 - 324 - 325 - 326 - 327 - 328 - 329 - 330 - 331 - 332 - 333 - 334 - 335 - 336 - 337 - 338 - 339 - 340 - 341 - 342 - 343 - 344 - 345 - 346 - 347 - 348 - 349 - 350 - 351 - 352 - 353 - 354 - 355 - 356 - 357 - 358 - 359 - 360 - 361 - 362 - 363 - 364 - 365 - 366 - 367 - 368 - 369 - 370 - 371 - 372 - 373 - 374 - 375 - 376 - 377 - 378 - 379 - 380 - 381 - 382 - 383 - 384 - 385 - 386 - 387 - 388 - 389 - 390 - 391 - 392 - 393 - 394 - 395 - 396 - 397 - 398 - 399 - 400 - 401 - 402 - 403 - 404 - 405 - 406 - 407 - 408 - 409 - 410 - 411 - 412 - 413 - 414 - 415 - 416 - 417 - 418 - 419 - 420 - 421 - 422 - 423 - 424 - 425 - 426 - 427 - 428 - 429 - 430 - 431 - 432 - 433 - 434 - 435 - 436 - 437 - 438 - 439 - 440 - 441 - 442 - 443 - 444 - 445 - 446 - 447 - 448 - 449 - 450 - 451 - 452 - 453 - 454 - 455 - 456 - 457 - 458 - 459 - 460 - 461 - 462 - 463 - 464 - 465 - 466 - 467 - 468 - 469 - 470 - 471 - 472 - 473 - 474 - 475 - 476 - 477 - 478 - 479 - 480 - 481 - 482 - 483 - 484 - 485 - 486 - 487 - 488 - 489 - 490 - 491 - 492 - 493 - 494 - 495 - 496 - 497 - 498 - 499 - 500 - 501 - 502 - 503 - 504 - 505 - 506 - 507 - 508 - 509 - 510 - 511 - 512 - 513 - 514 - 515 - 516 - 517 - 518 - 519 - 520 - 521 - 522 - 523 - 524 - 525 - 526 - 527 - 528 - 529 - 530 - 531 - 532 - 533 - 534 - 535 - 536 - 537 - 538 - 539 - 540 - 541 - 542 - 543 - 544 - 545 - 546 - 547 - 548 - 549 - 550 - 551 - 552 - 553 - 554 - 555 - 556 - 557 - 558 - 559 - 560 - 561 - 562 - 563 - 564 - 565 - 566 - 567 - 568 - 569 - 570 - 571 - 572 - 573 - 574 - 575 - 576 - 577 - 578 - 579 - 580 - 581 - 582 - 583 - 584 - 585 - 586 - 587 - 588 - 589 - 590 - 591 - 592 - 593 - 594 - 595 - 596 - 597 - 598 - 599 - 600 - 601 - 602 - 603 - 604 - 605 - 606 - 607 - 608 - 609 - 610 - 611 - 612 - 613 - 614 - 615 - 616 - 617 - 618 - 619 - 620 - 621 - 622 - 623 - 624 - 625 - 626 - 627 - 628 - 629 - 630 - 631 - 632 - 633 - 634 - 635 - 636 - 637 - 638 - 639 - 640 - 641 - 642 - 643 - 644 - 645 - 646 - 647 - 648 - 649 - 650 - 651 - 652 - 653 - 654 - 655 - 656 - 657 - 658 - 659 - 660 - 661 - 662 - 663 - 664 - 665 - 666 - 667 - 668 - 669 - 670 - 671 - 672 - 673 - 674 - 675 - 676 - 677 - 678 - 679 - 680 - 681 - 682 - 683 - 684 - 685 - 686 - 687 - 688 - 689 - 690 - 691 - 692 - 693 - 694 - 695 - 696 - 697 - 698 - 699 - 700 - 701 - 702 - 703 - 704 - 705 - 706 - 707 - 708 - 709 - 710 - 711 - 712 - 713 - 714 - 715 - 716 - 717 - 718 - 719 - 720 - 721 - 722 - 723 - 724 - 725 - 726 - 727 - 728 - 729 - 730 - 731 - 732 - 733 - 734 - 735 - 736 - 737 - 738 - 739 - 740 - 741 - 742 - 743 - 744 - 745 - 746 - 747 - 748 - 749 - 750 - 751 - 752 - 753 - 754 - 755 - 756 - 757 - 758 - 759 - 760 - 761 - 762 - 763 - 764 - 765 - 766 - 767 - 768 - 769 - 770 - 771 - 772 - 773 - 774 - 775 - 776 - 777 - 778 - 779 - 780 - 781 - 782 - 783 - 784 - 785 - 786 - 787 - 788 - 789 - 790 - 791 - 792 - 793 - 794 - 795 - 796 - 797 - 798 - 799 - 800 - 801 - 802 - 803 - 804 - 805 - 806 - 807 - 808 - 809 - 810 - 811 - 812 - 813 - 814 - 815 - 816 - 817 - 818 - 819 - 820 - 821 - 822 - 823 - 824 - 825 - 826 - 827 - 828 - 829 - 830 - 831 - 832 - 833 - 834 - 835 - 836 - 837 - 838 - 839 - 840 - 841 - 842 - 843 - 844 - 845 - 846 - 847 - 848 - 849 - 850 - 851 - 852 - 853 - 854 - 855 - 856 - 857 - 858 - 859 - 860 - 861 - 862 - 863 - 864 - 865 - 866 - 867 - 868 - 869 - 870 - 871 - 872 - 873 - 874 - 875 - 876 - 877 - 878 - 879 - 880 - 881 - 882 - 883 - 884 - 885 - 886 - 887 - 888 - 889 - 890 - 891 - 892 - 893 - 894 - 895 - 896 - 897 - 898 - 899 - 900 - 901 - 902 - 903 - 904 - 905 - 906 - 907 - 908 - 909 - 910 - 911 - 912 - 913 - 914 - 915 - 916 - 917 - 918 - 919 - 920 - 921 - 922 - 923 - 924 - 925 - 926 - 927 - 928 - 929 - 930 - 931 - 932 - 933 - 934 - 935 - 936 - 937 - 938 - 939 - 940 - 941 - 942 - 943 - 944 - 945 - 946 - 947 - 948 - 949 - 950 - 951 - 952 - 953 - 954 - 955 - 956 - 957 - 958 - 959 - 960 - 961 - 962 - 963 - 964 - 965 - 966 - 967 - 968 - 969 - 970 - 971 - 972 - 973 - 974 - 975 - 976 - 977 - 978 - 979 - 980 - 981 - 982 - 983 - 984 - 985 - 986 - 987 - 988 - 989 - 990 - 991 - 992 - 993 - 994 - 995 - 996 - 997 - 998 - 999 -1000 -1001 -1002 -1003 -1004 -1005 -1006 -1007 -1008 -1009 -1010 -1011 -1012 -1013 -1014 -1015 -1016 -1017 -1018 -1019 -1020 -1021 -1022 -1023 -1024 -1025 -1026 -1027 -1028 -1029 -1030 -1031 -1032 -1033 -1034 -1035 -1036 -1037 -1038 -1039 -1040 -1041 -1042 -1043 -1044 -1045 -1046 -1047 -1048 -1049 -1050 -1051 -1052 -1053 -1054 -1055 -1056 -1057 -1058 -1059 -1060 -1061 -1062 -1063 -1064 -1065 -1066 -1067 -1068 -1069 -1070 -1071 -1072 -1073 -1074 -1075 -1076 -1077 -1078 -1079 -1080 -1081 -1082 -1083 -1084 -1085 -1086 -1087 -1088 -1089 -1090 -1091 -1092 -1093 -1094 -1095 -1096 -1097 -1098 -1099 -1100 -1101 -1102 -1103 -1104 -1105 -1106 -1107 -1108 -1109 -1110 -1111 -1112 -1113 -1114 -1115 -1116 -1117 -1118 -1119 -1120 -1121 -1122 -1123 -1124 -1125 -1126 -1127 -1128 -1129 -1130 -1131 -1132 -1133 -1134 -1135 -1136 -1137 -1138 -1139 -1140 -1141 -1142 -1143 -1144 -1145 -1146 -1147 -1148 -1149 -1150 -1151 -1152 -1153 -1154 -1155 -1156 -1157 -1158 -1159 -1160 -1161 -1162 -1163 -1164 -1165 -1166 -1167 -1168 -1169 -1170 -1171 -1172 -1173 -1174 -1175 -1176 -1177 -1178 -1179 -1180 -1181 -1182 -1183 -1184 -1185 -1186 -1187 -1188 -1189 -1190 -1191 -1192 -1193 -1194 -1195 -1196 -1197 -1198 -1199 -1200 -1201 -1202 -1203 -1204 -1205 -1206 -1207 -1208 -1209 -1210 -1211 -1212 -1213 -1214 -1215 -1216 -1217 -1218 -1219 -1220 -1221 -1222 -1223 -1224 -1225 -1226 -1227 -1228 -1229 -1230 -1231 -1232 -1233 -1234 -1235 -1236 -1237 -1238 -1239 -1240 -1241 -1242 | |
add_vertex_type(name, attributes=None, parent=None, bind=None)
-
-Declare a new vertex type (OWL subclass of KC:Vertex + SHACL node shape).
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- name
- |
-
- str
- |
-
-
-
- Class name within the user namespace. - |
- - required - | -
- attributes
- |
-
- dict
- |
-
-
-
- Mapping of attribute name to descriptor (VocabDescriptor, TextDescriptor, -or dict with "vocab"/"text" key and optional "required" flag). - |
-
- None
- |
-
- parent
- |
-
- str
- |
-
-
-
- Name of a registered vertex type to inherit from. - |
-
- None
- |
-
- bind
- |
-
- dict
- |
-
-
-
- Mapping of attribute names to fixed string values (sh:hasValue). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- SchemaBuilder (self, for chaining)
- |
-
-
-
-
- |
-
knowledgecomplex/schema.py405 -406 -407 -408 -409 -410 -411 -412 -413 -414 -415 -416 -417 -418 -419 -420 -421 -422 -423 -424 -425 -426 -427 -428 -429 -430 -431 -432 -433 -434 -435 -436 -437 -438 -439 -440 -441 -442 -443 -444 -445 -446 -447 -448 -449 -450 -451 -452 -453 -454 -455 -456 -457 -458 -459 -460 -461 -462 -463 -464 -465 -466 -467 -468 -469 | |
add_edge_type(name, attributes=None, parent=None, bind=None)
-
-Declare a new edge type (OWL subclass of KC:Edge + SHACL property shapes).
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- name
- |
-
- str
- |
-
-
-
- Class name within the user namespace. - |
- - required - | -
- attributes
- |
-
- dict
- |
-
-
-
- Mapping of attribute name to descriptor (VocabDescriptor, TextDescriptor, -or dict with "vocab"/"text" key and optional "required" flag). - |
-
- None
- |
-
- parent
- |
-
- str
- |
-
-
-
- Name of a registered edge type to inherit from. - |
-
- None
- |
-
- bind
- |
-
- dict
- |
-
-
-
- Mapping of attribute names to fixed string values (sh:hasValue). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- SchemaBuilder (self, for chaining)
- |
-
-
-
-
- |
-
knowledgecomplex/schema.py471 -472 -473 -474 -475 -476 -477 -478 -479 -480 -481 -482 -483 -484 -485 -486 -487 -488 -489 -490 -491 -492 -493 -494 -495 -496 -497 -498 -499 -500 -501 -502 -503 -504 -505 -506 -507 -508 -509 -510 -511 -512 -513 -514 -515 -516 -517 -518 -519 -520 -521 -522 -523 -524 -525 -526 -527 -528 -529 -530 -531 -532 -533 -534 | |
add_face_type(name, attributes=None, parent=None, bind=None)
-
-Declare a new face type (OWL subclass of KC:Face + SHACL property shapes).
-Attributes with required=False generate sh:minCount 0 constraints.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- name
- |
-
- str
- |
-
-
-
- Class name within the user namespace. - |
- - required - | -
- attributes
- |
-
- dict
- |
-
-
-
- Mapping of attribute name to descriptor (VocabDescriptor, TextDescriptor, -or dict with "vocab"/"text" key and optional "required" flag). - |
-
- None
- |
-
- parent
- |
-
- str
- |
-
-
-
- Name of a registered face type to inherit from. - |
-
- None
- |
-
- bind
- |
-
- dict
- |
-
-
-
- Mapping of attribute names to fixed string values (sh:hasValue). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- SchemaBuilder (self, for chaining)
- |
-
-
-
-
- |
-
knowledgecomplex/schema.py536 -537 -538 -539 -540 -541 -542 -543 -544 -545 -546 -547 -548 -549 -550 -551 -552 -553 -554 -555 -556 -557 -558 -559 -560 -561 -562 -563 -564 -565 -566 -567 -568 -569 -570 -571 -572 -573 -574 -575 -576 -577 -578 -579 -580 -581 -582 -583 -584 -585 -586 -587 -588 -589 -590 -591 -592 -593 -594 -595 -596 -597 -598 -599 -600 -601 | |
describe_type(name)
-
-Inspect a registered type's attributes, parent, and bindings.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- name
- |
-
- str
- |
-
-
-
- The registered type name. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- dict
- |
-
-
-
- Keys: name, kind, parent, own_attributes, inherited_attributes, -all_attributes, bound. - |
-
knowledgecomplex/schema.py603 -604 -605 -606 -607 -608 -609 -610 -611 -612 -613 -614 -615 -616 -617 -618 -619 -620 -621 -622 -623 -624 -625 -626 -627 -628 -629 -630 -631 -632 -633 -634 -635 -636 -637 -638 -639 -640 -641 -642 -643 -644 -645 -646 | |
type_names(kind=None)
-
-List registered type names, optionally filtered by kind.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kind
- |
-
- str
- |
-
-
-
- Filter by "vertex", "edge", or "face". - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- list[str]
- |
-
-
-
-
- |
-
knowledgecomplex/schema.py648 -649 -650 -651 -652 -653 -654 -655 -656 -657 -658 -659 -660 -661 -662 -663 | |
promote_to_attribute(type, attribute, vocab=None, text=None, required=True)
-
-Atomically promote a discovered pattern to a first-class typed attribute.
-Updates both OWL property definition and SHACL shape constraint for the named type. -After calling this, dump_owl() and dump_shacl() both reflect the updated attribute.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- type
- |
-
- str
- |
-
-
-
- The type name (must have been registered via add_*_type). - |
- - required - | -
- attribute
- |
-
- str
- |
-
-
-
- Attribute name to add or upgrade. - |
- - required - | -
- vocab
- |
-
- VocabDescriptor
- |
-
-
-
- Controlled vocabulary for the attribute. - |
-
- None
- |
-
- text
- |
-
- TextDescriptor
- |
-
-
-
- Free-text descriptor for the attribute. - |
-
- None
- |
-
- required
- |
-
- bool
- |
-
-
-
- If True, generates sh:minCount 1. Overrides the descriptor's own required flag. - |
-
- True
- |
-
Returns:
-| Type | -Description | -
|---|---|
- SchemaBuilder (self, for chaining)
- |
-
-
-
-
- |
-
knowledgecomplex/schema.py665 -666 -667 -668 -669 -670 -671 -672 -673 -674 -675 -676 -677 -678 -679 -680 -681 -682 -683 -684 -685 -686 -687 -688 -689 -690 -691 -692 -693 -694 -695 -696 -697 -698 -699 -700 -701 -702 -703 -704 -705 -706 -707 -708 -709 -710 -711 -712 -713 -714 -715 -716 -717 -718 -719 -720 -721 -722 -723 -724 -725 -726 -727 -728 -729 -730 -731 -732 -733 -734 -735 -736 -737 -738 -739 -740 -741 -742 | |
add_sparql_constraint(type_name, sparql, message)
-
-Attach a sh:sparql constraint to the SHACL shape for type_name.
-The sparql argument must be a SPARQL SELECT query that returns $this -for each violating focus node. pyshacl evaluates this and reports the -message for each returned row.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- type_name
- |
-
- str
- |
-
-
-
- The type name (must have been registered via add_*_type). - |
- - required - | -
- sparql
- |
-
- str
- |
-
-
-
- SPARQL SELECT query. Must bind $this to each violating node. - |
- - required - | -
- message
- |
-
- str
- |
-
-
-
- Human-readable message reported when the constraint is violated. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- SchemaBuilder (self, for chaining)
- |
-
-
-
-
- |
-
knowledgecomplex/schema.py744 -745 -746 -747 -748 -749 -750 -751 -752 -753 -754 -755 -756 -757 -758 -759 -760 -761 -762 -763 -764 -765 -766 -767 -768 -769 -770 -771 -772 -773 -774 -775 -776 -777 -778 -779 | |
add_query(name, operation, *, target_type=None)
-
-Register a named topological query template on this schema.
-The query is generated from a topological operation and optional type
-filter, then stored internally. It is exported as a .sparql file
-by :meth:export and automatically loaded by
-:class:~knowledgecomplex.graph.KnowledgeComplex at runtime.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- name
- |
-
- str
- |
-
-
-
- Query template name (becomes the filename stem, e.g. |
- - required - | -
- operation
- |
-
- str
- |
-
-
-
- Topological operation: |
- - required - | -
- target_type
- |
-
- str
- |
-
-
-
- Filter results to this type (including subtypes via OWL class hierarchy). - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- SchemaBuilder (self, for chaining)
- |
-
-
-
-
- |
-
------sb.add_query("spec_coboundary", "coboundary", target_type="verification")
-
knowledgecomplex/schema.py871 -872 -873 -874 -875 -876 -877 -878 -879 -880 -881 -882 -883 -884 -885 -886 -887 -888 -889 -890 -891 -892 -893 -894 -895 -896 -897 -898 -899 -900 -901 -902 -903 -904 -905 -906 -907 -908 | |
add_topological_constraint(type_name, operation, *, target_type=None, predicate='min_count', min_count=1, max_count=None, message=None)
-
-Escalate a topological query to a SHACL constraint.
-Generates a sh:sparql constraint that, for each focus node of
-type_name, evaluates a topological operation and checks a cardinality
-predicate. Delegates to :meth:add_sparql_constraint.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- type_name
- |
-
- str
- |
-
-
-
- The type to constrain (must be registered). - |
- - required - | -
- operation
- |
-
- str
- |
-
-
-
- Topological operation: |
- - required - | -
- target_type
- |
-
- str
- |
-
-
-
- Filter the topological result to this type. - |
-
- None
- |
-
- predicate
- |
-
- str
- |
-
-
-
-
|
-
- 'min_count'
- |
-
- min_count
- |
-
- int
- |
-
-
-
- Minimum count (used by |
-
- 1
- |
-
- max_count
- |
-
- int
- |
-
-
-
- Maximum count (used by |
-
- None
- |
-
- message
- |
-
- str
- |
-
-
-
- Custom violation message. Auto-generated if not provided. - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- SchemaBuilder (self, for chaining)
- |
-
-
-
-
- |
-
------sb.add_topological_constraint( -... "spec", "coboundary", -... target_type="verification", -... predicate="min_count", min_count=1, -... message="Every spec must have at least one verification edge", -... )
-
knowledgecomplex/schema.py910 - 911 - 912 - 913 - 914 - 915 - 916 - 917 - 918 - 919 - 920 - 921 - 922 - 923 - 924 - 925 - 926 - 927 - 928 - 929 - 930 - 931 - 932 - 933 - 934 - 935 - 936 - 937 - 938 - 939 - 940 - 941 - 942 - 943 - 944 - 945 - 946 - 947 - 948 - 949 - 950 - 951 - 952 - 953 - 954 - 955 - 956 - 957 - 958 - 959 - 960 - 961 - 962 - 963 - 964 - 965 - 966 - 967 - 968 - 969 - 970 - 971 - 972 - 973 - 974 - 975 - 976 - 977 - 978 - 979 - 980 - 981 - 982 - 983 - 984 - 985 - 986 - 987 - 988 - 989 - 990 - 991 - 992 - 993 - 994 - 995 - 996 - 997 - 998 - 999 -1000 -1001 -1002 -1003 -1004 -1005 -1006 -1007 -1008 -1009 -1010 -1011 -1012 -1013 -1014 -1015 -1016 -1017 -1018 -1019 -1020 | |
dump_owl()
-
-Return merged OWL graph (core + user schema) as a Turtle string.
- - -knowledgecomplex/schema.py1022 -1023 -1024 | |
dump_shacl()
-
-Return merged SHACL graph (core shapes + user shapes) as a Turtle string.
- - -knowledgecomplex/schema.py1026 -1027 -1028 | |
export(path, query_dirs=None)
-
-Export the schema to a directory as standard semantic web files.
-Writes ontology.ttl (OWL) and shapes.ttl (SHACL). If query_dirs are -provided, copies all .sparql files into a queries/ subdirectory.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- path
- |
-
- str | Path
- |
-
-
-
- Target directory. Created if it does not exist. - |
- - required - | -
- query_dirs
- |
-
- list[Path]
- |
-
-
-
- Directories containing .sparql query templates to include. - |
-
- None
- |
-
Returns:
-| Type | -Description | -
|---|---|
- Path
- |
-
-
-
- The export directory. - |
-
knowledgecomplex/schema.py1030 -1031 -1032 -1033 -1034 -1035 -1036 -1037 -1038 -1039 -1040 -1041 -1042 -1043 -1044 -1045 -1046 -1047 -1048 -1049 -1050 -1051 -1052 -1053 -1054 -1055 -1056 -1057 -1058 -1059 -1060 -1061 -1062 -1063 -1064 -1065 -1066 -1067 | |
load(path)
-
-
- classmethod
-
-
-Load a schema from a directory containing ontology.ttl and shapes.ttl.
-Reconstructs the type registry by inspecting OWL subclass triples.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- path
- |
-
- str | Path
- |
-
-
-
- Directory containing ontology.ttl and shapes.ttl. - |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- SchemaBuilder
- |
-
-
-
-
- |
-
knowledgecomplex/schema.py1069 -1070 -1071 -1072 -1073 -1074 -1075 -1076 -1077 -1078 -1079 -1080 -1081 -1082 -1083 -1084 -1085 -1086 -1087 -1088 -1089 -1090 -1091 -1092 -1093 -1094 -1095 -1096 -1097 -1098 -1099 -1100 -1101 -1102 -1103 -1104 -1105 -1106 -1107 -1108 -1109 -1110 -1111 -1112 -1113 -1114 -1115 -1116 -1117 -1118 -1119 -1120 -1121 -1122 -1123 -1124 -1125 -1126 -1127 -1128 -1129 -1130 -1131 -1132 -1133 -1134 -1135 -1136 -1137 -1138 -1139 -1140 -1141 -1142 -1143 -1144 -1145 -1146 -1147 -1148 -1149 -1150 -1151 -1152 -1153 -1154 -1155 -1156 -1157 -1158 -1159 -1160 -1161 -1162 -1163 -1164 -1165 -1166 -1167 -1168 -1169 -1170 -1171 -1172 -1173 -1174 -1175 -1176 -1177 -1178 -1179 -1180 -1181 -1182 -1183 -1184 -1185 -1186 -1187 -1188 -1189 -1190 -1191 -1192 -1193 -1194 -1195 -1196 -1197 -1198 -1199 -1200 -1201 -1202 -1203 -1204 -1205 -1206 -1207 -1208 -1209 -1210 -1211 -1212 -1213 -1214 -1215 -1216 -1217 -1218 -1219 -1220 -1221 -1222 -1223 -1224 -1225 -1226 -1227 -1228 -1229 -1230 -1231 -1232 -1233 -1234 -1235 -1236 -1237 -1238 -1239 -1240 -1241 -1242 | |
vocab(*values, multiple=False)
-
-Declare a controlled vocabulary for an attribute.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- *values
- |
-
- str
- |
-
-
-
- The allowed string values. - |
-
- ()
- |
-
- multiple
- |
-
- bool
- |
-
-
-
- If True, allows multiple values (no sh:maxCount). -If False (default), generates sh:maxCount 1. - |
-
- False
- |
-
Returns:
-| Type | -Description | -
|---|---|
- VocabDescriptor
- |
-
-
-
-
- |
-
------vocab("adjacent", "opposite") -vocab('adjacent', 'opposite') -vocab("a", "b", "c", multiple=True) -vocab('a', 'b', 'c', multiple=True)
-
knowledgecomplex/schema.py92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 | |
text(*, required=True, multiple=False)
-
-Declare a free-text string attribute.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- required
- |
-
- bool
- |
-
-
-
- If True (default), generates sh:minCount 1. - |
-
- True
- |
-
- multiple
- |
-
- bool
- |
-
-
-
- If True, allows multiple values (no sh:maxCount). -If False (default), generates sh:maxCount 1. - |
-
- False
- |
-
Returns:
-| Type | -Description | -
|---|---|
- TextDescriptor
- |
-
-
-
-
- |
-
------text() -text() -text(required=False, multiple=True) -text(required=False, multiple=True)
-
knowledgecomplex/schema.py139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 | |
knowledgecomplex.viz — NetworkX export and visualization helpers.
-Two complementary views of a knowledge complex are provided:
-Hasse diagram (plot_hasse, plot_hasse_star, plot_hasse_skeleton)
- Every element (vertex, edge, face) becomes a graph node. Directed edges
- represent the boundary operator, pointing from each element to its boundary
- elements (higher dimension → lower dimension). Faces have out-degree 3
- and in-degree 0; edges have out-degree 2; vertices have out-degree 0.
- Nodes are colored by type and sized by dimension.
Geometric realization (plot_geometric, plot_geometric_interactive)
- Only KC vertices become points in 3D space. KC edges become line segments
- connecting their two boundary vertices. KC faces become filled,
- semi-transparent triangular patches spanning their three boundary vertices.
- This is the classical geometric realization of the abstract simplicial
- complex — the view a topologist would draw.
to_networkx exports a DiGraph that backs the Hasse plots.
-verify_networkx validates that a DiGraph satisfies simplicial complex
-cardinality and closure invariants at runtime.
Requires optional dependencies::
-pip install knowledgecomplex[viz] # matplotlib + networkx
-pip install knowledgecomplex[viz-interactive] # + plotly for interactive 3D
-
-
-
-
-
-
-
-
-
-
-
-to_networkx(kc)
-
-Convert a KnowledgeComplex to a directed networkx DiGraph.
-Every element (vertex, edge, face) becomes a node. Directed edges
-represent the boundary operator kc:boundedBy, pointing from each
-element to its boundary elements (higher dimension → lower dimension).
In the resulting DiGraph:
-Each node carries attributes:
-type: element type name (e.g. "Node", "Link")kind: "vertex", "edge", or "face"dim: 0, 1, or 2uri: file URI if present, else NoneParameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- DiGraph
- |
-
-
-
-
- |
-
knowledgecomplex/viz.py78 - 79 - 80 - 81 - 82 - 83 - 84 - 85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 | |
verify_networkx(G)
-
-Validate that a DiGraph satisfies simplicial complex invariants.
-Checks cardinality constraints and boundary closure:
-kind and dim attributes.Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- G
- |
-
- DiGraph
- |
-
-
-
- A DiGraph produced by :func: |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- bool
- |
-
-
-
-
|
-
Raises:
-| Type | -Description | -
|---|---|
- ValueError
- |
-
-
-
- On the first invariant violation, with a descriptive message. - |
-
- TypeError
- |
-
-
-
- If G is not a |
-
knowledgecomplex/viz.py134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 | |
type_color_map(kc)
-
-Build a type-name to hex-color mapping from the schema's type registry.
-Uses matplotlib's tab10 colormap (or tab20 if > 10 types)
-for distinct, visually separable colors.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- dict[str, str]
- |
-
-
-
- Mapping from type name to hex color string. - |
-
knowledgecomplex/viz.py222 -223 -224 -225 -226 -227 -228 -229 -230 -231 -232 -233 -234 -235 -236 -237 -238 -239 -240 -241 -242 -243 -244 -245 -246 -247 | |
plot_hasse(kc, *, ax=None, figsize=(10, 8), with_labels=True, node_size_by_dim=True)
-
-Plot the Hasse diagram of the complex with type-based color coding.
-Every element (vertex, edge, face) is drawn as a node. Directed arrows -represent the boundary operator, pointing from each element to its -boundary elements (higher dimension → lower dimension). Nodes are colored -by type and sized by dimension (vertices largest, faces smallest).
-This is not a geometric picture of the complex — it is the partially
-ordered set of simplices. For a geometric view where vertices are points,
-edges are line segments, and faces are filled triangles, see
-:func:plot_geometric.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- ax
- |
-
- matplotlib Axes
- |
-
-
-
- Axes to draw on. Created if not provided. - |
-
- None
- |
-
- figsize
- |
-
- tuple
- |
-
-
-
- Figure size if creating a new figure. - |
-
- (10, 8)
- |
-
- with_labels
- |
-
- bool
- |
-
-
-
- Show element ID labels on nodes. - |
-
- True
- |
-
- node_size_by_dim
- |
-
- bool
- |
-
-
-
- Scale node size by dimension (vertex=large, face=small). - |
-
- True
- |
-
Returns:
-| Type | -Description | -
|---|---|
- (fig, ax)
- |
-
-
-
- The matplotlib Figure and Axes. - |
-
knowledgecomplex/viz.py278 -279 -280 -281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 -313 -314 -315 -316 -317 -318 -319 -320 -321 -322 -323 -324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 -335 -336 -337 -338 -339 -340 -341 -342 -343 -344 -345 -346 -347 -348 -349 -350 -351 -352 -353 -354 -355 -356 -357 -358 -359 -360 -361 -362 -363 -364 | |
plot_hasse_star(kc, id, *, ax=None, figsize=(10, 8), with_labels=True)
-
-Plot the Hasse diagram with the star of an element highlighted.
-Elements in St(id) are drawn in full color with directed arrows;
-all other elements are dimmed to light gray. This is the Hasse-diagram
-view — see :func:plot_hasse for details on what that means.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- id
- |
-
- str
- |
-
-
-
- Element whose star to highlight. - |
- - required - | -
- ax
- |
-
- matplotlib Axes
- |
-
-
-
-
- |
-
- None
- |
-
- figsize
- |
-
- tuple
- |
-
-
-
-
- |
-
- (10, 8)
- |
-
- with_labels
- |
-
- bool
- |
-
-
-
-
- |
-
- True
- |
-
Returns:
-| Type | -Description | -
|---|---|
- (fig, ax)
- |
-
-
-
-
- |
-
knowledgecomplex/viz.py367 -368 -369 -370 -371 -372 -373 -374 -375 -376 -377 -378 -379 -380 -381 -382 -383 -384 -385 -386 -387 -388 -389 -390 -391 -392 -393 -394 -395 -396 -397 -398 -399 -400 -401 -402 -403 -404 -405 -406 -407 -408 -409 -410 -411 -412 -413 -414 -415 -416 -417 -418 -419 -420 -421 -422 -423 -424 -425 -426 -427 -428 -429 -430 -431 -432 -433 -434 -435 -436 -437 -438 -439 -440 | |
plot_hasse_skeleton(kc, k, *, ax=None, figsize=(10, 8), with_labels=True)
-
-Plot the Hasse diagram of the k-skeleton only.
-Shows only elements of dimension ≤ k, with directed boundary arrows.
-This is the Hasse-diagram view — see :func:plot_hasse for details.
k=0: vertices only, k=1: vertices + edges, k=2: everything.
- - -Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- k
- |
-
- int
- |
-
-
-
- Maximum dimension (0, 1, or 2). - |
- - required - | -
- ax
- |
-
- matplotlib Axes
- |
-
-
-
-
- |
-
- None
- |
-
- figsize
- |
-
- tuple
- |
-
-
-
-
- |
-
- (10, 8)
- |
-
- with_labels
- |
-
- bool
- |
-
-
-
-
- |
-
- True
- |
-
Returns:
-| Type | -Description | -
|---|---|
- (fig, ax)
- |
-
-
-
-
- |
-
knowledgecomplex/viz.py443 -444 -445 -446 -447 -448 -449 -450 -451 -452 -453 -454 -455 -456 -457 -458 -459 -460 -461 -462 -463 -464 -465 -466 -467 -468 -469 -470 -471 -472 -473 -474 -475 -476 -477 -478 -479 -480 -481 -482 -483 -484 -485 -486 -487 -488 -489 -490 -491 -492 -493 -494 -495 -496 -497 -498 -499 -500 -501 -502 -503 -504 -505 -506 | |
plot_complex(kc, **kwargs)
-
-Deprecated: use :func:plot_hasse instead.
knowledgecomplex/viz.py512 -513 -514 -515 | |
plot_star(kc, id, **kwargs)
-
-Deprecated: use :func:plot_hasse_star instead.
knowledgecomplex/viz.py518 -519 -520 -521 | |
plot_skeleton(kc, k, **kwargs)
-
-Deprecated: use :func:plot_hasse_skeleton instead.
knowledgecomplex/viz.py524 -525 -526 -527 | |
plot_geometric(kc, *, ax=None, figsize=(10, 8), with_labels=True)
-
-Plot the geometric realization of the complex in 3D.
-KC vertices become points in 3D space (positioned by force-directed -layout). KC edges become line segments connecting their two boundary -vertices. KC faces become filled, semi-transparent triangular patches -spanning their three boundary vertices.
-This is the classical geometric realization — the view a topologist
-would draw. For the Hasse diagram where every element is a node and
-boundary relations are directed edges, see :func:plot_hasse.
Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
- ax
- |
-
- matplotlib Axes3D
- |
-
-
-
- A 3D axes to draw on. Created if not provided. - |
-
- None
- |
-
- figsize
- |
-
- tuple
- |
-
-
-
- Figure size if creating a new figure. - |
-
- (10, 8)
- |
-
- with_labels
- |
-
- bool
- |
-
-
-
- Show vertex ID labels. - |
-
- True
- |
-
Returns:
-| Type | -Description | -
|---|---|
- (fig, ax)
- |
-
-
-
- The matplotlib Figure and Axes3D. - |
-
knowledgecomplex/viz.py577 -578 -579 -580 -581 -582 -583 -584 -585 -586 -587 -588 -589 -590 -591 -592 -593 -594 -595 -596 -597 -598 -599 -600 -601 -602 -603 -604 -605 -606 -607 -608 -609 -610 -611 -612 -613 -614 -615 -616 -617 -618 -619 -620 -621 -622 -623 -624 -625 -626 -627 -628 -629 -630 -631 -632 -633 -634 -635 -636 -637 -638 -639 -640 -641 -642 -643 -644 -645 -646 -647 -648 -649 -650 -651 -652 -653 -654 -655 -656 -657 -658 -659 -660 -661 -662 -663 -664 -665 -666 -667 -668 -669 -670 -671 -672 -673 -674 -675 -676 -677 -678 -679 -680 -681 -682 | |
plot_geometric_interactive(kc)
-
-Plot an interactive 3D geometric realization of the complex.
-Same geometry as :func:plot_geometric — KC vertices are points, KC edges
-are line segments, KC faces are filled triangles — but rendered with
-Plotly for interactive rotation, zoom, and hover inspection.
Requires plotly::
-pip install knowledgecomplex[viz-interactive]
-
-
-
-Parameters:
-| Name | -Type | -Description | -Default | -
|---|---|---|---|
- kc
- |
-
- KnowledgeComplex
- |
-
-
-
-
- |
- - required - | -
Returns:
-| Type | -Description | -
|---|---|
- Figure
- |
-
-
-
- Call |
-
knowledgecomplex/viz.py688 -689 -690 -691 -692 -693 -694 -695 -696 -697 -698 -699 -700 -701 -702 -703 -704 -705 -706 -707 -708 -709 -710 -711 -712 -713 -714 -715 -716 -717 -718 -719 -720 -721 -722 -723 -724 -725 -726 -727 -728 -729 -730 -731 -732 -733 -734 -735 -736 -737 -738 -739 -740 -741 -742 -743 -744 -745 -746 -747 -748 -749 -750 -751 -752 -753 -754 -755 -756 -757 -758 -759 -760 -761 -762 -763 -764 -765 -766 -767 -768 -769 -770 -771 -772 -773 -774 -775 -776 -777 -778 -779 -780 -781 -782 -783 -784 -785 -786 | |
0&&i[i.length-1])&&(p[0]===6||p[0]===2)){r=0;continue}if(p[0]===3&&(!i||p[1]>i[0]&&p[1]=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function K(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var o=r.call(e),n,i=[],s;try{for(;(t===void 0||t-- >0)&&!(n=o.next()).done;)i.push(n.value)}catch(a){s={error:a}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(s)throw s.error}}return i}function B(e,t,r){if(r||arguments.length===2)for(var o=0,n=t.length,i;o