跳转到主要内容

opencc

基于 OpenCC 的简繁中文、地区用语与日文新字体转换

pg_opencc · 基于 OpenCC 的简繁中文、地区用语与日文新字体转换

概览

ID扩展软件包版本类别许可证编程语言
4480openccpg_opencc0.1.0UTILApache-2.0C++
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-dt-否是否是否是
关联
模式opencc
UTF8; bundled OpenCC 1.4.2.

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.1.019 18 17 16 15pg_opencc-
RPMPIGSTY0.1.019 18 17 16 15pg_opencc_$v-
DEBPIGSTY0.1.019 18 17 16 15postgresql-$v-opencc-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el8.aarch64N/APIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el9.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el9.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el10.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el10.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d12.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d12.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d13.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d13.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u22.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u22.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u24.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u24.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u26.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u26.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
软件包版本平台仓库大小下载
pg_opencc_190.1.0el9.x86_64pigsty798.8 KiBpg_opencc_19-0.1.0-1PGSTY.el9.x86_64.rpm
pg_opencc_190.1.0el9.aarch64pigsty781.2 KiBpg_opencc_19-0.1.0-1PGSTY.el9.aarch64.rpm
pg_opencc_190.1.0el10.x86_64pigsty812.8 KiBpg_opencc_19-0.1.0-1PGSTY.el10.x86_64.rpm
pg_opencc_190.1.0el10.aarch64pigsty790.0 KiBpg_opencc_19-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-19-opencc0.1.0d12.x86_64pigsty783.6 KiBpostgresql-19-opencc_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-19-opencc0.1.0d12.aarch64pigsty748.8 KiBpostgresql-19-opencc_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-19-opencc0.1.0d13.x86_64pigsty802.5 KiBpostgresql-19-opencc_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-19-opencc0.1.0d13.aarch64pigsty763.5 KiBpostgresql-19-opencc_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-19-opencc0.1.0u22.x86_64pigsty774.5 KiBpostgresql-19-opencc_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-19-opencc0.1.0u22.aarch64pigsty764.2 KiBpostgresql-19-opencc_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-19-opencc0.1.0u24.x86_64pigsty763.0 KiBpostgresql-19-opencc_0.1.0-1PGSTY~noble_amd64.deb
postgresql-19-opencc0.1.0u24.aarch64pigsty752.6 KiBpostgresql-19-opencc_0.1.0-1PGSTY~noble_arm64.deb
postgresql-19-opencc0.1.0u26.x86_64pigsty769.8 KiBpostgresql-19-opencc_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-19-opencc0.1.0u26.aarch64pigsty761.9 KiBpostgresql-19-opencc_0.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_opencc_180.1.0el8.x86_64pigsty890.4 KiBpg_opencc_18-0.1.0-1PGSTY.el8.x86_64.rpm
pg_opencc_180.1.0el8.aarch64pigsty850.7 KiBpg_opencc_18-0.1.0-1PGSTY.el8.aarch64.rpm
pg_opencc_180.1.0el9.x86_64pigsty798.7 KiBpg_opencc_18-0.1.0-1PGSTY.el9.x86_64.rpm
pg_opencc_180.1.0el9.aarch64pigsty781.0 KiBpg_opencc_18-0.1.0-1PGSTY.el9.aarch64.rpm
pg_opencc_180.1.0el10.x86_64pigsty813.0 KiBpg_opencc_18-0.1.0-1PGSTY.el10.x86_64.rpm
pg_opencc_180.1.0el10.aarch64pigsty790.5 KiBpg_opencc_18-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-18-opencc0.1.0d12.x86_64pigsty783.9 KiBpostgresql-18-opencc_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-18-opencc0.1.0d12.aarch64pigsty749.6 KiBpostgresql-18-opencc_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-18-opencc0.1.0d13.x86_64pigsty802.6 KiBpostgresql-18-opencc_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-18-opencc0.1.0d13.aarch64pigsty764.2 KiBpostgresql-18-opencc_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-18-opencc0.1.0u22.x86_64pigsty774.9 KiBpostgresql-18-opencc_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-18-opencc0.1.0u22.aarch64pigsty764.1 KiBpostgresql-18-opencc_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-18-opencc0.1.0u24.x86_64pigsty764.0 KiBpostgresql-18-opencc_0.1.0-1PGSTY~noble_amd64.deb
postgresql-18-opencc0.1.0u24.aarch64pigsty753.6 KiBpostgresql-18-opencc_0.1.0-1PGSTY~noble_arm64.deb
postgresql-18-opencc0.1.0u26.x86_64pigsty770.2 KiBpostgresql-18-opencc_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-18-opencc0.1.0u26.aarch64pigsty761.9 KiBpostgresql-18-opencc_0.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_opencc_170.1.0el8.x86_64pigsty890.4 KiBpg_opencc_17-0.1.0-1PGSTY.el8.x86_64.rpm
pg_opencc_170.1.0el8.aarch64pigsty850.8 KiBpg_opencc_17-0.1.0-1PGSTY.el8.aarch64.rpm
pg_opencc_170.1.0el9.x86_64pigsty798.7 KiBpg_opencc_17-0.1.0-1PGSTY.el9.x86_64.rpm
pg_opencc_170.1.0el9.aarch64pigsty780.9 KiBpg_opencc_17-0.1.0-1PGSTY.el9.aarch64.rpm
pg_opencc_170.1.0el10.x86_64pigsty813.0 KiBpg_opencc_17-0.1.0-1PGSTY.el10.x86_64.rpm
pg_opencc_170.1.0el10.aarch64pigsty790.3 KiBpg_opencc_17-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-17-opencc0.1.0d12.x86_64pigsty784.2 KiBpostgresql-17-opencc_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-17-opencc0.1.0d12.aarch64pigsty749.3 KiBpostgresql-17-opencc_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-17-opencc0.1.0d13.x86_64pigsty802.8 KiBpostgresql-17-opencc_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-17-opencc0.1.0d13.aarch64pigsty764.3 KiBpostgresql-17-opencc_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-17-opencc0.1.0u22.x86_64pigsty778.5 KiBpostgresql-17-opencc_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-17-opencc0.1.0u22.aarch64pigsty767.6 KiBpostgresql-17-opencc_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-17-opencc0.1.0u24.x86_64pigsty764.1 KiBpostgresql-17-opencc_0.1.0-1PGSTY~noble_amd64.deb
postgresql-17-opencc0.1.0u24.aarch64pigsty754.1 KiBpostgresql-17-opencc_0.1.0-1PGSTY~noble_arm64.deb
postgresql-17-opencc0.1.0u26.x86_64pigsty770.1 KiBpostgresql-17-opencc_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-17-opencc0.1.0u26.aarch64pigsty762.1 KiBpostgresql-17-opencc_0.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_opencc_160.1.0el8.x86_64pigsty890.3 KiBpg_opencc_16-0.1.0-1PGSTY.el8.x86_64.rpm
pg_opencc_160.1.0el8.aarch64pigsty850.7 KiBpg_opencc_16-0.1.0-1PGSTY.el8.aarch64.rpm
pg_opencc_160.1.0el9.x86_64pigsty798.7 KiBpg_opencc_16-0.1.0-1PGSTY.el9.x86_64.rpm
pg_opencc_160.1.0el9.aarch64pigsty781.0 KiBpg_opencc_16-0.1.0-1PGSTY.el9.aarch64.rpm
pg_opencc_160.1.0el10.x86_64pigsty813.1 KiBpg_opencc_16-0.1.0-1PGSTY.el10.x86_64.rpm
pg_opencc_160.1.0el10.aarch64pigsty790.4 KiBpg_opencc_16-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-16-opencc0.1.0d12.x86_64pigsty783.9 KiBpostgresql-16-opencc_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-16-opencc0.1.0d12.aarch64pigsty749.2 KiBpostgresql-16-opencc_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-16-opencc0.1.0d13.x86_64pigsty802.8 KiBpostgresql-16-opencc_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-16-opencc0.1.0d13.aarch64pigsty764.1 KiBpostgresql-16-opencc_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-16-opencc0.1.0u22.x86_64pigsty778.5 KiBpostgresql-16-opencc_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-16-opencc0.1.0u22.aarch64pigsty767.5 KiBpostgresql-16-opencc_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-16-opencc0.1.0u24.x86_64pigsty764.1 KiBpostgresql-16-opencc_0.1.0-1PGSTY~noble_amd64.deb
postgresql-16-opencc0.1.0u24.aarch64pigsty754.2 KiBpostgresql-16-opencc_0.1.0-1PGSTY~noble_arm64.deb
postgresql-16-opencc0.1.0u26.x86_64pigsty770.0 KiBpostgresql-16-opencc_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-16-opencc0.1.0u26.aarch64pigsty762.1 KiBpostgresql-16-opencc_0.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_opencc_150.1.0el8.x86_64pigsty890.5 KiBpg_opencc_15-0.1.0-1PGSTY.el8.x86_64.rpm
pg_opencc_150.1.0el8.aarch64pigsty850.5 KiBpg_opencc_15-0.1.0-1PGSTY.el8.aarch64.rpm
pg_opencc_150.1.0el9.x86_64pigsty798.8 KiBpg_opencc_15-0.1.0-1PGSTY.el9.x86_64.rpm
pg_opencc_150.1.0el9.aarch64pigsty780.9 KiBpg_opencc_15-0.1.0-1PGSTY.el9.aarch64.rpm
pg_opencc_150.1.0el10.x86_64pigsty813.2 KiBpg_opencc_15-0.1.0-1PGSTY.el10.x86_64.rpm
pg_opencc_150.1.0el10.aarch64pigsty790.5 KiBpg_opencc_15-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-15-opencc0.1.0d12.x86_64pigsty783.8 KiBpostgresql-15-opencc_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-15-opencc0.1.0d12.aarch64pigsty749.5 KiBpostgresql-15-opencc_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-15-opencc0.1.0d13.x86_64pigsty802.7 KiBpostgresql-15-opencc_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-15-opencc0.1.0d13.aarch64pigsty764.2 KiBpostgresql-15-opencc_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-15-opencc0.1.0u22.x86_64pigsty778.4 KiBpostgresql-15-opencc_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-15-opencc0.1.0u22.aarch64pigsty767.5 KiBpostgresql-15-opencc_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-15-opencc0.1.0u24.x86_64pigsty764.1 KiBpostgresql-15-opencc_0.1.0-1PGSTY~noble_amd64.deb
postgresql-15-opencc0.1.0u24.aarch64pigsty754.1 KiBpostgresql-15-opencc_0.1.0-1PGSTY~noble_arm64.deb
postgresql-15-opencc0.1.0u26.x86_64pigsty770.1 KiBpostgresql-15-opencc_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-15-opencc0.1.0u26.aarch64pigsty762.2 KiBpostgresql-15-opencc_0.1.0-1PGSTY~resolute_arm64.deb

