Implement automatic titles

This commit is contained in:
Juno Takano 2025-12-10 10:19:51 -03:00
commit c6fccd2d7b
4 changed files with 31 additions and 37 deletions

View file

@ -6,11 +6,11 @@ It works by ingesting a TOML file containing your node specification and serving
## Roadmap ## Roadmap
- [ ] Automatic anchors
- [x] Array syntax for lightweight connections - [x] Array syntax for lightweight connections
- [x] Automatic IDs - [x] Automatic IDs
- [ ] Automatic titles - [x] Automatic titles
- [ ] Automatic anchors - [x] Mismatch between TOML ID and provided ID
- [ ] Mismatch between TOML ID and provided ID
## Motivation ## Motivation

View file

@ -28,15 +28,6 @@ fn modulate_nodes(old_nodes: HashMap<String, Node>) -> HashMap<String, Node> {
let connections = node.connections.clone().unwrap_or_default(); let connections = node.connections.clone().unwrap_or_default();
let mut new_edges = connections.clone(); let mut new_edges = connections.clone();
for link in node.links.iter() {
new_edges.push(Edge {
from: key.to_string(),
to: link.to_string(),
anchor: String::new(),
detached: !old_nodes.contains_key(link),
})
}
for (i, edge) in connections.iter().enumerate() { for (i, edge) in connections.iter().enumerate() {
let mut new_edge = edge.clone(); let mut new_edge = edge.clone();
@ -54,8 +45,26 @@ fn modulate_nodes(old_nodes: HashMap<String, Node>) -> HashMap<String, Node> {
new_edges[i] = new_edge; new_edges[i] = new_edge;
} }
// Create connections for each link
for link in node.links.iter() {
new_edges.push(Edge {
from: key.to_string(),
to: link.to_string(),
anchor: String::new(),
detached: !old_nodes.contains_key(link),
})
}
// Populate empty titles with IDs
let new_title = if node.title.is_empty() {
key.clone()
} else {
node.title.clone()
};
let new_node = Node { let new_node = Node {
id: key.clone(), id: key.clone(),
title: new_title,
connections: Some(new_edges), connections: Some(new_edges),
..node.clone() ..node.clone()
}; };

View file

@ -3,34 +3,29 @@ use std::collections::HashMap;
#[derive(Serialize, Deserialize, Clone, Default, Debug)] #[derive(Serialize, Deserialize, Clone, Default, Debug)]
pub struct Graph { pub struct Graph {
pub messages: Vec<String>,
pub root_node: String,
pub nodes: HashMap<String, Node>, pub nodes: HashMap<String, Node>,
#[serde(skip)] pub root_node: String,
pub incoming: HashMap<String, Vec<Edge>>, #[serde(default)] pub messages: Vec<String>,
#[serde(skip)] pub incoming: HashMap<String, Vec<Edge>>,
} }
#[derive(Serialize, Deserialize, Clone, Default, Debug)] #[derive(Serialize, Deserialize, Clone, Default, Debug)]
pub struct Node { pub struct Node {
pub title: String,
pub body: String, pub body: String,
#[serde(default)] pub title: String,
#[serde(default)] pub links: Vec<String>,
#[serde(default)] pub id: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub connections: Option<Vec<Edge>>, pub connections: Option<Vec<Edge>>,
#[serde(default)]
pub links: Vec<String>,
#[serde(default)]
pub id: String,
} }
#[derive(Serialize, Clone, Default, PartialEq, Deserialize, Debug)] #[derive(Serialize, Clone, Default, PartialEq, Deserialize, Debug)]
pub struct Edge { pub struct Edge {
pub to: String, pub to: String,
#[serde(default)] #[serde(default)] pub anchor: String,
pub anchor: String, #[serde(default)] pub from: String,
#[serde(default)] #[serde(default)] pub detached: bool,
pub from: String,
#[serde(default)]
pub detached: bool,
} }
impl Graph { impl Graph {

View file

@ -1,8 +1,6 @@
messages = []
root_node = "Interface" root_node = "Interface"
[nodes.Interface] [nodes.Interface]
title = "Interface"
body = """ body = """
An interface is a point of contact between the inside and the outside of something. Contrast with intraface. An interface is a point of contact between the inside and the outside of something. Contrast with intraface.
""" """
@ -10,7 +8,6 @@ An interface is a point of contact between the inside and the outside of somethi
links = ["Intraface"] links = ["Intraface"]
[nodes.Intraface] [nodes.Intraface]
title = "Intraface"
body = """ body = """
The intraface is the reflexive process of communicating, creating, thinking, that does not or cannot get shared with others. Contrast with interface. The intraface is the reflexive process of communicating, creating, thinking, that does not or cannot get shared with others. Contrast with interface.
""" """
@ -18,13 +15,11 @@ The intraface is the reflexive process of communicating, creating, thinking, tha
links = ["Thinking", "Interface"] links = ["Thinking", "Interface"]
[nodes.Thinking] [nodes.Thinking]
title = "Thinking"
body = """ body = """
Thinking is a process by which some beings create and manipulate mental constructs. Thinking is a process by which some beings create and manipulate mental constructs.
""" """
[nodes.Paradigm] [nodes.Paradigm]
title = "Paradigm"
body = """ body = """
A paradigm is a cohesive set of beliefs, methods and principles that serve both as justification for a given position and as guidance for how to pursue its praxis. A paradigm is a cohesive set of beliefs, methods and principles that serve both as justification for a given position and as guidance for how to pursue its praxis.
""" """
@ -32,7 +27,6 @@ A paradigm is a cohesive set of beliefs, methods and principles that serve both
links = [ "Principle", "Belief", "Method", "Position", "Praxis" ] links = [ "Principle", "Belief", "Method", "Position", "Praxis" ]
[nodes.Principle] [nodes.Principle]
title = "Principle"
body = """ body = """
A principle is a belief that implies commitment and necessity. A principle is a belief that implies commitment and necessity.
@ -50,7 +44,6 @@ anchor = "identifying"
to = "Identity" to = "Identity"
[nodes.Religion] [nodes.Religion]
title = "Religion"
body = """ body = """
A religion is a paradigm that involves unfalsifiable beliefs, particularly those in the domain of morality. A religion is a paradigm that involves unfalsifiable beliefs, particularly those in the domain of morality.
@ -79,7 +72,6 @@ links = [
] ]
[nodes.Identity] [nodes.Identity]
title = "Identity"
body = """ body = """
Identity is how individuals construe their sameness and otherness from each other and from nothingness. Identity is how individuals construe their sameness and otherness from each other and from nothingness.
""" """
@ -91,7 +83,6 @@ anchor = "nothingness"
to = "Emptiness" to = "Emptiness"
[nodes.Emptiness] [nodes.Emptiness]
title = "Emptiness"
body = """ body = """
Emptiness is the vacuous base in which entities exist. Emptiness is the vacuous base in which entities exist.
""" """
@ -99,7 +90,6 @@ Emptiness is the vacuous base in which entities exist.
links = [ "Entity" ] links = [ "Entity" ]
[nodes.Entity] [nodes.Entity]
title = "Entity"
body = """ body = """
An entity is anything except for actual emptiness. It does not have to be sentient, or physical. It can be an idea, a concept, a memory. The concept of emptiness is an entity, but emptiness itself is not. An entity is anything except for actual emptiness. It does not have to be sentient, or physical. It can be an idea, a concept, a memory. The concept of emptiness is an entity, but emptiness itself is not.
""" """