Add syntax for simpler connections between nodes

This commit is contained in:
Juno Takano 2025-12-10 00:58:46 -03:00
commit 26d6b3240a
4 changed files with 65 additions and 74 deletions

View file

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

View file

@ -26,7 +26,16 @@ fn modulate_nodes(old_nodes: HashMap<String, Node>) -> HashMap<String, Node> {
for (key, node) in old_nodes.iter() {
let connections = node.connections.clone().unwrap_or_default();
let mut vec = 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() {
@ -42,14 +51,14 @@ fn modulate_nodes(old_nodes: HashMap<String, Node>) -> HashMap<String, Node> {
new_edge.detached = true;
}
vec[i] = new_edge;
new_edges[i] = new_edge;
}
let new_node = Node {
connections: Some(vec),
connections: Some(new_edges),
..node.clone()
};
nodes.insert(key.to_string(), new_node);
}
@ -64,14 +73,9 @@ fn make_incoming(nodes: HashMap<String, Node>) -> HashMap<String, Vec<Edge>> {
let empty_vec: Vec<Edge> = vec![];
for edge in node.connections.clone().unwrap_or_default().iter() {
let vec = incoming.get(&edge.to.clone()).unwrap_or(&empty_vec);
if vec.contains(edge) {
vec.clone().extend_from_slice(&[edge.clone()]);
incoming.insert(edge.to.clone(), vec.clone());
} else {
incoming.insert(edge.to.clone(), vec![edge.clone()]);
}
let mut edges = incoming.get(&edge.to.clone()).unwrap_or(&empty_vec).clone();
edges.extend_from_slice(&[edge.clone()]);
incoming.insert(edge.to.clone(), edges.clone());
}
}

View file

@ -28,14 +28,16 @@ pub struct Node {
pub body: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub connections: Option<Vec<Edge>>,
#[serde(default)]
pub links: Vec<String>,
}
impl Graph {
pub fn new(message: Option<String>) -> Graph {
Self {
nodes: HashMap::new(),
incoming: HashMap::new(),
root_node: "".to_string(),
incoming: HashMap::new(),
messages: vec![message
.unwrap_or("This graph is empty or in error".to_string())],
}
@ -59,6 +61,7 @@ impl Node {
None => "Node is empty, missing or wasn't found.".to_string()
},
connections: None,
links: vec![],
}
}
}

View file

@ -8,8 +8,7 @@ body = """
An interface is a point of contact between the inside and the outside of something. Contrast with intraface.
"""
[[nodes.Interface.connections]]
to = "Intraface"
links = ["Intraface"]
[nodes.Intraface]
title = "Intraface"
@ -18,12 +17,7 @@ body = """
The intraface is the reflexive process of communicating, creating, thinking, that does not or cannot get shared with others. Contrast with interface.
"""
[[nodes.Intraface.connections]]
to = "Thinking"
[[nodes.Intraface.connections]]
to = "Interface"
links = ["Thinking", "Interface"]
[nodes.Thinking]
title = "Thinking"
@ -39,20 +33,7 @@ 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.
"""
[[nodes.Paradigm.connections]]
to = "Belief"
[[nodes.Paradigm.connections]]
to = "Method"
[[nodes.Paradigm.connections]]
to = "Principle"
[[nodes.Paradigm.connections]]
to = "Position"
[[nodes.Paradigm.connections]]
to = "Praxis"
links = [ "Principle", "Belief", "Method", "Position", "Praxis" ]
[nodes.Principle]
title = "Principle"
@ -67,22 +48,12 @@ A principle is usually informed by experience or formed by cultural context, nam
As other beliefs, simply identifying with a principle does not mean one follows it, which can introduce a sense of dissonance and/or guilt.
"""
links = [ "Dissonance", "Guilt", "Belief", "Religion", ]
[[nodes.Principle.connections]]
anchor = "identifying"
to = "Identity"
[[nodes.Principle.connections]]
to = "Dissonance"
[[nodes.Principle.connections]]
to = "Guilt"
[[nodes.Principle.connections]]
to = "Belief"
[[nodes.Principle.connections]]
to = "Religion"
[nodes.Religion]
title = "Religion"
id = "Religion"
@ -98,35 +69,48 @@ Religion does not subsist solely because of its hard truths, but because it cate
One poignant fact about religion is that its dogmas tend to create exclusion, segregating those who can or want to adhere to them from those who can't or don't want to. This not only means religion will create divisions, it also means that the people excluded from it will be left with less means to fulfill the previously mentioned basic human necessities that religion addresses.
"""
[[nodes.Religion.connections]]
to = "Paradigm"
links = [
"Paradigm",
"Principle",
"Truth",
"Tradition",
"Morality",
"Episteme",
"Necessity",
"Knowledge",
"Community",
"Identity",
"Dogma",
"Reductionism",
]
[[nodes.Religion.connections]]
to = "Truth"
[nodes.Identity]
title = "Identity"
id = "Identity"
body = """
Identity is how individuals construe their sameness and otherness from each other and from nothingness.
"""
[[nodes.Religion.connections]]
to = "Necessity"
links = ["Principle"]
[[nodes.Religion.connections]]
to = "Knowledge"
[[nodes.Identity.connections]]
anchor = "nothingness"
to = "Emptiness"
[[nodes.Religion.connections]]
to = "Community"
[nodes.Emptiness]
title = "Emptiness"
id = "Emptiness"
body = """
Emptiness is the vacuous base in which entities exist.
"""
[[nodes.Religion.connections]]
to = "Identity"
links = [ "Entity" ]
[[nodes.Religion.connections]]
to = "Episteme"
[nodes.Entity]
title = "Entity"
id = "Entity"
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.
"""
[[nodes.Religion.connections]]
to = "Morality"
[[nodes.Religion.connections]]
to = "Dogma"
[[nodes.Religion.connections]]
to = "Tradition"
[[nodes.Religion.connections]]
to = "Reductionism"
links = [ "Emptiness" ]