Skip to content

fix: improve AniList alternative name handling and reading generation#18

Merged
bee-san merged 3 commits intomainfrom
claude/fix-anilist-alt-names-GqgZK
Mar 10, 2026
Merged

fix: improve AniList alternative name handling and reading generation#18
bee-san merged 3 commits intomainfrom
claude/fix-anilist-alt-names-GqgZK

Conversation

@bee-san
Copy link
Owner

@bee-san bee-san commented Mar 10, 2026

  • Parse "Romanized (Japanese)" format in alt names: extract Japanese part
    as the dictionary term and use the romanized part for reading generation
    (e.g. "Aoki Umi (碧井海)" → term "碧井海" with reading "あおきうみ")
  • Filter out non-Japanese aliases to prevent English terms like "Ruri's
    Mother" from getting dictionary entries
  • Strip internal whitespace from generated readings to fix issues like
    "えらいな の はは" → "えらいなのはは"
  • Add contains_japanese() helper to kana module for detecting Japanese text

https://claude.ai/code/session_01NRsURdxvKrse2dQTBW7LZ4

claude added 2 commits March 10, 2026 05:59
- Parse "Romanized (Japanese)" format in alt names: extract Japanese part
  as the dictionary term and use the romanized part for reading generation
  (e.g. "Aoki Umi (碧井海)" → term "碧井海" with reading "あおきうみ")
- Filter out non-Japanese aliases to prevent English terms like "Ruri's
  Mother" from getting dictionary entries
- Strip internal whitespace from generated readings to fix issues like
  "えらいな の はは" → "えらいなのはは"
- Add contains_japanese() helper to kana module for detecting Japanese text

https://claude.ai/code/session_01NRsURdxvKrse2dQTBW7LZ4
- Add `alternativeSpoiler` to the AniList GraphQL character query
- Add `spoiler_aliases` field to Character model
- Parse spoiler alternatives from API response, filtering nulls/empties
- Merge spoiler aliases (deduplicated union) during character merging
- Include spoiler alias entries in dictionary only when user has enabled
  the existing `show_spoilers` setting
- VNDB characters default to empty spoiler_aliases (no equivalent field)

https://claude.ai/code/session_01NRsURdxvKrse2dQTBW7LZ4
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves character alias ingestion and reading generation when building Yomitan dictionaries, primarily by enhancing AniList alternative-name parsing (including spoiler-marked aliases) and normalizing kana readings produced from romaji.

Changes:

  • Add spoiler_aliases to the Character model, parse AniList alternativeSpoiler, and gate spoiler alias entries behind show_spoilers.
  • Improve alias term generation by parsing Romanized (Japanese) formats and filtering out non-Japanese aliases from becoming dictionary terms.
  • Normalize generated readings by stripping internal whitespace, and add kana::contains_japanese() to support alias filtering.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
yomitan-dict-builder/src/anilist_client.rs Fetches/parses AniList alternativeSpoiler into spoiler_aliases and adds tests.
yomitan-dict-builder/src/models.rs Extends Character with spoiler_aliases (serde default).
yomitan-dict-builder/src/vndb_client.rs Sets spoiler_aliases to empty for VNDB characters.
yomitan-dict-builder/src/kana.rs Adds contains_japanese() helper for Japanese-script detection.
yomitan-dict-builder/src/name_parser.rs Strips internal whitespace from readings and adds tests covering the behavior.
yomitan-dict-builder/src/anilist_name_test_data.rs Updates expected readings to reflect whitespace stripping.
yomitan-dict-builder/src/dict_builder.rs Parses Romanized (Japanese) aliases, filters non-Japanese aliases, integrates spoiler aliases, and adds tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +308 to +315
if !other.spoiler_aliases.is_empty() {
let existing: HashSet<String> = base.spoiler_aliases.iter().cloned().collect();
for alias in &other.spoiler_aliases {
if !alias.is_empty() && !existing.contains(alias) {
base.spoiler_aliases.push(alias.clone());
}
}
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge_character_fields claims spoiler aliases are deduplicated, but the existing HashSet is never updated as new aliases are pushed. If other.spoiler_aliases contains duplicates (or repeats within the loop), duplicates can still be appended to base.spoiler_aliases. Consider making existing mutable and inserting into it when pushing (e.g., if existing.insert(alias.clone()) { ... }).

Copilot uses AI. Check for mistakes.
Comment on lines +688 to +693
// Include spoiler aliases when the user has enabled spoilers
let all_aliases: Box<dyn Iterator<Item = &String>> = if self.settings.show_spoilers {
Box::new(char.aliases.iter().chain(char.spoiler_aliases.iter()))
} else {
Box::new(char.aliases.iter())
};
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building all_aliases as Box<dyn Iterator<...>> adds a heap allocation and dynamic dispatch on a hot path. This can be avoided by using a concrete iterator (e.g., chaining char.aliases.iter() with char.spoiler_aliases.iter() or std::iter::empty() based on the flag) so the compiler can optimize it.

Copilot uses AI. Check for mistakes.
- Make HashSet mutable in alias/spoiler_alias merging so duplicates
  within `other` are properly caught during the loop
- Replace Box<dyn Iterator> with slice reference + chain for spoiler
  alias iteration, avoiding unnecessary heap allocation on hot path

https://claude.ai/code/session_01NRsURdxvKrse2dQTBW7LZ4
@bee-san bee-san merged commit f1e07b6 into main Mar 10, 2026
1 check failed
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.

3 participants