mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 23:36:20 +00:00
feat(graph): a hub stands for its implicit tag, no separate tag node beside it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
58c3ee9611
commit
ad62a7d258
4 files changed
+71
-27
No files matched your search
@@ -926,23 +926,35 @@ class MemoryBackend implements GraphBackend {
|
||||
t.add(index[m]!);
|
||||
k.add(EdgeKind.contains.index);
|
||||
}
|
||||
// Tags are virtual nodes after the pages; a page points at each of its tags.
|
||||
// Tags are virtual nodes after the pages; a page points at each of its tags. A tag
|
||||
// named like a hub uses the hub's node, and its members (already contained) skip it.
|
||||
final hubNodes = {
|
||||
for (final id in ids)
|
||||
if (_isHub(id)) _tagKey(pages[id]!.title): index[id]!,
|
||||
};
|
||||
final tagNames = <String, String>{};
|
||||
for (final p in pages.values) {
|
||||
for (final tg in allTags(p)) {
|
||||
if (hubNodes.containsKey(_tagKey(tg))) continue;
|
||||
tagNames.putIfAbsent(_tagKey(tg), () => tg);
|
||||
}
|
||||
}
|
||||
final tagKeys = tagNames.keys.toList()..sort();
|
||||
final tagIndex = {
|
||||
...hubNodes,
|
||||
for (var j = 0; j < tagKeys.length; j++) tagKeys[j]: ids.length + j,
|
||||
};
|
||||
final contained = {
|
||||
for (final (h, m) in containsEdges) (index[h]!, index[m]!),
|
||||
};
|
||||
for (final p in pages.values) {
|
||||
final i = index[p.id];
|
||||
if (i == null) continue;
|
||||
for (final tg in allTags(p)) {
|
||||
final to = tagIndex[_tagKey(tg)]!;
|
||||
if (to == i || contained.contains((to, i))) continue;
|
||||
s.add(i);
|
||||
t.add(tagIndex[_tagKey(tg)]!);
|
||||
t.add(to);
|
||||
k.add(EdgeKind.tagged.index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ void main() {
|
||||
expect(() => b.setPageTags(j.id, ['x']), throwsException);
|
||||
});
|
||||
|
||||
test('a hub is an implicit tag of its members, merged once', () async {
|
||||
test('a hub is an implicit tag of its members, shown as the hub', () async {
|
||||
final b = MemoryBackend();
|
||||
final media = b.createPage('Media');
|
||||
b.makeHub(media.id);
|
||||
@@ -100,17 +100,10 @@ void main() {
|
||||
expect(cat.single.count, 2);
|
||||
expect(b.pages[a.id]!.tags, isEmpty);
|
||||
|
||||
// In the graph the hub stands for its tag: no tag node, members only contained.
|
||||
final data = await b.graphData();
|
||||
final tags = data.nodes.where((n) => n.isTag).toList();
|
||||
expect(tags.length, 1);
|
||||
expect(tags.single.backlinks, 2);
|
||||
final ti = data.nodes.indexOf(tags.single);
|
||||
final from = [
|
||||
for (var e = 0; e < data.kinds.length; e++)
|
||||
if (data.kinds[e] == EdgeKind.tagged.index && data.targets[e] == ti)
|
||||
data.nodes[data.sources[e]].title,
|
||||
]..sort();
|
||||
expect(from, ['Bleach', 'Naruto']);
|
||||
expect(data.nodes.where((n) => n.isTag), isEmpty);
|
||||
expect(data.kinds.contains(EdgeKind.tagged.index), isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user