knowledgecomplex 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- knowledgecomplex/__init__.py +91 -0
- knowledgecomplex/analysis.py +1177 -0
- knowledgecomplex/audit.py +173 -0
- knowledgecomplex/clique.py +399 -0
- knowledgecomplex/codecs/__init__.py +9 -0
- knowledgecomplex/codecs/markdown.py +220 -0
- knowledgecomplex/diff.py +429 -0
- knowledgecomplex/exceptions.py +38 -0
- knowledgecomplex/filtration.py +226 -0
- knowledgecomplex/graph.py +1107 -0
- knowledgecomplex/io.py +167 -0
- knowledgecomplex/ontologies/README.md +182 -0
- knowledgecomplex/ontologies/__init__.py +24 -0
- knowledgecomplex/ontologies/brand.py +67 -0
- knowledgecomplex/ontologies/operations.py +44 -0
- knowledgecomplex/ontologies/research.py +73 -0
- knowledgecomplex/queries/boundary.sparql +17 -0
- knowledgecomplex/queries/closure.sparql +18 -0
- knowledgecomplex/queries/coboundary.sparql +16 -0
- knowledgecomplex/queries/degree.sparql +12 -0
- knowledgecomplex/queries/skeleton.sparql +17 -0
- knowledgecomplex/queries/star.sparql +19 -0
- knowledgecomplex/queries/vertices.sparql +13 -0
- knowledgecomplex/resources/kc_core.ttl +140 -0
- knowledgecomplex/resources/kc_core_shapes.ttl +191 -0
- knowledgecomplex/schema.py +1142 -0
- knowledgecomplex/viz.py +786 -0
- knowledgecomplex-0.1.0.dist-info/METADATA +442 -0
- knowledgecomplex-0.1.0.dist-info/RECORD +31 -0
- knowledgecomplex-0.1.0.dist-info/WHEEL +4 -0
- knowledgecomplex-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# knowledgecomplex/resources/kc_core.ttl
|
|
2
|
+
# Abstract OWL ontology — KC topological backbone.
|
|
3
|
+
# This file is a static resource; do not generate at runtime.
|
|
4
|
+
#
|
|
5
|
+
# DESIGN SEAMS (constraints OWL cannot express — see kc_core_shapes.ttl):
|
|
6
|
+
# - Edge boundary vertices must be distinct (open-world assumption; needs SHACL)
|
|
7
|
+
# - Closed-triangle constraint across 3 Face boundary edges (co-reference; needs sh:sparql)
|
|
8
|
+
# - Boundary-closure of a Complex (compositional validity; needs sh:sparql)
|
|
9
|
+
#
|
|
10
|
+
# SIMPLIFICATION (this implementation):
|
|
11
|
+
# All simplices are unoriented. The boundary operator (boundedBy) returns an
|
|
12
|
+
# unordered set, not an ordered list. For oriented simplex support see
|
|
13
|
+
# docs/issues/orientation-support.md.
|
|
14
|
+
|
|
15
|
+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
|
16
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
|
17
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
|
18
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
|
19
|
+
@prefix kc: <https://example.org/kc#> .
|
|
20
|
+
|
|
21
|
+
<https://example.org/kc>
|
|
22
|
+
a owl:Ontology ;
|
|
23
|
+
rdfs:label "Knowledge Complex Core Ontology" ;
|
|
24
|
+
rdfs:comment "Abstract topological backbone: Element, Vertex, Edge, Face, Complex." .
|
|
25
|
+
|
|
26
|
+
# ---------------------------------------------------------------------------
|
|
27
|
+
# Base class for all topological elements (simplices)
|
|
28
|
+
# ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
kc:Element a owl:Class ;
|
|
31
|
+
rdfs:label "Element" ;
|
|
32
|
+
rdfs:comment """Abstract topological element (k-simplex). All KC types are elements.
|
|
33
|
+
The simplex order k determines boundary cardinality:
|
|
34
|
+
k=0 (Vertex): empty boundary (cardinality 0)
|
|
35
|
+
k=1 (Edge): 2 boundary vertices
|
|
36
|
+
k=2 (Face): 3 boundary edges
|
|
37
|
+
k>=1 general: (k+1) boundary (k-1)-simplices
|
|
38
|
+
Higher orders can be defined by subclassing Element.""" .
|
|
39
|
+
|
|
40
|
+
# ---------------------------------------------------------------------------
|
|
41
|
+
# Abstract simplex classes (subclasses of Element)
|
|
42
|
+
# ---------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
kc:Vertex a owl:Class ;
|
|
45
|
+
rdfs:subClassOf kc:Element ;
|
|
46
|
+
rdfs:label "Vertex" ;
|
|
47
|
+
rdfs:comment "Abstract 0-simplex. Empty boundary (∂v = ∅). Concrete types must subclass this." .
|
|
48
|
+
|
|
49
|
+
kc:Edge a owl:Class ;
|
|
50
|
+
rdfs:subClassOf kc:Element ;
|
|
51
|
+
rdfs:label "Edge" ;
|
|
52
|
+
rdfs:comment "Abstract 1-simplex. Boundary: exactly 2 vertices. Concrete types must subclass this." .
|
|
53
|
+
|
|
54
|
+
kc:Face a owl:Class ;
|
|
55
|
+
rdfs:subClassOf kc:Element ;
|
|
56
|
+
rdfs:label "Face" ;
|
|
57
|
+
rdfs:comment "Abstract 2-simplex. Boundary: exactly 3 edges. Concrete types must subclass this." .
|
|
58
|
+
|
|
59
|
+
# Higher-order simplices (k>=3) can be defined by subclassing kc:Element
|
|
60
|
+
# and adding a boundedBy cardinality restriction. For example:
|
|
61
|
+
# kc:Tetrahedron rdfs:subClassOf kc:Element . # 3-simplex
|
|
62
|
+
# kc:Tetrahedron rdfs:subClassOf [
|
|
63
|
+
# a owl:Restriction ; owl:onProperty kc:boundedBy ;
|
|
64
|
+
# owl:qualifiedCardinality "4"^^xsd:nonNegativeInteger ;
|
|
65
|
+
# owl:onClass kc:Face ] .
|
|
66
|
+
|
|
67
|
+
# ---------------------------------------------------------------------------
|
|
68
|
+
# Boundary operator (dimension-polymorphic)
|
|
69
|
+
# ---------------------------------------------------------------------------
|
|
70
|
+
# boundedBy maps a k-simplex to its bounding (k-1)-simplices:
|
|
71
|
+
# Vertex: no boundedBy (k=0, empty boundary)
|
|
72
|
+
# Edge boundedBy Vertex (cardinality 2)
|
|
73
|
+
# Face boundedBy Edge (cardinality 3)
|
|
74
|
+
# Coboundary (inverse lookup) is handled by SPARQL queries, not stored triples.
|
|
75
|
+
|
|
76
|
+
kc:boundedBy a owl:ObjectProperty ;
|
|
77
|
+
rdfs:domain kc:Element ;
|
|
78
|
+
rdfs:range kc:Element ;
|
|
79
|
+
rdfs:label "boundedBy" ;
|
|
80
|
+
rdfs:comment """Boundary operator (∂). Maps a k-simplex to its bounding
|
|
81
|
+
(k-1)-simplices. Cardinality is enforced per subclass via OWL restrictions.
|
|
82
|
+
Vertices (k=0) have empty boundary. For k>=1, cardinality = k+1.
|
|
83
|
+
All elements are unoriented (boundary is an unordered set).""" .
|
|
84
|
+
|
|
85
|
+
# ---------------------------------------------------------------------------
|
|
86
|
+
# Source file URI (optional, superstructure-level attribute)
|
|
87
|
+
# ---------------------------------------------------------------------------
|
|
88
|
+
# kc:uri allows any element to point to its source file (local or remote).
|
|
89
|
+
# This is particularly useful for domain applications (e.g. AAA) where each
|
|
90
|
+
# element corresponds to an actual document file.
|
|
91
|
+
|
|
92
|
+
kc:uri a owl:DatatypeProperty ;
|
|
93
|
+
rdfs:domain kc:Element ;
|
|
94
|
+
rdfs:range xsd:anyURI ;
|
|
95
|
+
rdfs:label "uri" ;
|
|
96
|
+
rdfs:comment """Optional URI pointing to the source file for this element.
|
|
97
|
+
Accepts any URI scheme (file:///, https://, etc.).
|
|
98
|
+
At-most-one per element (sh:maxCount 1 enforced in kc_core_shapes.ttl).""" .
|
|
99
|
+
|
|
100
|
+
# ---------------------------------------------------------------------------
|
|
101
|
+
# Cardinality restrictions (topological-OWL cell of the 2x2)
|
|
102
|
+
# ---------------------------------------------------------------------------
|
|
103
|
+
|
|
104
|
+
# Edge: exactly 2 boundary vertices
|
|
105
|
+
# DESIGN SEAM: distinctness of the 2 vertices requires SHACL (see kc_core_shapes.ttl)
|
|
106
|
+
|
|
107
|
+
kc:Edge rdfs:subClassOf [
|
|
108
|
+
a owl:Restriction ;
|
|
109
|
+
owl:onProperty kc:boundedBy ;
|
|
110
|
+
owl:qualifiedCardinality "2"^^xsd:nonNegativeInteger ;
|
|
111
|
+
owl:onClass kc:Vertex
|
|
112
|
+
] .
|
|
113
|
+
|
|
114
|
+
# Face: exactly 3 boundary edges
|
|
115
|
+
# DESIGN SEAM: closed-triangle constraint (boundary edges share vertices in a cycle)
|
|
116
|
+
# cannot be expressed in OWL. See sh:sparql in kc_core_shapes.ttl.
|
|
117
|
+
|
|
118
|
+
kc:Face rdfs:subClassOf [
|
|
119
|
+
a owl:Restriction ;
|
|
120
|
+
owl:onProperty kc:boundedBy ;
|
|
121
|
+
owl:qualifiedCardinality "3"^^xsd:nonNegativeInteger ;
|
|
122
|
+
owl:onClass kc:Edge
|
|
123
|
+
] .
|
|
124
|
+
|
|
125
|
+
# ---------------------------------------------------------------------------
|
|
126
|
+
# Complex — a collection of elements (simplices)
|
|
127
|
+
# ---------------------------------------------------------------------------
|
|
128
|
+
|
|
129
|
+
kc:Complex a owl:Class ;
|
|
130
|
+
rdfs:label "Complex" ;
|
|
131
|
+
rdfs:comment """A simplicial complex: a collection of elements (simplices) that is
|
|
132
|
+
closed under the boundary operator. If a simplex is in the complex, all its
|
|
133
|
+
boundary elements must also be in the complex. Topological validity of the
|
|
134
|
+
composition is enforced by SHACL (see kcs:ComplexShape).""" .
|
|
135
|
+
|
|
136
|
+
kc:hasElement a owl:ObjectProperty ;
|
|
137
|
+
rdfs:domain kc:Complex ;
|
|
138
|
+
rdfs:range kc:Element ;
|
|
139
|
+
rdfs:label "hasElement" ;
|
|
140
|
+
rdfs:comment "Membership relation: an element belongs to this complex." .
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# knowledgecomplex/resources/kc_core_shapes.ttl
|
|
2
|
+
# Abstract SHACL shapes — KC topological constraints.
|
|
3
|
+
# This file is a static resource; do not generate at runtime.
|
|
4
|
+
#
|
|
5
|
+
# This file covers the topological-SHACL cell of the 2x2 responsibility map.
|
|
6
|
+
# It enforces instance-level constraints that OWL cardinality axioms cannot express:
|
|
7
|
+
#
|
|
8
|
+
# 1. Edge boundary vertices are distinct individuals.
|
|
9
|
+
# WHY NOT OWL: OWL operates under the open-world assumption. Two boundedBy
|
|
10
|
+
# triples pointing to different IRIs are not guaranteed to denote different
|
|
11
|
+
# individuals without an explicit owl:differentFrom assertion. SHACL operates
|
|
12
|
+
# on the graph as-is.
|
|
13
|
+
#
|
|
14
|
+
# 2. Closed-triangle constraint: the 3 boundary edges of a Face share vertices
|
|
15
|
+
# forming a cycle.
|
|
16
|
+
# WHY NOT OWL: This requires co-referencing across 3 separate boundedBy values —
|
|
17
|
+
# i.e. checking that the boundary edges' own boundary vertices form a specific
|
|
18
|
+
# topological pattern across multiple individuals. OWL-DL cannot express this.
|
|
19
|
+
# sh:sparql is the correct mechanism.
|
|
20
|
+
#
|
|
21
|
+
# 3. Boundary-closure of a Complex: if a simplex is in the complex, all its
|
|
22
|
+
# boundary elements must also be in the complex.
|
|
23
|
+
# WHY NOT OWL: This requires co-referencing across kc:hasElement and
|
|
24
|
+
# kc:boundedBy on different individuals. OWL cannot express "for every element
|
|
25
|
+
# in the complex, each of its boundary elements is also in the complex."
|
|
26
|
+
#
|
|
27
|
+
# 4. kc:uri is optional and at-most-one per element.
|
|
28
|
+
# WHY SHACL: OWL cardinality is inference-based; SHACL enforces this at
|
|
29
|
+
# the instance level without open-world complications.
|
|
30
|
+
#
|
|
31
|
+
# SIMPLIFICATION: All simplices are unoriented. boundedBy returns an unordered set.
|
|
32
|
+
|
|
33
|
+
@prefix sh: <http://www.w3.org/ns/shacl#> .
|
|
34
|
+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
|
35
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
|
36
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
|
37
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
|
38
|
+
@prefix kc: <https://example.org/kc#> .
|
|
39
|
+
@prefix kcs: <https://example.org/kc/shape#> .
|
|
40
|
+
|
|
41
|
+
# ---------------------------------------------------------------------------
|
|
42
|
+
# ElementShape — superstructure constraint: kc:uri is optional, at-most-one
|
|
43
|
+
# ---------------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
kcs:ElementShape
|
|
46
|
+
a sh:NodeShape ;
|
|
47
|
+
sh:targetClass kc:Element ;
|
|
48
|
+
rdfs:label "ElementShape" ;
|
|
49
|
+
rdfs:comment "Superstructure constraint: kc:uri may appear at most once per element." ;
|
|
50
|
+
|
|
51
|
+
sh:property [
|
|
52
|
+
sh:path kc:uri ;
|
|
53
|
+
sh:datatype xsd:anyURI ;
|
|
54
|
+
sh:maxCount 1 ;
|
|
55
|
+
sh:message "An element may have at most one kc:uri value."
|
|
56
|
+
] .
|
|
57
|
+
|
|
58
|
+
# ---------------------------------------------------------------------------
|
|
59
|
+
# EdgeShape — topological-SHACL constraints on KC:Edge instances
|
|
60
|
+
# ---------------------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
kcs:EdgeShape
|
|
63
|
+
a sh:NodeShape ;
|
|
64
|
+
sh:targetClass kc:Edge ;
|
|
65
|
+
rdfs:label "EdgeShape" ;
|
|
66
|
+
rdfs:comment "Topological constraints on KC:Edge instances." ;
|
|
67
|
+
|
|
68
|
+
# boundedBy: exactly 2, each must be KC:Vertex
|
|
69
|
+
sh:property [
|
|
70
|
+
sh:path kc:boundedBy ;
|
|
71
|
+
sh:minCount 2 ;
|
|
72
|
+
sh:maxCount 2 ;
|
|
73
|
+
sh:class kc:Vertex ;
|
|
74
|
+
sh:message "Edge must have exactly two boundedBy relations of type KC:Vertex."
|
|
75
|
+
] ;
|
|
76
|
+
|
|
77
|
+
# Distinctness constraint: the two boundary vertices must differ
|
|
78
|
+
# WHY SHACL NOT OWL: see file header note 1.
|
|
79
|
+
# NOTE: We use COUNT(DISTINCT) because SPARQL pattern matching on two
|
|
80
|
+
# boundedBy triples produces self-joins where both variables bind to the
|
|
81
|
+
# same value, even when two distinct vertices exist.
|
|
82
|
+
sh:sparql [
|
|
83
|
+
a sh:SPARQLConstraint ;
|
|
84
|
+
rdfs:comment "Edge boundary vertices must be distinct individuals." ;
|
|
85
|
+
sh:message "Edge boundary vertices must not be the same vertex." ;
|
|
86
|
+
sh:select """
|
|
87
|
+
PREFIX kc: <https://example.org/kc#>
|
|
88
|
+
SELECT $this WHERE {
|
|
89
|
+
$this kc:boundedBy ?v .
|
|
90
|
+
}
|
|
91
|
+
GROUP BY $this
|
|
92
|
+
HAVING (COUNT(DISTINCT ?v) < 2)
|
|
93
|
+
"""
|
|
94
|
+
] .
|
|
95
|
+
|
|
96
|
+
# ---------------------------------------------------------------------------
|
|
97
|
+
# FaceShape — topological-SHACL constraints on KC:Face instances
|
|
98
|
+
# ---------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
kcs:FaceShape
|
|
101
|
+
a sh:NodeShape ;
|
|
102
|
+
sh:targetClass kc:Face ;
|
|
103
|
+
rdfs:label "FaceShape" ;
|
|
104
|
+
rdfs:comment "Topological constraints on KC:Face instances." ;
|
|
105
|
+
|
|
106
|
+
# boundedBy: exactly 3, each must be KC:Edge
|
|
107
|
+
sh:property [
|
|
108
|
+
sh:path kc:boundedBy ;
|
|
109
|
+
sh:minCount 3 ;
|
|
110
|
+
sh:maxCount 3 ;
|
|
111
|
+
sh:class kc:Edge ;
|
|
112
|
+
sh:message "Face must have exactly three boundedBy relations, each of type KC:Edge."
|
|
113
|
+
] ;
|
|
114
|
+
|
|
115
|
+
# Closed-triangle constraint.
|
|
116
|
+
# WHY SHACL sh:sparql NOT OWL: see file header note 2.
|
|
117
|
+
# The query finds faces where the 3 boundary edges do NOT form a closed triangle.
|
|
118
|
+
# A closed triangle requires: for edges e1, e2, e3, each with 2 boundary vertices,
|
|
119
|
+
# the union of all 6 boundary vertex slots contains exactly 3 distinct vertices
|
|
120
|
+
# and each vertex appears in exactly 2 of the 3 edges.
|
|
121
|
+
sh:sparql [
|
|
122
|
+
a sh:SPARQLConstraint ;
|
|
123
|
+
rdfs:comment """
|
|
124
|
+
Closed-triangle constraint: the 3 boundary edges of a Face must share
|
|
125
|
+
vertices forming a cycle (v1-v2, v2-v3, v3-v1). This cannot be expressed
|
|
126
|
+
in OWL because it requires co-referencing property values across 3 edge
|
|
127
|
+
individuals.
|
|
128
|
+
""" ;
|
|
129
|
+
sh:message "Face boundary edges do not form a closed triangle over shared vertices." ;
|
|
130
|
+
sh:select """
|
|
131
|
+
PREFIX kc: <https://example.org/kc#>
|
|
132
|
+
SELECT $this WHERE {
|
|
133
|
+
$this kc:boundedBy ?e1 ;
|
|
134
|
+
kc:boundedBy ?e2 ;
|
|
135
|
+
kc:boundedBy ?e3 .
|
|
136
|
+
FILTER (?e1 != ?e2 && ?e2 != ?e3 && ?e1 != ?e3)
|
|
137
|
+
?e1 kc:boundedBy ?a1 ; kc:boundedBy ?b1 .
|
|
138
|
+
?e2 kc:boundedBy ?a2 ; kc:boundedBy ?b2 .
|
|
139
|
+
?e3 kc:boundedBy ?a3 ; kc:boundedBy ?b3 .
|
|
140
|
+
FILTER (?a1 != ?b1 && ?a2 != ?b2 && ?a3 != ?b3)
|
|
141
|
+
# For a valid triangle each endpoint of e1 must appear in at least
|
|
142
|
+
# one other edge's boundary.
|
|
143
|
+
BIND(
|
|
144
|
+
EXISTS {
|
|
145
|
+
{ ?e2 kc:boundedBy ?a1 } UNION { ?e3 kc:boundedBy ?a1 }
|
|
146
|
+
} AS ?a1_shared
|
|
147
|
+
)
|
|
148
|
+
BIND(
|
|
149
|
+
EXISTS {
|
|
150
|
+
{ ?e2 kc:boundedBy ?b1 } UNION { ?e3 kc:boundedBy ?b1 }
|
|
151
|
+
} AS ?b1_shared
|
|
152
|
+
)
|
|
153
|
+
FILTER NOT EXISTS {
|
|
154
|
+
# Valid closed triangle: each endpoint of e1 is shared with another edge
|
|
155
|
+
FILTER (?a1_shared && ?b1_shared)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
"""
|
|
159
|
+
] .
|
|
160
|
+
|
|
161
|
+
# ---------------------------------------------------------------------------
|
|
162
|
+
# ComplexShape — boundary-closure constraint on KC:Complex instances
|
|
163
|
+
# ---------------------------------------------------------------------------
|
|
164
|
+
|
|
165
|
+
kcs:ComplexShape
|
|
166
|
+
a sh:NodeShape ;
|
|
167
|
+
sh:targetClass kc:Complex ;
|
|
168
|
+
rdfs:label "ComplexShape" ;
|
|
169
|
+
rdfs:comment """Boundary-closure constraint: if a simplex is in the complex,
|
|
170
|
+
all its boundary elements must also be in the complex.""" ;
|
|
171
|
+
|
|
172
|
+
# Boundary-closure: every element's boundary elements must also be members.
|
|
173
|
+
# WHY SHACL sh:sparql NOT OWL: see file header note 3.
|
|
174
|
+
# The query finds complexes where some element has a boundary element that
|
|
175
|
+
# is NOT also a member of the complex.
|
|
176
|
+
sh:sparql [
|
|
177
|
+
a sh:SPARQLConstraint ;
|
|
178
|
+
rdfs:comment """Boundary-closure: for every element in the complex,
|
|
179
|
+
each of its boundedBy targets must also be a hasElement of the complex.""" ;
|
|
180
|
+
sh:message "Complex is not closed under the boundary operator: an element's boundary element is missing from the complex." ;
|
|
181
|
+
sh:select """
|
|
182
|
+
PREFIX kc: <https://example.org/kc#>
|
|
183
|
+
SELECT $this WHERE {
|
|
184
|
+
$this kc:hasElement ?elem .
|
|
185
|
+
?elem kc:boundedBy ?boundary .
|
|
186
|
+
FILTER NOT EXISTS {
|
|
187
|
+
$this kc:hasElement ?boundary .
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
"""
|
|
191
|
+
] .
|