Skip to content

fix(affixes): resolve destructive affix removal and protect root words (fixes #26) - #39

Open
AbdelrahmanBayoumi wants to merge 1 commit into
mainfrom
fix/issue-26-remove-arabic-affixes
Open

AbdelrahmanBayoumi wants to merge 1 commit into
mainfrom
fix/issue-26-remove-arabic-affixes

Conversation

@AbdelrahmanBayoumi

Copy link
Copy Markdown
Member

Summary of Changes

Fixes #26 - Resolves destructive affix removal in removeArabicAffixes and prevents word corruption.

1. Core Fixes in removeArabicAffixes:

  • Minimum Stem Length Constraint (minStemLength >= 3): Ensures root letters are never stripped (e.g. "بيت", "تفاح", "أمل", "نجم", "يوم", "ولد" now remain intact instead of being mutilated into "يت", "فاح", "مل", etc.).
  • Compound & Preposition Prefixes: Added support for common Arabic prefixes:
    • Compound: بالـ, كالـ, وللـ, فالـ, فللـ (e.g. بالكتاب -> كتاب, وللقدس -> قدس).
    • Definite: الـ, للـ (e.g. الكتاب -> كتاب, للمعلمين -> معلم).
    • Conjunction: و (e.g. وكتاب -> كتاب).
  • Safe Suffix Stripping: Cleanly strips standard suffixes (ون, ين, ات, هم, نا, ة, ه, ي, ية) while protecting singular words with root "ان" (such as "إنسان" and "قرآن").
  • Configurable Options: Exported AffixOptions interface allowing callers to configure minStemLength (default 3), prefixes (default true), and suffixes (default true).

2. Fixes in tashfeerBannedWords:

  • Fixed false negatives where banned words (like "فلسطين" and "بالقدس") failed to trigger encryption because similarity was checked only against the stripped form. Now checks both raw and stripped similarity.

Verification

  • npm test: 84/84 tests passed across 5 test suites (100% statement, branch, function, and line coverage on src/scripts/affixes.ts).
  • npm run lint: 0 errors, 0 warnings.
  • npm run build:cjs, npm run build:esm, npm run bundle: All builds and bundles generated cleanly.

Closes #26

fixes #26)

- enforce minStemLength (default: 3) to protect root consonants from being mangled
- add support for compound prefixes (بال, كال, ولل, فال, فلل) and conjunctions (و)
- add comprehensive suffix handling without stripping ambiguous dual endings
- export AffixOptions interface for fine-grained prefix/suffix/length control
- check both raw and stripped string in tashfeerBannedWords to fix false negatives (e.g. فلسطين, بالقدس)
- update tests and docs to verify non-destructive linguistic behavior

Closes #26
@AbdelrahmanBayoumi AbdelrahmanBayoumi self-assigned this Oct 18, 2026
@AbdelrahmanBayoumi AbdelrahmanBayoumi added the enhancement New feature or request label Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ميزة إزالة اللواحق العربية

1 participant