Alef1986 commited on
Commit
3308bc3
·
1 Parent(s): 65ddadb

Refactor: Isolate SMIM layer, canonical graphs without DB/UI coupling

Browse files
Files changed (3) hide show
  1. js/app.js +2 -2
  2. js/smim/bfo.js +32 -46
  3. js/smim/iso15926.js +78 -59
js/app.js CHANGED
@@ -136,9 +136,9 @@ const App = {
136
  const eventsToProcess = showHistory.value ? state.eventLog : activeEdges.value;
137
 
138
  if (settings.ontology === 'BFO') {
139
- return bfoAdapter.generateSemanticGraph(eventsToProcess, baseNodes.value, state.currentTime, settings.storage);
140
  } else {
141
- return isoAdapter.generateSemanticGraph(eventsToProcess, baseNodes.value, state.currentTime, settings.storage);
142
  }
143
  });
144
 
 
136
  const eventsToProcess = showHistory.value ? state.eventLog : activeEdges.value;
137
 
138
  if (settings.ontology === 'BFO') {
139
+ return bfoAdapter.generateSemanticGraph(eventsToProcess, baseNodes.value, state.currentTime);
140
  } else {
141
+ return isoAdapter.generateSemanticGraph(eventsToProcess, baseNodes.value, state.currentTime);
142
  }
143
  });
144
 
js/smim/bfo.js CHANGED
@@ -3,11 +3,17 @@
3
  * ------------------------------------
4
  * Maps the Event Log into a 3D Semantic Graph.
5
  * Entities are 'MaterialEntities' that endure through time.
6
- * In LPG, time is a property on the edge.
7
- * In RDF, relations must be reified into explicit Statement nodes.
 
 
 
 
 
 
8
  */
9
 
10
- export function generateSemanticGraph(eventLog, baseNodes, currentTime, storageMode) {
11
  const nodes = [];
12
  const edges = [];
13
 
@@ -17,56 +23,36 @@ export function generateSemanticGraph(eventLog, baseNodes, currentTime, storageM
17
  id: n.id,
18
  label: n.label,
19
  type: 'MaterialEntity',
20
- data: { originalId: n.id, entityType: n.type }
 
 
 
21
  });
22
  });
23
 
24
- // 2. Process the Event Log
25
  eventLog.forEach(event => {
26
  // Check temporal validity
27
- if (event.valid_from > currentTime) return;
28
- const isActive = (event.valid_to === null || event.valid_to > currentTime);
29
-
30
- if (storageMode === 'LPG') {
31
- // In LPG, the temporal data sits neatly as properties on the directed edge
32
- edges.push({
33
- id: event.id,
34
- from: event.from,
35
- to: event.to,
36
- label: 'has_part',
37
- type: 'composition',
38
- data: { isActive, event }
39
- });
40
- } else {
41
- // RDF Mode: W3C Reification Pattern
42
- // We cannot put properties on an edge, so we create a Statement Node
43
- const stmtId = `stmt_${event.id}`;
44
- const litFromId = `lit_from_${event.id}`;
45
- const litToId = `lit_to_${event.id}`;
46
-
47
- // The reification node
48
- nodes.push({
49
- id: stmtId,
50
- label: `_:${event.id}`,
51
- type: 'TemporalPartMembership',
52
- data: { isActive, event }
53
- });
54
-
55
- // Links from Statement to Subjects/Objects
56
- edges.push({ id: `rel_p_${event.id}`, from: stmtId, to: event.from, label: ':hasParent', type: 'reification' });
57
- edges.push({ id: `rel_c_${event.id}`, from: stmtId, to: event.to, label: ':hasChild', type: 'reification' });
58
-
59
- // Temporal Literals (valid_from)
60
- nodes.push({ id: litFromId, label: `"T${event.valid_from}"^^xsd:int`, type: 'Literal', data: {} });
61
- edges.push({ id: `rel_vf_${event.id}`, from: stmtId, to: litFromId, label: ':validFrom', type: 'reification' });
62
 
63
- // Temporal Literals (valid_to) - only if the relation is closed
64
- if (event.valid_to !== null) {
65
- nodes.push({ id: litToId, label: `"T${event.valid_to}"^^xsd:int`, type: 'Literal', data: {} });
66
- edges.push({ id: `rel_vt_${event.id}`, from: stmtId, to: litToId, label: ':validTo', type: 'reification', data: { isPast: true } });
 
 
 
 
 
 
 
 
 
67
  }
68
- }
69
  });
70
 
71
  return { nodes, edges };
72
- }
 
3
  * ------------------------------------
4
  * Maps the Event Log into a 3D Semantic Graph.
5
  * Entities are 'MaterialEntities' that endure through time.
