# \[开源\] morph-query：英语词素/形态切分查询工具 (Python API / CLI)

**URL:** <https://forum.freemdict.com/t/topic/44283>\
**Category:** 软件经验交流展望\
**Tags:** 技术\
**Created:** [2026 年6 月 15 日 13:50 UTC](https://forum.freemdict.com/t/topic/44283 "2026-06-15T13:50:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![connor\_yang](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/c/a87d85/32.png) [@connor\_yang](https://forum.freemdict.com/u/connor_yang)\
**Post date:** [2026 年6 月 15 日 13:50 UTC](https://forum.freemdict.com/t/topic/44283/1 "2026-06-15T13:50:27Z")

</div>

在背单词或者进行语言学研究时，我们经常需要拆解单词的前缀、后缀、词根、派生词缀和屈折变化。虽然有诸如 UniMorph  
(umLabeller) 和 CityLex 这样优秀的公开形态学（Morphology）标注数据集，但它们通常以几十兆甚至上百兆的 raw TSV  
文本形式存在，直接检索和在代码中调用非常不便。

为了解决这个问题，我写了一个轻量级的本地查询工具 morph-query（已发布到 PyPI，代码在 GitHub  
开源）。它将这些数据集整理并索引化为一个 ~50MB 的高性能 SQLite 数据库，并提供了开箱即用的命令行工具（CLI）和 Python  
API。

• GitHub 仓库：[https://github.com/connoryang331/morph-query](https://github.com/connoryang331/morph-query)  
• PyPI 地址： `pip install morph-query`

──────

## 🚀 核心特性

1. 多维度词素查询：支持按前缀 (Prefix)、后缀 (Suffix)、词根 (Root)、派生后缀 (Derivational Suffix) 或屈折后缀  
(Inflectional Suffix) 检索单词。
2. 毫秒级响应：底层采用精心设计的 SQLite 关系表和多重索引，子查询及批量查询均在 1ms 内完成。
3. 极简安装：为了避免 PyPI 安装包过大，我们将 50MB 的数据库托管在 GitHub Release。用户在首次运行 mq 命令或初始化  
Python 实例时，程序会自动下载并解压至本地，无需手动配置。
4. 同时支持 CLI 和库调用：既可以在终端快速排查词素，也可以作为 Python 库集成到大家的词典制作脚本中。  
──────

## 💻 使用演示

### 1. 终端命令行 (CLI)

安装后直接在终端运行 mq 命令：

```
# 查询包含特定词根的单词
mq query --root dict

# 查询特定的形态切分 (如前缀、词根、后缀)
mq query --prefix con --root struct --suffix ion

```

输出样式类似下面这样（支持彩色高亮排版）：

```
Word: construction
----------------------------------------
Data Source: umLabeller
- Morpheme Division: con-struct-ion
- Prefix: con
- Root: struct
- Derivational Suffix: ion
- Inflectional Suffix: (none)

```

### 2. Python API 调用

```
from morph_query import MQ

mq = MQ()

# 批量查询单词的词素切分
results = mq.query_words(["construction", "deconstruct"])
for word, info in results.items():
    print(word, info)

```

---

<div class="post-metadata">

**Author:** ![xuhuaq](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/x/eada6e/32.png) [@xuhuaq](https://forum.freemdict.com/u/xuhuaq)\
**Post date:** [2026 年7 月 14 日 18:19 UTC](https://forum.freemdict.com/t/topic/44283/2 "2026-07-14T18:19:48Z")

</div>

大哥，你这有点坑人啊

```auto

程序：
Failed to download morph-query database from https://github.com/connoryang331/morph-query/releases/download/v0.1.0/morph_query.db.zip. Error: HTTP Error 404: Not Found
实际：
https://github.com/connoryang331/morphoneme/releases/download/v0.1.0/morphoneme.db.zip

程序：
Please ensure you have internet access, or download it manually and place it at C:\Users\Administrator\.morph_query\morph_query.db
REAME.MD
如果未找到，程序会检查 ~/.morphoneme/morphoneme.db 路径。
实际：
morphoneme.db.zip解压出来为morphoneme.db，而程序在找morph_query.db

帖子：
mq query --root dict
实际：
mq query --root dict
Unknown: query

..............

```
