(最初的问题是关于为一个给定单词生成所有形式。这个答案集中在为字典的所有单词生成所有形式的更难的问题上。我在这里发布这个,因为这是在搜索更难的单词时出现的问题问题。)
unmunching 更新
截至 2021 年,Hunspell 提供了两个工具,称为 unmunch 和 wordforms,用于生成单词形式。它们各自的用法是:
# print all forms for all words whose roots are given in `roots.dic`
# and make use of affix rules defined in `affixes.aff`:
unmunch roots.dic affixes.aff
# print the forms of ONE given word (a single root with no affix rule)
# which are allowed by the reference dictionary defined by the pair of
# `roots.dic` and `affixes.aff`:
wordforms affixes.aff roots.dic word
所以affixes.aff 将由您的语言给出,roots.dic 将是您的语言的参考词典,或者是包含您要生成的新词根的自定义词典。
很遗憾,Hunspell 的unmunch 已弃用¹,无法正常工作。它继承自 MySpell,我猜它不支持 Hunspell 的所有功能。显然它不能正确支持 UTF-8。当我尝试将它与参考法语词典(Dicollecte,v7.0)一起使用时,它通过应用不应该应用的词缀规则(例如:共轭非动词)来生成垃圾词。
wordforms 应该是最新的,所以您可能会尝试用wordforms 模拟unmunch(正如自述文件所建议的那样),但是后者只取一个不合格的根,并将其与roots.dic 和affixes.aff 隐含的整个字典进行比较。每个根需要花费大量时间,最糟糕的是,您必须依次调用wordforms,所有根都在roots.dic。所以你会有一个二次时间。对我来说,使用法语词缀的参考集,这太慢了以至于无法使用——即使只有 10 个词根!为了说明,不可用的 Bash 代码是:
# /!\ EXTREMELY SLOW
aff='affixes.aff'
dic='roots.dic'
cat "$dic" | while read -r root ; do # read each root of the file
root="${root%%/*}" # strip the root from the optional slash (attached affix rules)
wordforms "$aff" "$dic" "$root" # generate all forms for this root
done \
| sort -u # sort (according to the locale) and remove duplicates
另外,请注意wordforms 生成裸词,而unmunch 能够附加派生元数据(例如词性或性别),因此使用wordforms 您会丢失信息(可能会或可能不会对你很重要)。
unmunch 缺少替代品是a known issue。显然,Hunspell 开发人员不会在可预见的未来解决这个问题(关于资金的问题?)。这导致几个人重新实现了该功能,您会在整个 GitHub 问题中找到指针。
¹ 来自 the repo 的自述文件。