6
+ * Relations are Continuant compositions ('has_part') carrying temporal properties.
7
+ *
8
+ * Completely decoupled from database storage (SMS) and UI concerns.
9
+ *
10
+ * @param {Array} eventLog - The projection of temporal events.
11
+ * @param {Array} baseNodes - The projection of base continuant entities.
12
+ * @param {number|null} [currentTime=null] - Global time to evaluate current validity.
13
+ * @returns {{ nodes: Array, edges: Array }} The canonical Semantic Graph.
14
  */
15
 
16
+ export function generateSemanticGraph(eventLog, baseNodes, currentTime = null) {
17
  const nodes = [];
18
  const edges = [];
19
 
 
23
  id: n.id,
24
  label: n.label,
25
  type: 'MaterialEntity',
26
+ properties: {
27
+ originalId: n.id,
28
+ entityType: n.type
29
+ }
30
  });
31
  });
32
 
33
+ // 2. Process the Event Log into canonical 3D relationships
34
  eventLog.forEach(event => {
35
  // Check temporal validity
36
+ if (currentTime !== null && currentTime !== undefined && event.valid_from > currentTime) {
37
+ return;
38
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
+ const isCurrent = event.valid_to === null ||
41
+ (currentTime !== null && currentTime !== undefined ? event.valid_to > currentTime : false);
42
+
43
+ edges.push({
44
+ id: event.id,
45
+ from: event.from,
46
+ to: event.to,
47
+ label: 'has_part',
48
+ type: 'composition',
49
+ properties: {
50
+ validFrom: event.valid_from,
51
+ validTo: event.valid_to,
52
+ isCurrent
53
  }
54
+ });
55
  });
56
 
57
  return { nodes, edges };
58
+ }
js/smim/iso15926.js CHANGED
@@ -1,18 +1,23 @@
1
  /**
2
  * ISO 15926 ONTOLOGY ADAPTER (4D Perdurant)
3
  * -----------------------------------------
4
- * Maps the flat Event Log into a 4D Spatio-Temporal Semantic Graph.
5
  * Entities are treated as 'ActualIndividuals' (4D extents).
6
  * Relationships do not connect extents directly; instead, they connect
7
- * specific 'States' (Temporal Slices) of those entities.
 
 
 
 
 
 
 
 
8
  */
9
 
10
- export function generateSemanticGraph(eventLog, baseNodes, currentTime, storageMode) {
11
  const nodes = [];
12
  const edges = [];
13
-
14
- // Track states per entity to build TRANSITION_TO chains in LPG mode
15
- const entityStates = {};
16
 
17
  // 1. Create Base 4D Extent Nodes (ActualIndividuals)
18
  baseNodes.forEach(n => {
@@ -20,73 +25,87 @@ export function generateSemanticGraph(eventLog, baseNodes, currentTime, storageM
20
  id: `4d_${n.id}`,
21
  label: `${n.label}_4D`,
22
  type: 'ActualIndividual',
23
- data: { originalId: n.id, entityType: n.type }
 
 
 
24
  });
25
- entityStates[n.id] = [];
26
  });
27
 
28
  // 2. Process the Event Log to create Temporal Slices (States)
29
  eventLog.forEach(event => {
30
- const isActive = (event.valid_to === null || event.valid_to > currentTime) && event.valid_from <= currentTime;
31
- // For historical view, we might include past events. Here we process all that started <= currentTime
32
- if (event.valid_from > currentTime) return;
 
 
 
33
 
34
  const parentStateId = `st_${event.from}_${event.id}`;
35
  const childStateId = `st_${event.to}_${event.id}`;
36
-
37
  // Add State nodes for both Parent and Child for this specific event duration
38
- nodes.push({ id: parentStateId, label: `${event.from}_State`, type: 'State', data: { event, isActive, ownerId: event.from } });
39
- nodes.push({ id: childStateId, label: `${event.to}_State`, type: 'State', data: { event, isActive, ownerId: event.to } });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  // Link States to their whole 4D Extents
42
- edges.push({ id: `tpo_p_${event.id}`, from: parentStateId, to: `4d_${event.from}`, label: 'temporalPartOf', type: 'classification', data: { isActive } });
43
- edges.push({ id: `tpo_c_${event.id}`, from: childStateId, to: `4d_${event.to}`, label: 'temporalPartOf', type: 'classification', data: { isActive } });
 
 
 
 
 
 
 
 
44
 
45
- // Link Parent State to Child State
46
- if (storageMode === 'LPG') {
47
- edges.push({
48
- id: event.id,
49
- from: parentStateId,
50
- to: childStateId,
51
- label: 'COMPOSED_OF',
52
- type: 'composition',
53
- data: { isActive, event }
54
- });
55
- // Store state for later transition chaining
56
- if (entityStates[event.from]) entityStates[event.from].push({ stateId: parentStateId, event });
57
- } else { // RDF Mode
58
- edges.push({
59
- id: event.id,
60
- from: parentStateId,
61
- to: childStateId,
62
- label: ':hasPart',
63
- type: 'composition',
64
- data: { isActive, event }
65
- });
66
- }
67
- });
68
 
