An open library for flexible simplified-traditional Chinese text conversion.
Project description
STS 簡繁祕書
STS (Simplified-Traditional Secretary) is an open library for flexible simplified-traditional Chinese text conversion.
簡繁祕書是開源、輕巧、有彈性的中文簡繁轉換工具,也支援異體字轉換及地區慣用詞轉換。
Features 特色
- 使用與 OpenCC 格式相容的詞典檔。
- 可「並聯」或「串聯」組合多個詞典檔作為轉換方案,並預先儲存成單一詞典檔以加速載入。詞典檔更新時也會自動重新生成組合詞典。
- 簡繁對應、異體字對應、地區慣用詞對應等不同的對應關係皆區分至不同的詞典檔。
- 詞典及配置檔與程式本體分離,可自由修改、擴充。
- 支援一對多轉換,轉換結果可輸出為純文字、HTML、JSON 等格式。
- 支援 Unicode 組合字,例如「⿰虫鬼」視為一個字,不會因為詞典有「虫=>蟲」而被轉為「⿰蟲鬼」。
- 支援用正規表示式略過特定文字的轉換。
- 支援編碼轉換,可自訂輸入及輸出檔案的字元編碼。
Usage 使用
Installation 安裝
pip install -U sts-lib
Command Line
-
sts --help或sts COMMAND --help檢視可用指令的詳細說明文檔。 -
sts convert [OPTIONs] [file [file ...]]執行簡繁轉換:file為一或多個欲轉換的檔案。(省略則讀取標準輸入 STDIN)-c CONFIG指定配置檔,可為內建配置檔名稱或自製 JSON 配置檔的路徑。可用的內建配置檔詳見 sts/data/config 目錄,可簡寫,例如輸入s2t代表使用sts/data/config/s2t.json。-f FORMAT指定輸出格式,可用格式如下:txt:純文字,適合一般使用。txtm:純文字加轉換標示。html:加上 HTML 標記的文本,可嵌入至網頁應用程式做互動式校對。htmlpage:加入 HTML 樣式的網頁,可直接開啟做互動式校對。json:以 JSON 格式表示轉換輸出,可用其他程式進一步解析處理。
--exclude PATTERN指定用於忽略簡繁轉換的正規表示式。有指定return子群組時會取代為子群組的值。- 例如
sts convert -c s2twp --exclude "「.*?」"會把「程序」正义轉換為「程序」正義。 - 例如
sts convert -c s2twp --exclude "-{(?P<return>.*?)}-"會把-{程序}-正义轉換為程序正義。
- 例如
--in-enc ENCODING指定輸入編碼。可用編碼參見這裡。--out-enc ENCODING指定輸出編碼。可用編碼參見這裡。-o OUTPUT指定對應輸入檔案轉換結果的輸出路徑。(無對應者輸出至原處)--stdout將所有轉換結果輸出至標準輸出 STDOUT。
Python
from sts import StsListMaker, StsConverter
# generate a dictionary file from a config and get its path
dictfile = StsListMaker().make('s2t', quiet=True)
# initialize the converter from the dictionary file
converter = StsConverter(dictfile, options={})
# perform conversion for a text
converter.convert_text('汉字') # 漢字
# perform conversion for a file (None for stdin/stdout)
converter.convert_file(input=None, output=None)
# process converted data stream
[p for p in converter.convert("汉字")] # [StsDictConv(key=['汉'], values=['漢']), '字']
License 許可協議
本專案以 Apache License 2.0 協議授權使用。
詞典檔原始資料來自同文堂、維基百科、OpenCC 等開源專案,再按本專案之需求編校。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sts-lib-0.18.3.tar.gz.
File metadata
- Download URL: sts-lib-0.18.3.tar.gz
- Upload date:
- Size: 500.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bf3bc77c1f8fa8fced4634b73f73e0bca48465b0c6bb54cd05ec3fcf6c3b5f1
|
|
| MD5 |
d9823444fca161bd0203c0ab12427018
|
|
| BLAKE2b-256 |
cb17d403377650512b1349b60b1c9aa349f8a0cc00b3dbaa318352cbc48ddf90
|
File details
Details for the file sts_lib-0.18.3-py3-none-any.whl.
File metadata
- Download URL: sts_lib-0.18.3-py3-none-any.whl
- Upload date:
- Size: 505.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b515ab7af86280eccf7b02db7e5de96209d5b1c5d27e16cc9c2f2a39f8c6d9e2
|
|
| MD5 |
4197ed7eafaa9124b88a4c45b545966f
|
|
| BLAKE2b-256 |
634701d07a69aefd05c4f46596c5f5626bab161f568da4e5d6cc83d6d22aa182
|