diff --git a/tag/tag.go b/tag/tag.go index 4818914..dff7ce5 100644 --- a/tag/tag.go +++ b/tag/tag.go @@ -42,10 +42,11 @@ type Tag struct { Aliases []string - // TODO: define an actual TagSet type for this kind of functionality? - // Parents maps 'canonical' (human readable) tag names to their normalised (path friendly) form. It is implemented as - // a map rather than a simple slice to essentially act as a set, with the normalised forms being just a convenience. - Parents map[string]string + // Parents is a set of Tags that can be considered to be directly 'above' this tag in a perceptual hierarchy. It is + // probably best to lean on the broad side when considering what conceptually constitutes a 'parent'. For example, + // 'mathematics' could be considered a parent of 'algebra', 'geometry', etc. but also 'physics', 'engineering', even + // 'music'. + Parents sets.Set[string] // Children ? @@ -220,9 +221,9 @@ func (t *Tag) UnmarshalYAML(value *yaml.Node) error { t.Icon = icon.(string) } if parents, ok := data["parents"]; ok { - t.Parents = map[string]string{} + t.Parents = sets.New[string]() for _, p := range parents.([]any) { - t.Parents[p.(string)] = normaliseName(p.(string)) + t.Parents.Insert(p.(string)) } } if relations, ok := data["relations"]; ok { diff --git a/tag/tag_test.go b/tag/tag_test.go index c512e50..eea0c51 100644 --- a/tag/tag_test.go +++ b/tag/tag_test.go @@ -29,6 +29,10 @@ func Test_LoadPath(t *testing.T) { func Test_normaliseName(t *testing.T) { assert.Equal(t, "test-tag-name", normaliseName("Test TAG name")) assert.Equal(t, "already-normalised", normaliseName("already-normalised")) + tags, _ := LoadAll() + for name, _ := range tags { + t.Logf("tag: %v", name) + } } @@ -56,10 +60,10 @@ func Test_MarshalYAML(t *testing.T) { "QWERTYUIOP", "ASDFGHJKLZ", ), - Parents: map[string]string { - "Parent 1": "parent-1", - "Parent Number Two": "parent-number-two", - }, + Parents: sets.New( + "Parent 1", + "Parent Number Two", + ), Relations: map[string]string { "Relation 1": "similar subject", "Relation Number Two": "first encountered in the same book", @@ -101,10 +105,10 @@ func Test_UnmarshalYAML(t *testing.T) { "QWERTYUIOP", "ASDFGHJKLZ", ), - Parents: map[string]string { - "Parent 1": "parent-1", - "Parent Number Two": "parent-number-two", - }, + Parents: sets.New( + "Parent 1", + "Parent Number Two", + ), Relations: map[string]string { "Relation 1": "similar subject", "Relation Number Two": "first encountered in the same book",