Skip to content

Commit abaa779

Browse files
authored
Merge pull request #3 from BlockScience/dev
Dev: update the documentation and set uri for w3id redirects
2 parents d07a554 + f4a04a8 commit abaa779

File tree

88 files changed

+44683
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+44683
-80
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: CI
22

33
on:
4-
push:
5-
branches: [main]
64
pull_request:
75
branches: [main]
86

ARCHITECTURE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ This separation is key: the LLM handles ambiguity, intent, and synthesis; the KC
238238
## Namespace Conventions
239239

240240
```turtle
241-
@prefix kc: <https://example.org/kc#> . # core framework
242-
@prefix kcs: <https://example.org/kc/shape#> . # core shapes
241+
@prefix kc: <https://w3id.org/kc#> . # core framework
242+
@prefix kcs: <https://w3id.org/kc/shape#> . # core shapes
243243
@prefix aaa: <https://example.org/aaa#> . # user namespace (example)
244244
@prefix aaas: <https://example.org/aaa/shape#> .# user shapes (example)
245245
```

docs/index.md

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,40 @@ pip install -e ".[dev]"
2828

2929
## Quick start
3030

31+
Load a pre-built complex, discover hidden structure, and extend it:
32+
33+
```python
34+
from knowledgecomplex import KnowledgeComplex, find_cliques, betti_numbers
35+
36+
# 1. Load a pre-built complex (vertices and edges, no faces yet)
37+
kc = KnowledgeComplex.load("examples/01_quickstart/data/pipeline")
38+
39+
# 2. Discover triangles hiding in the edge graph
40+
triangles = find_cliques(kc, k=3)
41+
print(f"Found {len(triangles)} triangles") # 2
42+
43+
# 3. Check topology — independent cycles exist
44+
print(betti_numbers(kc)) # [1, 2, 0] — two cycles
45+
46+
# 4. Declare face types and fill them in
47+
from knowledgecomplex import infer_faces
48+
kc._schema.add_face_type("operation")
49+
infer_faces(kc, "operation")
50+
51+
# 5. Cycles are now filled
52+
print(betti_numbers(kc)) # [1, 0, 0] — no more cycles
53+
54+
# 6. Visualize
55+
from knowledgecomplex import plot_hasse, plot_geometric
56+
fig, ax = plot_hasse(kc)
57+
fig, ax = plot_geometric(kc)
58+
```
59+
60+
For building schemas from scratch, see [`examples/02_construction/`](https://github.com/blockscience/knowledgecomplex/tree/main/examples/02_construction). Three pre-built ontologies ship with the package:
61+
3162
```python
32-
from knowledgecomplex import SchemaBuilder, KnowledgeComplex, vocab, text
33-
34-
# 1. Define a schema
35-
sb = SchemaBuilder(namespace="ex")
36-
sb.add_vertex_type("actor", attributes={"name": text()})
37-
sb.add_vertex_type("activity", attributes={"name": text()})
38-
sb.add_vertex_type("resource", attributes={"name": text()})
39-
sb.add_edge_type("performs", attributes={"role": vocab("lead", "support")})
40-
sb.add_edge_type("requires", attributes={"mode": vocab("read", "write")})
41-
sb.add_edge_type("produces", attributes={"mode": vocab("read", "write")})
42-
sb.add_edge_type("accesses", attributes={"mode": vocab("read", "write")})
43-
sb.add_edge_type("responsible", attributes={"level": vocab("owner", "steward")})
44-
sb.add_face_type("operation")
45-
sb.add_face_type("production")
46-
47-
# 2. Build an instance
48-
kc = KnowledgeComplex(schema=sb)
49-
kc.add_vertex("alice", type="actor", name="Alice")
50-
kc.add_vertex("etl-run", type="activity", name="Daily ETL")
51-
kc.add_vertex("dataset1", type="resource", name="JSON Records")
52-
kc.add_vertex("dataset2", type="resource", name="Sales DB")
53-
54-
kc.add_edge("e1", type="performs", vertices={"alice", "etl-run"}, role="lead")
55-
kc.add_edge("e2", type="requires", vertices={"etl-run", "dataset1"}, mode="read")
56-
kc.add_edge("e3", type="produces", vertices={"etl-run", "dataset2"}, mode="write")
57-
kc.add_edge("e4", type="accesses", vertices={"alice", "dataset1"}, mode="read")
58-
kc.add_edge("e5", type="responsible", vertices={"alice", "dataset2"}, level="owner")
59-
60-
kc.add_face("op1", type="operation", boundary=["e1", "e2", "e4"])
61-
kc.add_face("prod1", type="production", boundary=["e1", "e3", "e5"])
62-
63-
# 3. Query
64-
df = kc.query("vertices") # built-in SPARQL template
65-
print(df)
63+
from knowledgecomplex.ontologies import operations, brand, research
64+
sb = brand.schema() # audience/theme with resonance, interplay, overlap
6665
```
6766

6867
See the [examples/](https://github.com/blockscience/knowledgecomplex/tree/main/examples) directory for 10 runnable examples.

examples/01_quickstart/data/pipeline/instance.ttl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@prefix ex: <https://example.org/ex#> .
2-
@prefix kc: <https://example.org/kc#> .
2+
@prefix kc: <https://w3id.org/kc#> .
33
@prefix owl: <http://www.w3.org/2002/07/owl#> .
44
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
55
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@@ -38,7 +38,7 @@ ex:role a owl:DatatypeProperty ;
3838
rdfs:domain ex:performs ;
3939
rdfs:range xsd:string .
4040

41-
<https://example.org/kc> a owl:Ontology ;
41+
<https://w3id.org/kc> a owl:Ontology ;
4242
rdfs:label "Knowledge Complex Core Ontology" ;
4343
rdfs:comment "Abstract topological backbone: Element, Vertex, Edge, Face, Complex." .
4444

examples/01_quickstart/data/pipeline/ontology.ttl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@prefix ex: <https://example.org/ex#> .
2-
@prefix kc: <https://example.org/kc#> .
2+
@prefix kc: <https://w3id.org/kc#> .
33
@prefix owl: <http://www.w3.org/2002/07/owl#> .
44
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
55
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@@ -45,7 +45,7 @@ ex:role a owl:DatatypeProperty ;
4545
rdfs:domain ex:performs ;
4646
rdfs:range xsd:string .
4747

48-
<https://example.org/kc> a owl:Ontology ;
48+
<https://w3id.org/kc> a owl:Ontology ;
4949
rdfs:label "Knowledge Complex Core Ontology" ;
5050
rdfs:comment "Abstract topological backbone: Element, Vertex, Edge, Face, Complex." .
5151

examples/01_quickstart/data/pipeline/shapes.ttl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@prefix ex: <https://example.org/ex#> .
22
@prefix exs: <https://example.org/ex/shape#> .
3-
@prefix kc: <https://example.org/kc#> .
4-
@prefix kcs: <https://example.org/kc/shape#> .
3+
@prefix kc: <https://w3id.org/kc#> .
4+
@prefix kcs: <https://w3id.org/kc/shape#> .
55
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
66
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
77
@prefix sh: <http://www.w3.org/ns/shacl#> .
@@ -83,7 +83,7 @@ kcs:ComplexShape a sh:NodeShape ;
8383
each of its boundedBy targets must also be a hasElement of the complex.""" ;
8484
sh:message "Complex is not closed under the boundary operator: an element's boundary element is missing from the complex." ;
8585
sh:select """
86-
PREFIX kc: <https://example.org/kc#>
86+
PREFIX kc: <https://w3id.org/kc#>
8787
SELECT $this WHERE {
8888
$this kc:hasElement ?elem .
8989
?elem kc:boundedBy ?boundary .
@@ -106,7 +106,7 @@ kcs:EdgeShape a sh:NodeShape ;
106106
rdfs:comment "Edge boundary vertices must be distinct individuals." ;
107107
sh:message "Edge boundary vertices must not be the same vertex." ;
108108
sh:select """
109-
PREFIX kc: <https://example.org/kc#>
109+
PREFIX kc: <https://w3id.org/kc#>
110110
SELECT $this WHERE {
111111
$this kc:boundedBy ?v .
112112
}
@@ -141,7 +141,7 @@ kcs:FaceShape a sh:NodeShape ;
141141
""" ;
142142
sh:message "Face boundary edges do not form a closed triangle over shared vertices." ;
143143
sh:select """
144-
PREFIX kc: <https://example.org/kc#>
144+
PREFIX kc: <https://w3id.org/kc#>
145145
SELECT $this WHERE {
146146
$this kc:boundedBy ?e1 ;
147147
kc:boundedBy ?e2 ;

knowledgecomplex/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# Internal dependencies: rdflib, pyshacl, owlrl
33
# These are never re-exported. The public API is schema.py and graph.py only.
44

5+
from importlib.metadata import version, PackageNotFoundError
6+
try:
7+
__version__ = version("knowledgecomplex")
8+
except PackageNotFoundError:
9+
__version__ = "unknown"
10+
511
from knowledgecomplex.schema import SchemaBuilder, vocab, text, TextDescriptor, Codec
612
from knowledgecomplex.graph import KnowledgeComplex, Element
713
from knowledgecomplex.filtration import Filtration

knowledgecomplex/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
if TYPE_CHECKING:
3434
from knowledgecomplex.graph import KnowledgeComplex
3535

36-
_KC = Namespace("https://example.org/kc#")
36+
_KC = Namespace("https://w3id.org/kc#")
3737

3838

3939
class ComplexDiff:

knowledgecomplex/graph.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
_FRAMEWORK_QUERIES_DIR = Path(__file__).parent / "queries"
4646

4747
# Internal namespace constants
48-
_KC = Namespace("https://example.org/kc#")
48+
_KC = Namespace("https://w3id.org/kc#")
4949

5050

5151
def _load_query_templates(
@@ -744,7 +744,7 @@ def element_ids(self, type: str | None = None) -> list[str]:
744744
sparql = f"""
745745
SELECT ?elem WHERE {{
746746
?elem a/rdfs:subClassOf* <{type_iri}> .
747-
<{self._complex_iri}> <https://example.org/kc#hasElement> ?elem .
747+
<{self._complex_iri}> <https://w3id.org/kc#hasElement> ?elem .
748748
}}
749749
"""
750750
results = self._instance_graph.query(
@@ -881,7 +881,7 @@ def coboundary(self, id: str, *, type: str | None = None) -> set[str]:
881881
"""
882882
tf = self._type_filter_clause("coboundary", type)
883883
sparql = f"""\
884-
PREFIX kc: <https://example.org/kc#>
884+
PREFIX kc: <https://w3id.org/kc#>
885885
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
886886
SELECT ?coboundary WHERE {{
887887
?coboundary kc:boundedBy <{self._iri(id)}> .
@@ -938,7 +938,7 @@ def closure(self, ids: str | set[str], *, type: str | None = None) -> set[str]:
938938
values = " ".join(f"(<{self._iri(i)}>)" for i in ids)
939939
tf = self._type_filter_clause("closure", type)
940940
sparql = f"""\
941-
PREFIX kc: <https://example.org/kc#>
941+
PREFIX kc: <https://w3id.org/kc#>
942942
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
943943
SELECT ?closure WHERE {{
944944
VALUES (?sigma) {{ {values} }}

knowledgecomplex/ontologies/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Once your persistent URI is live, use it as your namespace:
115115

116116
```python
117117
sb = SchemaBuilder(namespace="mydom")
118-
# Currently generates: https://example.org/mydom#
118+
# Currently generates: https://example.org/mydom# (user namespace)
119119
# For production: update _base_iri to your w3id.org URI
120120
```
121121

0 commit comments

Comments
 (0)