cds2.knowledge
Knowledge graphs, research notebooks and ranked retrieval.
Knowledge organization: concept graphs, notebooks and retrieval.
Concept
dataclass
A named node in the knowledge graph with optional summary text.
Source code in src/cds2/knowledge.py
9 10 11 12 13 14 | |
Relation
dataclass
A typed directed edge between two concepts.
Source code in src/cds2/knowledge.py
17 18 19 20 21 22 23 | |
Note
dataclass
A free-form research note tagged with concepts.
Source code in src/cds2/knowledge.py
26 27 28 29 30 31 32 33 | |
KnowledgeGraph
Typed directed concept graph with traversal utilities.
Source code in src/cds2/knowledge.py
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 | |
add_concept(concept)
Register a concept; re-adding replaces the previous entry.
Source code in src/cds2/knowledge.py
44 45 46 47 48 | |
add_relation(relation)
Add a directed labelled edge; both endpoints must exist.
Source code in src/cds2/knowledge.py
50 51 52 53 54 55 56 57 58 | |
neighbors(name, direction='outgoing')
Direct neighbours of a concept ('outgoing', 'incoming' or 'both').
Source code in src/cds2/knowledge.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
shortest_path(start, goal)
Fewest-hops path via BFS; empty list when unreachable.
Source code in src/cds2/knowledge.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
transitive_closure(start)
Every node reachable from start by any number of hops.
Source code in src/cds2/knowledge.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
has_cycle()
Detect whether the directed graph contains a cycle.
Source code in src/cds2/knowledge.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
Notebook
Tagged research notes that can reference graph concepts.
Source code in src/cds2/knowledge.py
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 | |
search(query, graph, notebook=None)
Ranked keyword hits across concepts, summaries, relations and notes.
Returns (score, description) pairs sorted best-first.
Source code in src/cds2/knowledge.py
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 | |