opencc SQL 参考手册
opencc v0.1.0(内置 OpenCC 1.4.2)完整 SQL 接口速查:全部 16 套内置配置、转换与诊断函数、系统视图及 opencc.preload 参数。
所有函数与视图均位于固定模式 opencc 下。转换、检测与诊断函数在同一版本内为 IMMUTABLE 且 PARALLEL SAFE,要求数据库编码为 UTF8。
内置配置一览
转换函数
opencc.convert(input text, config text)
, text
, default—- 使用上述 16 套内置配置之一转换文本。
opencc.localize(input text, target text, source text)
, text
, defaultsource = 'auto'- 在
zh-Hans、zh-Hant、zh-CN、zh-TW、zh-HK 与 ja 之间路由转换。需做地区词汇转换时显式指定 source。 opencc.<配置名>(input text)
, text
, default—- 16 套配置的快捷封装(
s2t、t2s、s2tw、tw2s、s2twp、tw2sp、s2hk、hk2s、s2hkp、hk2sp、t2tw、tw2t、t2hk、hk2t、t2jp、jp2t),等价于 opencc.convert(input, '<配置名>')。
字形检测与歧义诊断
opencc.detect(input text)
, text
, default—- 启发式判断文本字形:
none、neutral、simplified、traditional、mixed 或 japanese。 opencc.script_stats(input text)
, record
, default—- 返回
(han integer, simplified integer, traditional integer, kana integer) 各类字符数。 opencc.explain(input text, config text)
, table
, default—- 返回
(seq integer, source text, steps text[], output text),展示每段输入在各转换阶段的中间输出。 opencc.ambiguities(input text, config text)
, table
, default—- 返回
(pos integer, len integer, source text, output text, candidates text[]),定位一简对多繁歧义片段。 opencc.candidates(word text, config text)
, text[]
, default—- 返回词条在指定配置下的全部候选结果(默认项排首位;词典未收录时返回
{})。
系统视图与运维函数
opencc.configs
, 视图
, default—- 列出全部 16 套内置配置(
name、source、target、phrases、maturity、description、loaded),loaded 反映当前后端加载状态。 opencc.routes
, 视图
, default—- 列出
localize() 支持的全部 36 条地区路由(source、target、chain、maturity)。 opencc.version()
, record
, default—STABLE。返回 (extension text, opencc text, dictionary text),含内置词典 SHA-256 摘要。opencc.dependents()
, table
, default—STABLE。返回 (kind text, object text, uses text, action text),列出直接依赖的物化对象及重建 SQL。
配置参数(GUC)
opencc.preload
, string
, default''- 逗号分隔的预加载配置名列表(或
'all')。与 shared_preload_libraries = 'opencc' 配合并在重启后生效,使各后端共享只读词典内存页。
SELECT name, loaded FROM opencc.configs ORDER BY name;