| 1 | # OpenCC 配置範例 |
| 2 | |
| 3 | [English](README.md) |
| 4 | |
| 5 | 本目錄收錄供學習與自訂使用的配置範例。這些檔案不是 OpenCC 官方內建配置, |
| 6 | 也不會出現在 `opencc --help` 的內建配置列表中。 |
| 7 | |
| 8 | 使用時請明確傳入配置檔路徑,並用 `--path` 指向已編譯詞典檔所在目錄: |
| 9 | |
| 10 | ```sh |
| 11 | opencc -c examples/config/s2twp_taiwan_word.json --path /path/to/opencc/dictionary/ |
| 12 | ``` |
| 13 | |
| 14 | 若使用 Bazel 建置產物: |
| 15 | |
| 16 | ```sh |
| 17 | bazel-bin/src/tools/command_line \ |
| 18 | -c examples/config/s2twp_taiwan_word.json \ |
| 19 | --path bazel-bin/data/dictionary/ |
| 20 | ``` |
| 21 | |
| 22 | 這些範例以 `data/config/s2twp.json` 為基礎,並加入小型 inline dictionary, |
| 23 | 示範如何在不修改官方詞典檔的情況下加入本地覆寫規則。使用者可在此基礎上酌情修改, |
| 24 | 以適應自身轉換需求。 |
| 25 | |
| 26 | 詞組範例也將對應 inline 條目加入 `segmentation.dict`,並放在 |
| 27 | `STPhrases.ocd2` 之前。這樣更適合作為使用者自行修改的模板:若新增多字詞覆寫, |
| 28 | 分詞條目可避免來源詞組在進入轉換鏈之前被切開,導致後續規則無法命中。 |
| 29 | |
| 30 | 引號範例沒有修改 `segmentation`,因為它只轉換單字元標點符號。 |
| 31 | |
| 32 | 分詞位置示例: |
| 33 | |
| 34 | ```json |
| 35 | "segmentation": { |
| 36 | "type": "mmseg", |
| 37 | "dict": { |
| 38 | "type": "group", |
| 39 | "match_policy": "short_circuit", |
| 40 | "dicts": [ |
| 41 | { |
| 42 | "type": "inline", |
| 43 | "entries": { |
| 44 | "自訂來源詞組": "自訂來源詞組" |
| 45 | } |
| 46 | }, |
| 47 | { "type": "ocd2", "file": "STPhrases.ocd2" } |
| 48 | ] |
| 49 | } |
| 50 | } |
| 51 | ``` |
| 52 | |
| 53 | `match_policy: short_circuit`(省略時的預設行為)會在詞典組中找到第一個命中當前前綴的 |
| 54 | 詞典後短路停止,不再繼續查找後續詞典。當 inline dict 應優先生效、且不希望後面的詞典 |
| 55 | 覆寫其結果時,使用此策略。 |