Skip to content

fix: #2 — feat(foundation): reference resolver with EN + ZH support#12

Merged
MiaoDX merged 1 commit into
mainfrom
claude-issue-2
May 1, 2026
Merged

fix: #2 — feat(foundation): reference resolver with EN + ZH support#12
MiaoDX merged 1 commit into
mainfrom
claude-issue-2

Conversation

@MiaoDX

@MiaoDX MiaoDX commented May 1, 2026

Copy link
Copy Markdown
Owner

Closes #2.

Parses a free-form scripture reference into a canonical Reference{Tradition, Work, Book?, Chapter, VerseStart, VerseEnd?} per plan.md §8.1.

What's in this PR

  • internal/resolver/reference.goReference struct, tradition/work constants, *AmbiguousError, sentinel errors (ErrEmpty, ErrUnrecognized, ErrInvalidNumber, ErrInvalidRange)
  • internal/resolver/resolve.goResolve(input string) (Reference, error) entry point + per-tradition dispatch + a tryMatchPrefix helper that uses an ASCII-letter boundary so "jo" won't beat "joel"
  • internal/resolver/bible.go — full 66-book alias table (English canonical + common abbreviations + Simplified Chinese)
  • internal/resolver/quran.go — ~12 popular surahs by name
  • internal/resolver/numerals.go — Chinese numeral parser for 1..999 (, , 十一, 二十, 八十一, 一百零一, 一百二十三 ...)
  • internal/resolver/resolve_test.go — 50+ positive, 17 negative, 3 ambiguous, 19 numeral cases

Acceptance criteria mapping

  • Parses Bible: John 3:16, Jn 3:16, 1 John 3:16, 约翰福音 3:16, 约翰一书 3:16
  • Parses Tao Te Ching: dao 11, daodejing chapter 11, 道德经 11, 道德经第十一章
  • Parses Heart Sutra: sutra heart, 心经, 般若波罗蜜多心经
  • Parses Quran: Quran 2:255, 2:255, Surah Al-Baqarah 255
  • Returns canonical Reference{Tradition, Work, Book?, Chapter, VerseStart, VerseEnd?}
  • Ambiguous bare 3:16 returns *AmbiguousError with candidates (Quran + Bible-shape)
  • Table-driven tests with ≥ 50 inputs across all 4 traditions, both languages, plus negatives

Design notes

  • Per-tradition alias tables sorted by byte length descending so longer matches win — "1 john" beats "john", "约翰福音" beats "约".
  • The ASCII-letter boundary in tryMatchPrefix is intentionally narrow: rejecting any letter would break CJK chains like "道德经第十一章" (CJK ideographs are letters by Unicode category). Longest-first sorting handles CJK ambiguity instead.
  • Errors wrap the package sentinels with fmt.Errorf("%w: ...", ...) so callers can use errors.Is. *AmbiguousError is returned as a typed error so callers can use errors.As.

Verification

  • go vet ./... clean
  • staticcheck ./... clean
  • go test ./...internal/resolver and internal/schema both PASS

Generated by Claude Code

Resolves a free-form scripture reference into a canonical
Reference{Tradition, Work, Book, Chapter, VerseStart, VerseEnd?}.

Coverage per plan.md §8.1:
- Bible: 66-book alias table (English canonical + common abbreviations
  + Simplified Chinese), handles "John 3:16", "Jn 3:16", "1 John 3:16",
  "约翰福音 3:16", "约翰一书 3:16", ranges, full-width colon
- Tao Te Ching: "dao 11", "daodejing chapter 11", "道德经 11",
  "道德经第十一章" (Chinese numerals)
- Heart Sutra: "心经", "般若波罗蜜多心经", "Heart Sutra", "sutra heart"
- Quran: "Quran 2:255", "古兰经 2:255", "Surah Al-Baqarah 255"
  (~12 surahs by name)
- Bare "N:M" with no tradition keyword returns *AmbiguousError with
  candidates

Implementation notes:
- Per-tradition lookup tables sorted by alias byte-length DESC so
  longer matches win ("1 john" beats "john", "约翰福音" beats "约")
- ASCII letter boundary check prevents "jo" matching "joel"; CJK
  ambiguity is handled by the longest-first ordering instead
- Chinese numeral parser supports 1..999 (一, 十, 十一, 二十, 八十一,
  一百零一, 一百二十三 ...)
- Errors wrap sentinels (ErrEmpty, ErrUnrecognized, ErrInvalidNumber,
  ErrInvalidRange) so callers can errors.Is / errors.As

Tests: 50+ positive cases across 4 traditions and both languages,
17 negative cases, 3 ambiguous cases, 19 Chinese numeral cases.

Closes #2

https://claude.ai/code/session_017oFxiyRdiLLc32qfADHFav
@MiaoDX MiaoDX marked this pull request as ready for review May 1, 2026 13:28
@MiaoDX MiaoDX merged commit 6c1078a into main May 1, 2026
1 check passed
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.

feat(foundation): reference resolver with EN + ZH support

2 participants