px普贤教程PuXian
普贤教程 › 包参考

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_plurals
if_singulars
if_countn, s
其余 6 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
if_is_vowelc
if_irregular_table
if_ordinaln
if_articles
if_pluralizes
if_singularizes

包内说明(源码头注释)

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
============================================================