Add add_compound_hyphens flag and compound support to case lookups#24
Merged
Conversation
Add an `add_compound_hyphens` Bin() option (default True). When set to
False, the hyphens that the compounding algorithm inserts at the
boundaries it discovers ('síamskattar-kjóll') are suppressed, yielding
the bare concatenated form ('síamskattarkjóll'). Only these synthetic
boundaries are affected; hyphens that are part of the queried word, or
that occur in BÍN itself (e.g. 'Vestur-Þýskaland'), are always preserved.
get_compound() ignores the flag and always exposes the structure, since
that is its sole purpose.
Extend the compounding algorithm to lookup_nominative/accusative/dative/
genitive and lookup_forms, which previously bypassed it: a word that is
not present in BÍN as a whole is now resolved by casting its head and
re-prefixing the result, consistent with lookup(). Compounding is skipped
when a bin_id is supplied (a constructed compound has none of its own), or
when the word does occur in BÍN but is excluded by the cat/lemma/case
constraints. As a side effect this lets cast_to_*() cast user-hyphenated
compounds that are not in BÍN (e.g. 'Vestur-hestur' -> 'Vestur-hest').
Fix the lookup_cats()/lookup_lemmas_and_cats() documentation, which
incorrectly stated that an empty set is returned for compound words; both
functions have long resolved compounds via the algorithm.
Also sync uv.lock to the 1.3.0 version already set in pyproject.toml.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Three related changes to compound-word handling in the lookup API:
1.
add_compound_hyphensflag (the headline)A new
Bin()option (defaultTrue, so existing behavior is unchanged). When set toFalse, the hyphens the compounding algorithm inserts at the boundaries it discovers (síamskattar-kjóll) are suppressed, yielding the bare concatenated form (síamskattarkjóll).This addresses a recurring user complaint: callers had to strip these hyphens themselves, which was error-prone because they couldn't distinguish the inserted hyphens from legitimate ones. The flag suppresses only the synthetic boundaries; hyphens that are part of the queried word (e.g.
fjármála-ráðherra) or that occur in BÍN itself (e.g.Vestur-Þýskaland) are always preserved.get_compound()ignores the flag and always shows structure, since that is its sole purpose.2. Compound support in the case-lookup functions
lookup_nominative/accusative/dative/genitiveandlookup_formspreviously bypassed the compounding algorithm entirely (they hit the binary layer directly). They now resolve a word that is absent from BÍN by casting its head and re-prefixing, consistent withlookup(). Compounding is skipped when abin_idis supplied, or when the word is in BÍN but excluded by thecat/lemma/caseconstraints (so deliberate empty results are not second-guessed).As a side effect,
cast_to_*()now also casts user-hyphenated compounds that are not in BÍN (e.g.Vestur-hestur→Vestur-hest); this is pinned by a test.3. Documentation fix
The
lookup_cats()/lookup_lemmas_and_cats()docs incorrectly claimed an empty set is returned for compound words; both have long resolved them. Corrected.Testing
uv run pytest— 21 passed (addedtest_no_compound_hyphens,test_compound_case_lookups, and casting assertions intest_casting).uv run pyright— 0 errors.ruff check src/islenska— clean.🤖 Generated with Claude Code