Search code examples
hunspell

Generate Permutations using Hunspell affix rules


let's assure there is a new language where a combination of 3 letters in any order are valid. For e.g. abc, acb, bac, bca, cba, bab all are valid. How do I write a hunspell affix file for this?

affix file:

PFX A Y 1
PFX A 0 a .

PFX B Y 1
PFX B 0 b .

PFX C Y 1
PFX C 0 c .

SFX a Y 1
SFX a 0 a .

SFX b Y 1
SFX b 0 b .

SFX c Y 1
SFX c 0 c .

This is just an example assuming there are only 3 characters (ABC) but it can be extended to A to Z.

Dict file:

a/BCbc
b/ACac
c/ABab

Is there any other better way to write this code or this is the only way to achieve this?


Update:

In the sample file given below how many words will be generated? Is there a default limit on nesting?

https://gist.github.com/shantanuo/fd7504a99411b20e915f59fc3b365a24


Solution

  • Is not possible via the .aff files from Hunspell to have a simpler solution. Of course you have the possibility to generate the .aff files for this use case.

    With other tools like "languagetool" you have the possibility to write your own RuleFilter (Java). This should make it possible to implement this more generically but would probably be even more time consuming than simply generating the .aff files.