Skip to main content

zagens_topic_memory/
graph.rs

1//! Pheromone-style topic graph (B2 / topic-memory-graph port).
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7pub const GRAPH_SCHEMA_VERSION: &str = "0.1.0";
8
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
10pub struct PheromoneGraph {
11    pub version: String,
12    #[serde(rename = "lastDecay")]
13    pub last_decay: String,
14    pub nodes: HashMap<String, PheromoneNode>,
15    pub edges: HashMap<String, PheromoneEdge>,
16    #[serde(rename = "blockedPoints")]
17    pub blocked_points: Vec<BlockedPoint>,
18    #[serde(rename = "recentEmotions", skip_serializing_if = "Option::is_none")]
19    pub recent_emotions: Option<Vec<EmotionMode>>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub trails: Option<Vec<CognitiveTrail>>,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
25pub struct PheromoneNode {
26    pub count: u32,
27    #[serde(rename = "lastSeen")]
28    pub last_seen: String,
29    pub strength: f64,
30    pub depth: f64,
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub blocked: Option<bool>,
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub dormant: Option<bool>,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
38pub struct PheromoneEdge {
39    pub weight: f64,
40    #[serde(rename = "lastSeen")]
41    pub last_seen: String,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
45pub struct BlockedPoint {
46    pub node: String,
47    pub context: String,
48    pub since: String,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
52pub struct CognitiveTrail {
53    pub entry: String,
54    pub exit: String,
55    pub date: String,
56    pub emotion: EmotionMode,
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
60pub enum EmotionMode {
61    #[serde(rename = "A")]
62    Angry,
63    #[serde(rename = "B")]
64    Happy,
65    #[serde(rename = "C")]
66    Sad,
67    #[serde(rename = "N")]
68    Neutral,
69}
70
71impl EmotionMode {
72    #[must_use]
73    pub fn as_wire(self) -> &'static str {
74        match self {
75            Self::Angry => "A",
76            Self::Happy => "B",
77            Self::Sad => "C",
78            Self::Neutral => "N",
79        }
80    }
81}