69
- // 3. LPG-specific rule: Build TRANSITION_TO chains between sequential states of the same whole
70
- if (storageMode === 'LPG') {
71
- Object.keys(entityStates).forEach(entityId => {
72
- const statesList = entityStates[entityId];
73
- // Sort states chronologically by their valid_from time
74
- statesList.sort((a, b) => a.event.valid_from - b.event.valid_from);
75
-
76
- for (let i = 0; i < statesList.length - 1; i++) {
77
- const currState = statesList[i];
78
- const nextState = statesList[i+1];
79
- edges.push({
80
- id: `trans_${entityId}_${i}`,
81
- from: currState.stateId,
82
- to: nextState.stateId,
83
- label: 'TRANSITION_TO',
84
- type: 'transition',
85
- data: { atTime: nextState.event.valid_from, isActive: true }
86
- });
87
  }
88
  });
89
- }
90
 
91
  return { nodes, edges };
92
- }
 
1
  /**
2
  * ISO 15926 ONTOLOGY ADAPTER (4D Perdurant)
3
  * -----------------------------------------
4
+ * Maps the Event Log projection into a 4D Spatio-Temporal Semantic Graph.
5
  * Entities are treated as 'ActualIndividuals' (4D extents).
6
  * Relationships do not connect extents directly; instead, they connect
7
+ * specific 'States' (temporal parts) of those entities via canonical 'hasPart'
8
+ * composition, with states linked to their 4D extents via 'temporalPartOf'.
9
+ *
10
+ * Completely decoupled from database storage (SMS) and UI concerns.
11
+ *
12
+ * @param {Array} eventLog - The projection of temporal events.
13
+ * @param {Array} baseNodes - The projection of base entities.
14
+ * @param {number|null} [currentTime=null] - Global time to evaluate current validity.
15
+ * @returns {{ nodes: Array, edges: Array }} The canonical Semantic Graph.
16
  */
17
 
18
+ export function generateSemanticGraph(eventLog, baseNodes, currentTime = null) {
19
  const nodes = [];
20
  const edges = [];
 
 
 
21
 
22
  // 1. Create Base 4D Extent Nodes (ActualIndividuals)
23
  baseNodes.forEach(n => {
 
25
  id: `4d_${n.id}`,
26
  label: `${n.label}_4D`,
27
  type: 'ActualIndividual',
28
+ properties: {
29
+ originalId: n.id,
30
+ entityType: n.type
31
+ }
32
  });
 
33
  });
34
 
35
  // 2. Process the Event Log to create Temporal Slices (States)
36
  eventLog.forEach(event => {
37
+ if (currentTime !== null && currentTime !== undefined && event.valid_from > currentTime) {
38
+ return;
39
+ }
40
+
41
+ const isCurrent = event.valid_to === null ||
42
+ (currentTime !== null && currentTime !== undefined ? event.valid_to > currentTime : false);
43
 
44
  const parentStateId = `st_${event.from}_${event.id}`;
45
  const childStateId = `st_${event.to}_${event.id}`;
46
+
47
  // Add State nodes for both Parent and Child for this specific event duration
48
+ nodes.push({
49
+ id: parentStateId,
50
+ label: `${event.from}_State`,
51
+ type: 'State',
52
+ properties: {
53
+ ownerId: event.from,
54
+ validFrom: event.valid_from,
55
+ validTo: event.valid_to,
56
+ isCurrent
57
+ }
58
+ });
59
+
60
+ nodes.push({
61
+ id: childStateId,
62
+ label: `${event.to}_State`,
63
+ type: 'State',
64
+ properties: {
65
+ ownerId: event.to,
66
+ validFrom: event.valid_from,
67
+ validTo: event.valid_to,
68
+ isCurrent
69
+ }
70
+ });
71
 
72
  // Link States to their whole 4D Extents
73
+ edges.push({
74
+ id: `tpo_p_${event.id}`,
75
+ from: parentStateId,
76
+ to: `4d_${event.from}`,
77
+ label: 'temporalPartOf',
78
+ type: 'classification',
79
+ properties: {
80
+ isCurrent
81
+ }
82
+ });
83
 
84
+ edges.push({
85
+ id: `tpo_c_${event.id}`,
86
+ from: childStateId,
87
+ to: `4d_${event.to}`,
88
+ label: 'temporalPartOf',
89
+ type: 'classification',
90
+ properties: {
91
+ isCurrent
92
+ }
93
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
+ // Link Parent State to Child State (Tenseless composition between temporal parts)
96
+ edges.push({
97
+ id: event.id,
98
+ from: parentStateId,
99
+ to: childStateId,
100
+ label: 'hasPart',
101
+ type: 'composition',
102
+ properties: {
103
+ validFrom: event.valid_from,
104
+ validTo: event.valid_to,
105
+ isCurrent
 
 
 
 
 
 
 
106
  }
107
  });
108
+ });
109
 
110
  return { nodes, edges };
111
+ }