| 1 | # Example OpenCC Configurations |
| 2 | |
| 3 | [繁體中文](README.zh.md) |
| 4 | |
| 5 | This directory contains example configurations for learning and customization. |
| 6 | They are not official built-in OpenCC configurations and are not listed by |
| 7 | `opencc --help`. |
| 8 | |
| 9 | Use them by passing the file path explicitly and pointing `--path` to the |
| 10 | directory that contains the compiled dictionary files: |
| 11 | |
| 12 | ```sh |
| 13 | opencc -c examples/config/s2twp_taiwan_word.json --path /path/to/opencc/dictionary/ |
| 14 | ``` |
| 15 | |
| 16 | When using Bazel build artifacts: |
| 17 | |
| 18 | ```sh |
| 19 | bazel-bin/src/tools/command_line \ |
| 20 | -c examples/config/s2twp_taiwan_word.json \ |
| 21 | --path bazel-bin/data/dictionary/ |
| 22 | ``` |
| 23 | |
| 24 | The examples are based on `data/config/s2twp.json` and add small inline |
| 25 | dictionaries to show how local overrides work without editing the official |
| 26 | dictionary files. You can modify these examples as needed to fit your own |
| 27 | conversion requirements. |
| 28 | |
| 29 | The phrase example also adds the corresponding inline entries to |
| 30 | `segmentation.dict` before `STPhrases.ocd2`. This makes it safer to adapt: when |
| 31 | you add your own multi-character phrase override, the segmentation entry keeps |
| 32 | the source phrase from being split before the conversion stages can match it. |
| 33 | |
| 34 | The quote-mark example does not modify `segmentation`, because it only converts |
| 35 | single-character punctuation marks. |
| 36 | |
| 37 | Segmentation placement: |
| 38 | |
| 39 | ```json |
| 40 | "segmentation": { |
| 41 | "type": "mmseg", |
| 42 | "dict": { |
| 43 | "type": "group", |
| 44 | "match_policy": "short_circuit", |
| 45 | "dicts": [ |
| 46 | { |
| 47 | "type": "inline", |
| 48 | "entries": { |
| 49 | "custom source phrase": "custom source phrase" |
| 50 | } |
| 51 | }, |
| 52 | { "type": "ocd2", "file": "STPhrases.ocd2" } |
| 53 | ] |
| 54 | } |
| 55 | } |
| 56 | ``` |
| 57 | |
| 58 | `match_policy: short_circuit` (the default when the field is absent) stops at |
| 59 | the first dictionary in the group that has a match for the current prefix. Use |
| 60 | it when your inline dict should take priority and you do not want later |
| 61 | dictionaries to override it. |