@@ -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
6867See the [ examples/] ( https://github.com/blockscience/knowledgecomplex/tree/main/examples ) directory for 10 runnable examples.
0 commit comments