fix: #2 — feat(foundation): reference resolver with EN + ZH support#12
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2.
Parses a free-form scripture reference into a canonical
Reference{Tradition, Work, Book?, Chapter, VerseStart, VerseEnd?}perplan.md§8.1.What's in this PR
internal/resolver/reference.go—Referencestruct, tradition/work constants,*AmbiguousError, sentinel errors (ErrEmpty,ErrUnrecognized,ErrInvalidNumber,ErrInvalidRange)internal/resolver/resolve.go—Resolve(input string) (Reference, error)entry point + per-tradition dispatch + atryMatchPrefixhelper 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 nameinternal/resolver/numerals.go— Chinese numeral parser for 1..999 (一,十,十一,二十,八十一,一百零一,一百二十三...)internal/resolver/resolve_test.go— 50+ positive, 17 negative, 3 ambiguous, 19 numeral casesAcceptance criteria mapping
John 3:16,Jn 3:16,1 John 3:16,约翰福音 3:16,约翰一书 3:16dao 11,daodejing chapter 11,道德经 11,道德经第十一章sutra heart,心经,般若波罗蜜多心经Quran 2:255,2:255,Surah Al-Baqarah 255Reference{Tradition, Work, Book?, Chapter, VerseStart, VerseEnd?}3:16returns*AmbiguousErrorwith candidates (Quran + Bible-shape)Design notes
"1 john"beats"john","约翰福音"beats"约".tryMatchPrefixis intentionally narrow: rejecting any letter would break CJK chains like"道德经第十一章"(CJK ideographs are letters by Unicode category). Longest-first sorting handles CJK ambiguity instead.fmt.Errorf("%w: ...", ...)so callers can useerrors.Is.*AmbiguousErroris returned as a typed error so callers can useerrors.As.Verification
go vet ./...cleanstaticcheck ./...cleango test ./...—internal/resolverandinternal/schemaboth PASSGenerated by Claude Code