Skip to content

Commit a3f17bc

Browse files
committed
rework example usage
1 parent 0e8eb18 commit a3f17bc

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,26 @@ pip install -e ".[dev]"
3232
from knowledgecomplex import SchemaBuilder, KnowledgeComplex, vocab, text
3333

3434
# 1. Define a schema
35-
sb = SchemaBuilder(namespace="aaa")
36-
sb.add_vertex_type("spec", attributes={"title": text(), "domain": text()})
37-
sb.add_vertex_type("guidance", attributes={"title": text(), "domain": text()})
38-
sb.add_edge_type("verification",
39-
attributes={"status": vocab("passing", "failing", "pending")})
40-
sb.add_face_type("assurance")
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("responsible", attributes={"level": vocab("owner", "steward")})
42+
sb.add_face_type("operation")
4143

4244
# 2. Build an instance
4345
kc = KnowledgeComplex(schema=sb)
44-
kc.add_vertex("spec-001", type="spec", uri="file:///docs/spec-001.md",
45-
title="Spec for Verification", domain="aaa")
46-
kc.add_vertex("guidance-001", type="guidance", uri="file:///docs/guidance-001.md",
47-
title="Guidance for Verification", domain="aaa")
48-
kc.add_edge("ver-001", type="verification",
49-
vertices={"spec-001", "guidance-001"}, status="passing")
46+
kc.add_vertex("alice", type="actor", name="Alice")
47+
kc.add_vertex("etl-run", type="activity", name="Daily ETL")
48+
kc.add_vertex("dataset", type="resource", name="Sales DB")
49+
50+
kc.add_edge("e1", type="performs", vertices={"alice", "etl-run"}, role="lead")
51+
kc.add_edge("e2", type="requires", vertices={"etl-run", "dataset"}, mode="write")
52+
kc.add_edge("e3", type="responsible", vertices={"alice", "dataset"}, level="owner")
53+
54+
kc.add_face("op1", type="operation", edges={"e1", "e2", "e3"})
5055

5156
# 3. Query
5257
df = kc.query("vertices") # built-in SPARQL template
@@ -61,12 +66,12 @@ print(kc.dump_graph()) # Turtle string
6166
Every element (vertex, edge, or face) can carry an optional `kc:uri` property pointing to its source file:
6267

6368
```python
64-
kc.add_vertex("doc-001", type="spec", uri="file:///path/to/doc-001.md")
65-
kc.add_edge("ver-001", type="verification", vertices={"doc-001", "doc-002"},
66-
uri="file:///edges/ver-001.md", status="passing")
69+
kc.add_vertex("alice", type="actor", uri="file:///actors/alice.md", name="Alice")
70+
kc.add_edge("e1", type="performs", vertices={"alice", "etl-run"},
71+
uri="file:///edges/e1.md", role="lead")
6772
```
6873

69-
SHACL enforces at-most-one `kc:uri` per element. This is particularly useful for domain applications like AAA where each element corresponds to an actual document file.
74+
SHACL enforces at-most-one `kc:uri` per element. This is useful for domain applications where each element corresponds to an actual document or record.
7075

7176
## Architecture
7277

docs/index.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,26 @@ pip install -e ".[dev]"
3232
from knowledgecomplex import SchemaBuilder, KnowledgeComplex, vocab, text
3333

3434
# 1. Define a schema
35-
sb = SchemaBuilder(namespace="aaa")
36-
sb.add_vertex_type("spec", attributes={"title": text(), "domain": text()})
37-
sb.add_vertex_type("guidance", attributes={"title": text(), "domain": text()})
38-
sb.add_edge_type("verification",
39-
attributes={"status": vocab("passing", "failing", "pending")})
40-
sb.add_face_type("assurance")
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("responsible", attributes={"level": vocab("owner", "steward")})
42+
sb.add_face_type("operation")
4143

4244
# 2. Build an instance
4345
kc = KnowledgeComplex(schema=sb)
44-
kc.add_vertex("spec-001", type="spec", uri="file:///docs/spec-001.md",
45-
title="Spec for Verification", domain="aaa")
46-
kc.add_vertex("guidance-001", type="guidance", uri="file:///docs/guidance-001.md",
47-
title="Guidance for Verification", domain="aaa")
48-
kc.add_edge("ver-001", type="verification",
49-
vertices={"spec-001", "guidance-001"}, status="passing")
46+
kc.add_vertex("alice", type="actor", name="Alice")
47+
kc.add_vertex("etl-run", type="activity", name="Daily ETL")
48+
kc.add_vertex("dataset", type="resource", name="Sales DB")
49+
50+
kc.add_edge("e1", type="performs", vertices={"alice", "etl-run"}, role="lead")
51+
kc.add_edge("e2", type="requires", vertices={"etl-run", "dataset"}, mode="write")
52+
kc.add_edge("e3", type="responsible", vertices={"alice", "dataset"}, level="owner")
53+
54+
kc.add_face("op1", type="operation", edges={"e1", "e2", "e3"})
5055

5156
# 3. Query
5257
df = kc.query("vertices") # built-in SPARQL template

0 commit comments

Comments
 (0)