mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 15:26:17 +00:00
feat(ffi): virtual tag nodes, single page type, rename and remove tag
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e2ed9054c6
commit
0005a8e7a4
8 files changed
+409
-378
No files matched your search
@@ -115,6 +115,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result<GraphData> {
|
||||
is_hub: false,
|
||||
home_hub: None,
|
||||
tags,
|
||||
is_tag: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -227,7 +228,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result<GraphData> {
|
||||
}
|
||||
}
|
||||
|
||||
tagged(g, &index, &by_key, &mut b)?;
|
||||
tagged(g, &index, &mut nodes, &mut b)?;
|
||||
|
||||
// Stable edge order (sources, then targets, then kind).
|
||||
let mut edges: Vec<((u32, u32, u8), f32)> = b.edges.into_iter().collect();
|
||||
@@ -245,7 +246,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result<GraphData> {
|
||||
neigh[s as usize].insert(t);
|
||||
neigh[t as usize].insert(s);
|
||||
referrers[t as usize].insert(s);
|
||||
if k == edge_kind::TAG {
|
||||
if k == edge_kind::TAG || k == edge_kind::TAGGED {
|
||||
*tag_use[s as usize].entry(t).or_default() += w;
|
||||
}
|
||||
}
|
||||
@@ -283,20 +284,48 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result<GraphData> {
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// A page filed under a tag page gets one `TAGGED` edge to it.
|
||||
/// Tags are virtual nodes (`tag:<key>`, appended after the pages): every page carrying a tag,
|
||||
/// listed or implied by a type, gets one `TAGGED` edge to it.
|
||||
fn tagged(
|
||||
g: &Graph,
|
||||
index: &HashMap<String, u32>,
|
||||
by_key: &HashMap<String, u32>,
|
||||
nodes: &mut Vec<GraphNode>,
|
||||
b: &mut Builder,
|
||||
) -> Result<()> {
|
||||
let mut st = g.conn().prepare("SELECT tag_key, page_id FROM page_tags")?;
|
||||
let display: HashMap<String, String> = g
|
||||
.tag_catalog()?
|
||||
.into_iter()
|
||||
.map(|t| (title_key(&t.name), t.name))
|
||||
.collect();
|
||||
let mut st = g
|
||||
.conn()
|
||||
.prepare("SELECT tag_key, page_id FROM page_tags ORDER BY tag_key, page_id")?;
|
||||
let rows = st.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))?;
|
||||
let mut tag_index: HashMap<String, u32> = HashMap::new();
|
||||
for row in rows {
|
||||
let (tag, page) = row?;
|
||||
if let (Some(&s), Some(&t)) = (index.get(&page), by_key.get(&tag)) {
|
||||
b.add(s, t, edge_kind::TAGGED, 1.0);
|
||||
}
|
||||
let (key, page) = row?;
|
||||
let Some(&s) = index.get(&page) else {
|
||||
continue;
|
||||
};
|
||||
let t = *tag_index.entry(key.clone()).or_insert_with(|| {
|
||||
nodes.push(GraphNode {
|
||||
id: format!("tag:{key}"),
|
||||
title: display.get(&key).cloned().unwrap_or_else(|| key.clone()),
|
||||
journal_date: None,
|
||||
origin_journal: None,
|
||||
created_at: 0,
|
||||
degree: 0,
|
||||
backlinks: 0,
|
||||
cluster: 0,
|
||||
primary_tag: None,
|
||||
is_hub: false,
|
||||
home_hub: None,
|
||||
tags: Vec::new(),
|
||||
is_tag: true,
|
||||
});
|
||||
nodes.len() as u32 - 1
|
||||
});
|
||||
b.add(s, t, edge_kind::TAGGED, 1.0);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user