源码

pig build pkg pg_opencc;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

pig repo add pgsql -u   # add both repo and update cache

使用 pig 安装扩展。

pig install pg_opencc;		# install by package name
pig install opencc;		# install by extension name

pig install opencc -v 19;   # install for PG 19
pig install opencc -v 18;   # install for PG 18
pig install opencc -v 17;   # install for PG 17
pig install opencc -v 16;   # install for PG 16
pig install opencc -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION opencc;

用法

来源:

opencc 由 pg_opencc 项目提供,用于简体中文、繁体中文、台湾与香港用语以及日文新字体之间的转换。0.1.0 版本将 OpenCC 1.4.2 及其词典嵌入共享库,运行时无需系统 OpenCC 或外部词典文件。

启用与转换

支持 PostgreSQL 14–18,要求数据库使用 UTF8 编码。这是受信任扩展,拥有数据库 CREATE 权限的用户即可安装。对象位于固定的 opencc 模式中,扩展不可迁移模式。基本使用无需预加载或重启服务器。

CREATE EXTENSION opencc;

SELECT opencc.s2twp('鼠标里面的硅二极管坏了,导致光标分辨率降低。');
SELECT opencc.convert('繁體中文', 't2s');
SELECT * FROM opencc.configs;

opencc.convert(input, config) 用于明确指定转换配置。opencc.s2t()、opencc.t2s() 等快捷函数与各个配置一一对应:

