Skip to content

Add add_compound_hyphens flag and compound support to case lookups#24

Merged
vthorsteinsson merged 1 commit into
mainfrom
add-no-hyphen-flag
May 22, 2026
Merged

Add add_compound_hyphens flag and compound support to case lookups#24
vthorsteinsson merged 1 commit into
mainfrom
add-no-hyphen-flag

Conversation

@vthorsteinsson

Copy link
Copy Markdown
Member

Summary

Three related changes to compound-word handling in the lookup API:

1. add_compound_hyphens flag (the headline)

A new Bin() option (default True, so existing behavior is unchanged). When set to False, 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/genitive and lookup_forms previously 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 with lookup(). Compounding is skipped when a bin_id is supplied, or when the word is in BÍN but excluded by the cat/lemma/case constraints (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-hesturVestur-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 (added test_no_compound_hyphens, test_compound_case_lookups, and casting assertions in test_casting).
  • uv run pyright — 0 errors.
  • ruff check src/islenska — clean.

🤖 Generated with Claude Code

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>
@vthorsteinsson vthorsteinsson merged commit 62408bd into main May 22, 2026
8 checks passed
@vthorsteinsson vthorsteinsson deleted the add-no-hyphen-flag branch May 22, 2026 14:14
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