forked from ksqsf/rime-moran
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_simp_dist.sh
executable file
·103 lines (82 loc) · 2.56 KB
/
make_simp_dist.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
set -e
set -x
BUILD_TYPE="$1"
rm -rf dist/
git archive HEAD -o archive.tar
mkdir -p dist
tar xf archive.tar -C dist
rm archive.tar
cd dist
# 更新单字字频
echo 更新单字字频...
cd tools
python3 schemagen.py --pinyin-table=./data/pinyin_simp.txt update-char-weight --rime-dict=../moran.chars.dict.yaml > ../moran.chars.dict.yaml.bak
mv ../moran.chars.dict.yaml{.bak,}
cd ..
# 替换辅助码
echo 替换辅助码...
compact_dicts=(
"moran.essay.dict.yaml"
"moran.tencent.dict.yaml"
"moran.moe.dict.yaml"
"moran.thuocl.dict.yaml"
"moran.computer.dict.yaml"
"moran.hanyu.dict.yaml"
"moran.words.dict.yaml"
)
simplifyDict() {
cp $1 $1.bak
opencc -c opencc/moran_t2s.json -i $1.bak -o $1
rm $1.bak
}
for dict in "${compact_dicts[@]}"; do
simplifyDict $dict
done
(cd tools/ && ./update_compact_dicts.sh)
darwin=false;
case "`uname`" in
Darwin*) darwin=true ;;
esac
sedi () {
case $(uname -s) in
*[Dd]arwin* | *BSD* ) sed -i '' "$@";;
*) sed -i "$@";;
esac
}
# 替換碼表
echo 替換碼表...
sedi 's/dictionary: moran_fixed/dictionary: moran_fixed_simp/' moran_fixed.schema.yaml
sedi 's/dictionary: moran_fixed/dictionary: moran_fixed_simp/' moran.schema.yaml
# 替换简体语法模型
echo 替换简体语法模型...
wget 'https://github.com/lotem/rime-octagram-data/raw/hans/zh-hans-t-essay-bgc.gram' -O zh-hans-t-essay-bgc.gram
wget 'https://github.com/lotem/rime-octagram-data/raw/hans/zh-hans-t-essay-bgw.gram' -O zh-hans-t-essay-bgw.gram
rm zh-hant-t-essay-bg{c,w}.gram
sedi 's/zh-hant-t-essay-bgw/zh-hans-t-essay-bgw/' moran.yaml
sedi 's/zh-hant-t-essay-bgc/zh-hans-t-essay-bgc/' moran.yaml
# 替换 simplification 为 traditionalization
for f in *.schema.yaml moran.yaml ; do
sedi 's/simplification/traditionalization/' $f
sedi 's/漢字, 汉字/汉字, 漢字/' $f
sedi 's/moran_t2s.json/s2t.json/' $f
done
# 替换 emoji 用字
simplifyDict opencc/moran_emoji.txt
sort -k 1,1 -u opencc/moran_emoji.txt > /tmp/moran_emoji.txt
mv /tmp/moran_emoji.txt opencc/moran_emoji.txt
cd ..
# 打包
echo 打包...
if [ x$BUILD_TYPE = x"github" ]; then
# GitHub Actions will take over the tarball creation.
rm -rf dist/tools dist/.git dist/.github dist/make_simp_dist.sh
exit 0
fi
rm -rf dist/tools
rm -rf dist/.git dist/.github dist/.gitignore
rm -rf dist/make_simp_dist.sh
cp 下载与安装说明.txt 更新纪要.txt dist
sedi 's/MORAN_VARIANT/简体/' dist/下载与安装说明.txt
7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on "MoranSimplified-$(date +%Y%m%d).7z" dist
rm -rf dist