Skip to content

fix: improve headword reconciliation for pinyin variants#7

Open
tofutim wants to merge 1 commit into
developfrom
feature/issue-6-investigate-bad-definition-for
Open

fix: improve headword reconciliation for pinyin variants#7
tofutim wants to merge 1 commit into
developfrom
feature/issue-6-investigate-bad-definition-for

Conversation

@tofutim

@tofutim tofutim commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Investigates and fixes the bad definition for 動態助詞 reported in #6.

Root cause: The dictionary had two separate entries for 動態助詞 — one from CC-CEDICT (dong4 tai4 zhu4 ci2, character-level pinyin) and one from Wiktextract (dongtai4 zhuci2, word-level pinyin). The reconcile_headwords function only handled u:/ü normalization, not spacing or tone-number formatting differences.

Findings:

  • 29,972 duplicate headword pairs in dictmaster.db (same traditional+simplified, different pinyin formatting)
  • 12,472 Arabic MiniMax translations contain Latin characters (e.g. جسيمAspect — Arabic+English concatenated)
  • Other bad MiniMax translations: Vietnamese trạng từ (means "adverb", not "aspect particle"), truncated Thai, garbled Farsi

Changes:

  • New _pinyin_merge_key() normalizes spaces, hyphens, tone numbers, and u:/ü to produce a canonical merge key
  • Rewritten reconcile_headwords() uses merge-key grouping (handles >2 variants per headword, also merges dialect_forms)
  • New find_bad_translations() detects Latin-character contamination in non-Latin script languages
  • 10 new tests covering spacing variants, hyphens, tone merging, case preservation

Test plan

  • All 37 merge tests pass (10 new)
  • All 193 dictmaster tests pass
  • No regressions in non-FTS tests (223 passed)
  • Run reconcile_headwords on production dictmaster.db to verify duplicate reduction
  • Run find_bad_translations to get full count of flagged entries for future cleanup

Closes #6

🤖 Generated with Claude Code

The reconciliation logic only handled u:/ü normalization, missing the
much larger class of duplicates caused by different pinyin formatting
between sources (CC-CEDICT char-level "dong4 tai4 zhu4 ci2" vs
Wiktextract word-level "dongtai4 zhuci2"). This caused 動態助詞 and
~29K other entries to appear as duplicates with separate definitions.

Changes:
- Add _pinyin_merge_key() that strips spaces, hyphens, tone numbers,
  and parenthesized annotations to produce a canonical merge key
- Rewrite reconcile_headwords() to use merge-key grouping instead of
  pairwise SQL comparison (handles >2 variants per headword)
- Also merge dialect_forms when consolidating headwords
- Add find_bad_translations() to detect MiniMax quality issues
  (Latin characters in non-Latin script languages like Arabic)
- Add 10 new tests covering spacing variants, hyphens, tone merging,
  case preservation, and the _pinyin_merge_key function

Closes #6

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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