Skip to content

Commit

Permalink
fix: hunspell - honor minimum compound word length (#2091)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Dec 12, 2021
1 parent c3d1903 commit c67f7b8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/hunspell-reader/src/aff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export class Aff {
* @internal
*/
applyRulesToWord(affWord: AffWord, remainingDepth: number): AffWord[] {
const compoundMin = this.affInfo.COMPOUNDMIN ?? 3;
const { word, base, suffix, prefix, dic } = affWord;
const allRules = this.getMatchingRules(affWord.rules);
const { rulesApplied, flags } = allRules
Expand All @@ -268,6 +269,7 @@ export class Aff {
const wordWithFlags = { word, flags, rulesApplied, rules: '', base, suffix, prefix, dic };
return [wordWithFlags, ...this.applyAffixesToWord(affixRules, { ...wordWithFlags, rules }, remainingDepth)]
.filter(({ flags }) => !flags.isNeedAffix)
.map((affWord) => adjustCompounding(affWord, compoundMin))
.map((affWord) => logAffWord(affWord, 'applyRulesToWord'));
}

Expand Down Expand Up @@ -499,3 +501,13 @@ function removeNeedAffix(flags: AffWordFlags): AffWordFlags {
delete newFlags.isNeedAffix;
return newFlags;
}

function adjustCompounding(affWord: AffWord, minLength: number): AffWord {
if (!affWord.flags.isCompoundPermitted || affWord.word.length >= minLength) {
return affWord;
}

const { isCompoundPermitted, ...flags } = affWord.flags;
affWord.flags = flags;
return affWord;
}

0 comments on commit c67f7b8

Please sign in to comment.