Spaces:
Running
Running
Refactor: Isolate SMIM layer, canonical graphs without DB/UI coupling
Browse files- js/app.js +2 -2
- js/smim/bfo.js +32 -46
- 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
|
| 140 |
} else {
|
| 141 |
-
return isoAdapter.generateSemanticGraph(eventsToProcess, baseNodes.value, state.currentTime
|
| 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 |
-
*
|
| 7 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
*/
|
| 9 |
|
| 10 |
-
export function generateSemanticGraph(eventLog, baseNodes, currentTime
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
});
|
| 22 |
});
|
| 23 |
|
| 24 |
-
// 2. Process the Event Log
|
| 25 |
eventLog.forEach(event => {
|
| 26 |
// Check temporal validity
|
| 27 |
-
if (event.valid_from > currentTime)
|
| 28 |
-
|
| 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 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 5 |
* Entities are treated as 'ActualIndividuals' (4D extents).
|
| 6 |
* Relationships do not connect extents directly; instead, they connect
|
| 7 |
-
* specific 'States' (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
*/
|
| 9 |
|
| 10 |
-
export function generateSemanticGraph(eventLog, baseNodes, currentTime
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
});
|
| 25 |
-
entityStates[n.id] = [];
|
| 26 |
});
|
| 27 |
|
| 28 |
// 2. Process the Event Log to create Temporal Slices (States)
|
| 29 |
eventLog.forEach(event => {
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
| 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({
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
// Link States to their whole 4D Extents
|
| 42 |
-
edges.push({
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 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 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 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 |
+
}
|