配置转换用途
s2t, t2s简体中文与繁体中文互转
s2tw, tw2s, s2hk, hk2s台湾或香港字形转换
s2twp, tw2sp台湾地区词汇转换
s2hkp, hk2sp香港地区词汇转换,仍在完善中
t2tw, tw2t, t2hk, hk2t繁体中文不同地区字形互转
t2jp, jp2t日文旧字体与新字体互转,实验性功能

地区转换与结果检查

opencc.localize(input, target, source) 接受 zh-Hans、zh-Hant、zh-CN、zh-TW、zh-HK 和 ja。默认的 source => 'auto' 可以判断文字类别,但无法区分台湾和香港词汇。需要准确转换地区用语时,应明确指定来源地区。

SELECT opencc.localize('滑鼠裡面的矽二極體壞了', 'zh-CN', source => 'zh-TW');
SELECT opencc.detect('中文'), opencc.script_stats('中文');
SELECT * FROM opencc.routes;
SELECT * FROM opencc.ambiguities('大战文丑的时候,他的头发很干燥', 's2t');
SELECT opencc.candidates('发', 's2t');
SELECT * FROM opencc.explain('数据库连接池', 's2twp');
对象用途
opencc.detect()判断文字类别,包括混合文字与无法区分简繁的文字
opencc.script_stats()统计汉字、简体字、繁体字和假名
opencc.configs, opencc.routes检查配置与地区转换链
opencc.ambiguities(), opencc.candidates()检查歧义片段和词典候选项
opencc.explain()检查各阶段的转换结果
opencc.version()返回扩展版本、引擎版本和词典摘要
opencc.dependents()查找依赖对象并给出建议的重建语句

运行与升级

转换函数在同一扩展版本内具有 IMMUTABLE STRICT PARALLEL SAFE 属性,可用于表达式索引和存储生成列。PostgreSQL 18 的生成列若调用自定义转换函数,必须明确指定 STORED。

未来扩展版本更新词典时,转换结果可能变化。升级时应检查 opencc.version(),并审阅 opencc.dependents() 返回的语句。依赖检查无法发现封装在其他自定义函数中的调用。

SELECT * FROM opencc.version();
SELECT * FROM opencc.dependents();

每个后端按需初始化转换器。也可选择在服务器启动时预加载,使后端共享相关内存;修改 shared_preload_libraries 需要重启:

shared_preload_libraries = 'opencc'
opencc.preload = 's2t,t2s,s2twp,tw2sp'

若已有预加载列表,将 opencc 加入其中。opencc.preload 也接受 all。删除扩展后会保留空模式。

表格阅读器