Skip to content

Add script to find related cards candidates - #1

Open
Querela wants to merge 1 commit into
thomas-bassett:poc-related-cardsfrom
Querela:poc-related-cards
Open

Querela wants to merge 1 commit into
thomas-bassett:poc-related-cardsfrom
Querela:poc-related-cards

Conversation

@Querela

@Querela Querela commented Jul 1, 2026

Copy link
Copy Markdown

Adds the script scripts/findRelatedCards.ts to generate likely related (translation) candidates. This script generates a hash from card metadata to cluster likely related cards (primarily using the card's illustrator combined with card type and additional fields). It allows to output JSON or default console logging.

Example execution:

# in the root of the cards-database repository folder:
# cards-database$

bun ./scripts/findRelatedCards.ts -h
# help

bun ./scripts/findRelatedCards.ts "data/Mega*/*/*.ts" -c Pokemon -i --json
# - provide one or more file patterns to cards, here for "Mega Evolution"
# - `-c` filter for``category` like "Pokemon"/"Trainer"/"Energy"
# - `-i` filter to only those cards that have an asset image link (TCGdex CDN)
# - `--json` output as JSON

bun findRelatedCards.ts "data/*/*/*.ts" "data-asia/*/*/*.ts"
# run over all cards

Example output:

Loading image assets information from ...
Found 797 files for pattern "data/Mega*/*/*.ts"
# ...
Parse errors:             0.00% (0)
No illustrators:          13.43% (107)
Wrong category:           18.82% (150)
----------------------------------------
Unique keys (total):      533
Possible mappings:        1.31% (7)
Filter mappings by requiring valid image assets...
Possible mappings:        1.31% (7)
# ...
✅ satoma:Pokemon:Common:Stage1:100:Psychic:-:-:Psychic0,Psychic30:1
        🎴 data/Mega Evolution/Mega Evolution/059.ts
           ⤷ 🖼️ https://assets.tcgdex.net/en/me/me01/059/high.png
        🎴 data/Mega Evolution/Ascended Heroes/088.ts
           ⤷ 🖼️ https://assets.tcgdex.net/en/me/me02.5/088/high.png
{
  "5ban Graphics:Pokemon:Double rare:Stage1:340:Fighting:-:-:Fighting130,Fighting+Fighting270:2": [
    {
      "path": "data/Mega Evolution/Ascended Heroes/113.ts",
      "url": "https://assets.tcgdex.net/en/me/me02.5/113/high.png",
      "cardId": "113",
      "setId": "me02.5",
      "serieId": "me",
      "lang": "en"
    },
    {
      "path": "data/Mega Evolution/Mega Evolution/077.ts",
      "url": "https://assets.tcgdex.net/en/me/me01/077/high.png",
      "cardId": "077",
      "setId": "me01",
      "serieId": "me",
      "lang": "en"
    }
  ]
}

Caveats

  • relies heavily on illustrator field to be set, which is not everywhere (either missing or not on Energy cards); but other hashes might make sense, too (dexId field is also not everywhere, so unreliable)
  • card hash for Energy/Trainer cards has just to little distinct information for good grouping
  • originally intended to map asian with western cards ("translation") but stamped/reprinted card variants are interesting, too, BUT how to automatically evaluate more than 2 card match candidates?
  • Question: what is "sameness"? --> /en/bw/bw4/50/, /en/bw/bwp/BW24/, /en/bw/bw1/47/ have different art (same illustrator) but are otherwise identical...

Ideas

  • webui to quickly and easily compare images manually
  • imagehash to create some perceptual hash to compare images automatically, should also work across languages, probably
  • automatically infer related sets (series should probably be done manually) based on common card mappings?
  • probably not the best idea to create a jscodeshift transform script (but possible) as manual review seems important for quality assurance (hence some webui or similar for quick review), but this script as intermediate result, input for UI review tool which outputs for jscodeshift transform script to update cards-database?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant