From 3b36a44eb038019b02ed7e4b07016460a37a9fa8 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Wed, 12 Nov 2025 17:00:43 +1100 Subject: [PATCH 1/3] avoid mixing up name matching e.g. - natu & eternatus - mew & mewtwo - etc --- src/pokedex/pokedex.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pokedex/pokedex.go b/src/pokedex/pokedex.go index 6c0c05e0..c4ef688f 100644 --- a/src/pokedex/pokedex.go +++ b/src/pokedex/pokedex.go @@ -132,10 +132,9 @@ func Decompress(data []byte) []byte { func CreateNameMetadata(idx string, key string, name PokemonName, rootDir string, fpaths []string) *PokemonMetadata { entryCategories := make(map[int][][]string, 0) - for i, fpath := range fpaths { basename := strings.TrimPrefix(fpath, rootDir) - if strings.Contains(basename, strings.ToLower(name.Slug)) { + if strings.Contains(basename, "/"+strings.ToLower(name.Slug)+"-") || strings.Contains(basename, "/"+strings.ToLower(name.Slug)+".") { data, err := os.ReadFile(fpath) Check(err) cats := createCategories(strings.TrimPrefix(fpath, rootDir), data) From c4b2d5510199bb68eeb18eea430f9a9e0b896323 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Wed, 12 Nov 2025 17:46:04 +1100 Subject: [PATCH 2/3] add test for similar names --- test/data/cows/similar_names/gen7x/mew.cow | 13 ++++ test/data/cows/similar_names/gen7x/mewtwo.cow | 12 +++ .../gen8/eternatus-eternamax.cow | 28 +++++++ .../cows/similar_names/gen8/eternatus.cow | 25 +++++++ test/data/cows/similar_names/gen8/natu.cow | 9 +++ test/pokedex_test.go | 73 +++++++++++++++++++ 6 files changed, 160 insertions(+) create mode 100644 test/data/cows/similar_names/gen7x/mew.cow create mode 100644 test/data/cows/similar_names/gen7x/mewtwo.cow create mode 100644 test/data/cows/similar_names/gen8/eternatus-eternamax.cow create mode 100644 test/data/cows/similar_names/gen8/eternatus.cow create mode 100644 test/data/cows/similar_names/gen8/natu.cow diff --git a/test/data/cows/similar_names/gen7x/mew.cow b/test/data/cows/similar_names/gen7x/mew.cow new file mode 100644 index 00000000..9ba242fc --- /dev/null +++ b/test/data/cows/similar_names/gen7x/mew.cow @@ -0,0 +1,13 @@ +  ▄▄▄▄▄▄▄ + ▄▄▄▄▄ ▄▄▄▀ + ▄▄▄▄▄▀▀▀▀▀▀ +  ▄▄▀ ▄▄ + ▀▄▄▄▄▄▄▄▄▄▄▄▄ + ▀▀ ▄ ▄ ▄ ▄▄▄ +   ▄  ▄▄  ▄▄▄▄▄▄▄▄ +  ▄ ▄▄▄▄▄▄▄▀▀▀▄▄  + ▀▄▄▀ ▄▄▄▄▄▄▀     +       ▄▄▄▄▄▄▄▀ +  ▄ ▄▄▄▄▄▄▄▀▀ + ▀▀  ▄▄  + ▀▀ diff --git a/test/data/cows/similar_names/gen7x/mewtwo.cow b/test/data/cows/similar_names/gen7x/mewtwo.cow new file mode 100644 index 00000000..e45766b9 --- /dev/null +++ b/test/data/cows/similar_names/gen7x/mewtwo.cow @@ -0,0 +1,12 @@ +  ▄▄  ▄▄ ▄▄ + ▄▄▄▄▄▄▄ ▄  ▄▄   + ▄▄ ▄▄ ▄  ▄▄ ▄▀ + ▀▄   ▄▄  ▄▄     +  ▄▄ ▄▄▄▄▀▄▄   ▄  + ▄▄▄▄▄  ▄▄▄▄▀ ▀▄ ▄▄ +   ▄▄▄▄▄▄▄ ▄ ▄▄▄▄▄   +    ▄ ▄▄   ▄▄  ▄▀ + ▄▄ ▄▄▄▄▄▄▄▄▄▄▄▀▀ + ▀▄▄▄▀ ▀▄▄▄▄ +  ▄▄▄▄  + ▀▀▀▀ diff --git a/test/data/cows/similar_names/gen8/eternatus-eternamax.cow b/test/data/cows/similar_names/gen8/eternatus-eternamax.cow new file mode 100644 index 00000000..9ee8e4d0 --- /dev/null +++ b/test/data/cows/similar_names/gen8/eternatus-eternamax.cow @@ -0,0 +1,28 @@ +  ▄ ▄▄▄▄▄ ▄▄▄▄▄ ▄▄ + ▄▄   ▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄   + ▄▄  ▄▄▄ ▄▄▄▄▄▄▄▄▄▀▀▄▄▄▄▄▄▄ ▄▄▄▄ + ▄▄ ▄▄▄▄▀▀▀▀ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▀▀▀▀▀ +  ▄▄▄ ▄▄ ▄▄▀▀▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ + ▀▄ ▄▄▄ ▄▀▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄ + ▀▄ ▄▀▄▄ ▄▄▄▄▄▀▀▀▀▀▀▀▀▀ ▄ ▄▀▀▀▀▀▄▄▄▄▄ ▄▀ + ▀▄  ▄▄ ▄▀▀ ▄▄   ▄▄▄▄▄▄▄ ▄ ▄▄▄▄▄▄▄ ▄▄ ▀▀▀▄▄ ▄▄ + ▄▄▄    ▄▄ ▄▄ ▄▄▄▄  ▄▄ ▄▄ ▄▄▄ ▄▄▄▄▄▄▄▄▄ ▀▄ ▄▄▄ + ▀▄ ▄▄ ▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▀▀▀▀▀ ▄▄▄ ▄ ▄▄▄   ▄▄ + ▀▀▄▄ ▄   ▄▄▄▄ ▄▄  ▄▄▄▄▄▀ ▄▄▄▄ ▄▀ ▀▄ ▄ ▄▄▀ + ▄▄   ▄▄▄▄▄▄ ▄ ▄▄  ▄▄▄  ▄▄▄▄ ▄ ▄▄▄▄▄▄▄▄ ▄▀▄   +   ▄▄ ▄ ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄ ▄▄ ▄▄ ▄▄▄ ▄ ▄ ▄▀▀▀▄▄ ▄▀ + ▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄ ▄▄▄▄▄▄ ▄ ▄▄ ▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄▀▀ ▄▄   + ▄▄▄▄▄ ▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄ ▄▄   ▄▄▄▄▄  ▄▀▀ ▄▄▄▄ ▄▀▀▀ + ▄▄▄▄▄ ▄▀▀▄▄▄ ▄▀▄▄  ▄ ▄ ▄▄▄▄▄▄ ▄ ▄▄▄▄  ▄   ▄▄▄▄▄▄ ▄ ▄▀ + ▄▄▄▄▄▀▀       ▄   ▄▄ ▄▄▄▄▄▄ ▄▄ ▄▄   ▀▄▄▄▄▀▄▄▀ ▀▀ + ▀▀ ▄ ▀▄ ▄▄  ▄ ▄ ▄▄ ▄ ▄ ▄▄    ▄▀ +   ▄▄ ▄▄ ▄ ▄▄▄▄▄▄ ▄▄ ▄▄▄ ▄  ▀ +  ▄▄   ▄▄▄▄  ▄▀▀▄ ▄▄▄▄▄     ▄▄▄ +   ▄▄▄▄▄ ▄▄▀▀▀ ▀▀▄ ▄▀▀▄▄▄▄ ▄    + ▄▄▄▄ ▄▀▀ ▀   ▄   ▄▀ +  ▄▄▄▀   ▄▄▄ ▄  +  ▄▀▀  ▄▄▄  ▄▀ +    ▄▄ +    ▄▄▀ +   ▄▀ + ▀▄▀ diff --git a/test/data/cows/similar_names/gen8/eternatus.cow b/test/data/cows/similar_names/gen8/eternatus.cow new file mode 100644 index 00000000..f18e461b --- /dev/null +++ b/test/data/cows/similar_names/gen8/eternatus.cow @@ -0,0 +1,25 @@ +  ▄▄▄▄ + ▄▄▄ ▄▄▄▄▄ + ▄▄▄▄▄▀▀▄▄▄▄▄ ▄ + ▄▄▄  ▄▄▄▄ ▄▄▄▄▀ ▀▀ ▄ ▄▄▄ ▄▄▄▄ + ▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄  ▄▄▄▄   ▄▄▄▄▀▀▄▄▄▄ + ▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▀ ▄▄▄▄ ▄▄▀ ▀▄▄▀ +   ▄▄▄  ▄▄▄▄ ▄▀▄▄▄ ▄▄▀▀ ▄▄ ▄▄▀▀     + ▄ ▄   ▄▄▄▄  ▄▄▄▄▄▄▄▀ ▄▄▄▄ ▄ ▄▄ ▄▀ ▀ + ▄▄▄▄    ▄ ▄ ▄▄▄ ▄▄▀ ▄▄▄▄ ▄▄▄▀   ▄    +   ▄▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▀ ▄▄▄ ▄▄▀ ▄ +  ▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄ ▄▀▀    ▄▀ ▄▄▄ ▄▄▄▄▄▄▄ +  ▄▄  ▄▄ ▄ ▄▄ ▄▄▄▄▄▀▄▄   ▄▄  ▄ ▄▄▄   ▄▄▄▄▄▄▄▄▄▀ +  ▄▄  ▄ ▄▄▄▄▄▄▄▄▄▀▄ ▄ ▄▄▄▄▄▄   ▄▄  ▄▄▄  ▄▄▄▄▄▄▄▀▀ +  ▄▄▀▄▄▄▄▄ ▄ ▄▄▀▄   ▄▄▄▄ ▄▄▄▄▄▄▄▀▄▄▄ ▄▄▄▄▄▄ ▄▀ ▄▄▄▄▄▄▄ + ▀▀▀▀▄▄▀▀▄▀ ▀▄▄▄▄▄▄▄ ▄▄▄▄▄  ▄  ▄▄▄▄▄ ▄▄▄▄▄▄▄▀ + ▄▄▄▄▄▄ ▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀▀▄ ▄▄▄▄▄▄▄▄▄▀ + ▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄ ▄▄ ▄▄▄▄ ▄▄▄▄▄  ▀▄▄▀ ▀▄▀▄▀ + ▀▀▀▄▄▄▄▄ ▄▄▄▄ ▀▄ ▄▄▄▄▄▄▄▄ ▄▄ ▄ ▄▄▀ + ▄▄▄▄▄ ▄▄ ▄▄  ▀▀▄▄▄▄▄▄▄▄▄ ▄ ▄▄▄ + ▀▀▀▄▄▄▄▄▄▄▀▀ ▀▀▄ ▄ ▄▄▄▄▄▄▄▄ + ▀▄▄▄▀▀ ▄▄▄▄▄▄▀▀▄▄▄ ▄▄▄  + ▀▄▄▀▀ ▄▄▄ ▄▄▄ ▄▀ + ▄▄▄▄▀▄▄▄▄▀ +  ▄▀▀▄▄▄▀▀ + ▀▀ diff --git a/test/data/cows/similar_names/gen8/natu.cow b/test/data/cows/similar_names/gen8/natu.cow new file mode 100644 index 00000000..cfddd175 --- /dev/null +++ b/test/data/cows/similar_names/gen8/natu.cow @@ -0,0 +1,9 @@ +  ▄▄▄▄ + ▄▄▄▄▀ + ▄▄▄▄▄▄▄▄ +  ▄▄ ▄▄▄▄ +   ▄▄ ▄▄▄ ▄▄ ▄  + ▄▄▄▄▄▄▄    ▄ ▄  + ▀▄▄▄▄▄ ▄▄▄▄▄▄  + ▀▄▄▄▄▄▄▄▄▀▀▀ + ▀▀  ▄▀ diff --git a/test/pokedex_test.go b/test/pokedex_test.go index a988aeec..3f9ebf81 100644 --- a/test/pokedex_test.go +++ b/test/pokedex_test.go @@ -2,6 +2,7 @@ package test import ( "embed" + "fmt" "os" "testing" @@ -53,3 +54,75 @@ func TestReadMetadataFromEmbedded(test *testing.T) { Assert(expected, result, test) } + +func TestCreateNameMetadataMew(test *testing.T) { + result := pokedex.CreateNameMetadata( + fmt.Sprintf("%04d", 0), + "mew", + pokedex.PokemonName{English: "Mew", Japanese: "ミュウ", JapanesePhonetic: "myuu", Slug: "mew"}, + "data/cows/similar_names/", + []string{"data/cows/similar_names/gen7x/mew.cow", "data/cows/similar_names/gen7x/mewtwo.cow"}, + ) + expected := &pokedex.PokemonMetadata{ + Idx: "0000", + Name: "Mew", + JapaneseName: "ミュウ", + JapanesePhonetic: "myuu", + Entries: []pokedex.PokemonEntryMapping{ + {EntryIndex: 0, Categories: []string{"medium", "gen7x"}}, + }, + } + + Assert(expected, result, test) +} + +func TestCreateNameMetadataNatu(test *testing.T) { + result := pokedex.CreateNameMetadata( + fmt.Sprintf("%04d", 0), + "natu", + pokedex.PokemonName{English: "Natu", Japanese: "ネイティ", JapanesePhonetic: "neiti", Slug: "natu"}, + "data/cows/similar_names/", + []string{ + "data/cows/similar_names/gen8/natu.cow", + "data/cows/similar_names/gen8/eternatus.cow", + "data/cows/similar_names/gen8/eternatus-eternamax.cow", + }, + ) + expected := &pokedex.PokemonMetadata{ + Idx: "0000", + Name: "Natu", + JapaneseName: "ネイティ", + JapanesePhonetic: "neiti", + Entries: []pokedex.PokemonEntryMapping{ + {EntryIndex: 0, Categories: []string{"small", "gen8"}}, + }, + } + + Assert(expected, result, test) +} + +func TestCreateNameMetadataEternatus(test *testing.T) { + result := pokedex.CreateNameMetadata( + fmt.Sprintf("%04d", 0), + "eternatus", + pokedex.PokemonName{English: "Eternatus", Japanese: "ムゲンダイナ", JapanesePhonetic: "mugendaina", Slug: "eternatus"}, + "data/cows/similar_names/", + []string{ + "data/cows/similar_names/gen8/natu.cow", + "data/cows/similar_names/gen8/eternatus.cow", + "data/cows/similar_names/gen8/eternatus-eternamax.cow", + }, + ) + expected := &pokedex.PokemonMetadata{ + Idx: "0000", + Name: "Eternatus", + JapaneseName: "ムゲンダイナ", + JapanesePhonetic: "mugendaina", + Entries: []pokedex.PokemonEntryMapping{ + {EntryIndex: 1, Categories: []string{"big", "gen8"}}, + {EntryIndex: 2, Categories: []string{"big", "gen8"}}, + }, + } + + Assert(expected, result, test) +} \ No newline at end of file From 65a4760aa448d7c20920f3e89760b2251a99ec35 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Wed, 12 Nov 2025 18:01:25 +1100 Subject: [PATCH 3/3] add some extra categories the most popular ones: - "hisui", "galar", "totem", "gmax", "alola", "mega" --- src/pokedex/pokedex.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/pokedex/pokedex.go b/src/pokedex/pokedex.go index c4ef688f..1f9a2064 100644 --- a/src/pokedex/pokedex.go +++ b/src/pokedex/pokedex.go @@ -172,6 +172,17 @@ func createCategories(fpath string, data []byte) []string { parts := strings.Split(fpath, "/") height := sizeCategory(len(strings.Split(string(data), "\n"))) + extra := []string{"hisui", "galar", "totem", "gmax", "alola", "mega"} + + nameParts := strings.Split( + strings.TrimSuffix(parts[len(parts)-1], ".cow"), + "-", + ) + for _, ex := range extra { + if nameParts[len(nameParts)-1] == ex { + return append([]string{height, ex}, parts[0:len(parts)-1]...) + } + } return append([]string{height}, parts[0:len(parts)-1]...) }