使用Hunspell词缀规则生成排列组合

huangapple go评论86阅读模式
英文:

Generate Permutations using Hunspell affix rules

问题

在 hunspell affix 文件中,您可以按照以下方式定义一个新语言,其中任意顺序的 3 个字母都是有效的:

affix 文件:

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 .

这是一个假设只有 3 个字符(ABC)的示例,但它可以扩展到 A 到 Z。

词典文件:

a/BCbc
b/ACac
c/ABab

这是实现这种语言的一种方式,但是否有更好的方式取决于具体需求。这种方式基本上是通过定义前缀和后缀规则来支持所有可能的组合。如果有其他需求或者更复杂的规则,您可能需要调整 affix 文件中的规则。

英文:

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?

答案1

得分: 1

无法通过Hunspell的.aff文件来实现更简单的解决方案。当然,您可以生成用于此用例的.aff文件。

使用类似“languagetool”等其他工具,您有可能编写自己的RuleFilter(Java)。这应该可以更通用地实现,但可能比简单生成.aff文件更耗时。

英文:

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.

huangapple
  • 本文由 发表于 2023年2月8日 11:14:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75381065.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定