普贤教程 › 包参考
inflect 包
英文词形变化(复数化)
| 项 | 值 |
|---|---|
| 包名 | inflect |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | inflect.px |
| 分类 | 文本与中文处理 |
| 文件数 / 行数 | 1 / 192 |
安装与引入
bash
pxpkg init # 首次 pxpkg add inflect@0.2.0 pxpkg install
px
import inflect所属分类教程:文本与中文处理
公开接口
| 函数 | 参数 |
|---|---|
if_plural | s |
if_singular | s |
if_count | n, s |
其余 6 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
if_is_vowel | c |
if_irregular_table | |
if_ordinal | n |
if_article | s |
if_pluralize | s |
if_singularize | s |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/inflect —— 英文词形变化(复数化) ------------------------------------------------------------ 纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。 if_plural(s) → Ok(str) | Err 单数 → 复数 if_singular(s) → Ok(str) | Err 复数 → 单数(常用规则子集) if_count(n, s) → str 带数量:"1 apple" / "3 apples" - 不规则词表:man/men, child/children, foot/feet, tooth/teeth, goose/geese, mouse/mice, person/people, ox/oxen, sheep/sheep… - s/x/z/ch/sh 结尾 → +es(box→boxes, church→churches, bus→buses) - 辅音+y → ies(city→cities);元音+y → +s(boy→boys) - 常见 f/fe 结尾 → ves(wolf→wolves, knife→knives) - 其余 → +s ============================================================