# 基于有限状态转换器(FST)的新词典格式，支持正则，模糊搜索

**URL:** <https://forum.freemdict.com/t/topic/44435>\
**Category:** 软件经验交流展望\
**Tags:** 软件, 技术\
**Created:** [2026 年6 月 28 日 11:24 UTC](https://forum.freemdict.com/t/topic/44435 "2026-06-28T11:24:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mxdict](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/m/b9e5f3/32.png) [@mxdict](https://forum.freemdict.com/u/mxdict)\
**Post date:** [2026 年6 月 28 日 11:24 UTC](https://forum.freemdict.com/t/topic/44435/1 "2026-06-28T11:24:17Z")

</div>

词典引擎地址：[fstd](https://github.com/MouJieQin/fstd)  
自研了一款基于有限状态转换器（Finite State Transducer）作为索引的新词典格式，fstdx/fstdd，分别对应mdx/mdd。

支持正则搜索，和基于编辑距离的模糊搜索，当然也支持基于trie的传统词典的前缀搜索。  
下面效果图的图形界面并不包含在词典引擎项目中。

正则搜索效果：

 ![Screenshot 2026-06-28 at 18.39.22](https://forumcdn.freemdict.com/uploads/default/original/3X/4/6/469cc4fdab6776e1d899ad27996e40c8f6024426.jpeg)

模糊搜索效果：

 ![Screenshot 2026-06-28 at 18.47.01](https://forumcdn.freemdict.com/uploads/default/original/3X/e/f/ef78728684475746c00afb06ff5baae3736f4129.jpeg)

很多时候动词在使用中都会变形，我们划词或复制粘贴搜索的时候都找不到动词的原形。英语词典还好，对于查找变形后的单词能直接跳转到动词原形词条，但其它语言，至少日语和韩语，支持这个的词典很少。这也是我写这个词典引擎的动因之一。在日韩语中，动词和形容词原形的后缀是固定的，japanese (“する”, “う”, “く”, “ぐ”, “す”, “つ”, “ぬ”, “ぶ”, “む”, “る”, “い”) ， Korean (“하다”, “다”)。我写了一个自动机算法，通过公共前缀和优先后缀去排序候选词。当然，不是在所有的情况下都有最好的效果。

前缀距离+优先后缀搜索效果：

 ![Screenshot 2026-06-28 at 18.42.29](https://forumcdn.freemdict.com/uploads/default/original/3X/4/1/41153a656145666bf73f6ef43f438d150f5e9a01.jpeg)  
 ![Screenshot 2026-06-28 at 18.43.39](https://forumcdn.freemdict.com/uploads/default/original/3X/5/b/5b468b416aa3cacc91a88ec8b8866f62c91cd47b.jpeg)

至于后缀搜索，有正则表达式的".\*suffix"的完全等价形式，但因为这个未知前缀，正则表达式自动机无法提前剪枝，导致要遍历所有的状态和边，虽然我加了并行优化，但如果词头非常多也会比较慢。建议可以用".{0,5}suffix"这样的不完全等价形式进行搜索，性能会好很多。如果非要支持这个功能就需要把所有词头倒排后编译fst索引，性能和前缀搜索一样，但内存要翻倍。

项目从一开始就考虑了要支持从mdx/mdd转化成fstdx/fstdd。转换器：[fstdtools](https://github.com/MouJieQin/fstdtools)。整个转换过程没有落地文件。  
安装

```auto
pip install fstdtools

```

欢迎大家提提意见。

现在正在完善python接口。可以在python里直接 `import fstd`后调用search类方法开发词典app.有什么疑问欢迎评论区提问或在github提一个issue。  
安装

```auto
pip install fstd

```

目前已在Macos x86/arm， linux， windows上测试通过。

---

<div class="post-metadata">

**Author:** ![ujsqbj](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/u/cab0a1/32.png) [@ujsqbj](https://forum.freemdict.com/u/ujsqbj)\
**Post date:** [2026 年6 月 28 日 16:38 UTC](https://forum.freemdict.com/t/topic/44435/2 "2026-06-28T16:38:56Z")

</div>

感到这个很有新意，但到GitHub上一看，还要自己编译，门槛似乎有点高。

---

<div class="post-metadata">

**Author:** ![mxdict](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/m/b9e5f3/32.png) [@mxdict](https://forum.freemdict.com/u/mxdict)\
**Post date:** [2026 年6 月 29 日 01:40 UTC](https://forum.freemdict.com/t/topic/44435/3 "2026-06-29T01:40:10Z")

</div>

fstd作为一个词典引擎并不是面向普通词典app用户的，而是面向词典app开发者或词典文件制作者。我给出的效果图虽然使用了fstd引擎，但图形界面是另一个项目，我开发自用的。我也在正做跨平台fstd编译release。不过如果编译打包出可执行文件，也是命令行工具，没有图形界面。

---

<div class="post-metadata">

**Author:** ![mxdict](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/m/b9e5f3/32.png) [@mxdict](https://forum.freemdict.com/u/mxdict)\
**Post date:** [2026 年6 月 30 日 08:05 UTC](https://forum.freemdict.com/t/topic/44435/4 "2026-06-30T08:05:13Z")

</div>

现在可以直接下载release压缩包了，但还不支持windows。

---

<div class="post-metadata">

**Author:** ![ujsqbj](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/u/cab0a1/32.png) [@ujsqbj](https://forum.freemdict.com/u/ujsqbj)\
**Post date:** [2026 年7 月 1 日 04:48 UTC](https://forum.freemdict.com/t/topic/44435/5 "2026-07-01T04:48:23Z")

</div>

我是电脑小白，而且是Windows用户。对作者创新支持。从字典影响力来看，还是带图形界面的版本更有影响力。

---

<div class="post-metadata">

**Author:** ![mxdict](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/m/b9e5f3/32.png) [@mxdict](https://forum.freemdict.com/u/mxdict)\
**Post date:** [2026 年7 月 6 日 15:10 UTC](https://forum.freemdict.com/t/topic/44435/6 "2026-07-06T15:10:51Z")

</div>

现在已支持Macos，linux， windows平台。  
安装fstdtools制作词典，或从mdx/mdd无落地文件转化为fstdx/fstdd词典，三大平台都可直接使用pip安装。

```auto
pip install fstdtools

```

提供python接口制作词典app/网页

```auto
pip install fstd

```
