mirror of
https://github.com/Vonng/ddia.git
synced 2024-12-06 15:20:12 +08:00
add: using opencc project to transform chinese
This commit is contained in:
parent
96a6ef3ced
commit
334425a783
13
Pipfile
Normal file
13
Pipfile
Normal file
@ -0,0 +1,13 @@
|
||||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
opencc = "*"
|
||||
click = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.6"
|
36
Pipfile.lock
generated
Normal file
36
Pipfile.lock
generated
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "e11e067f853c70dd2660c4e3d606219472ef597161bcf00ffcd63872df1183bf"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.6"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"click": {
|
||||
"hashes": [
|
||||
"sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a",
|
||||
"sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==7.1.2"
|
||||
},
|
||||
"opencc": {
|
||||
"hashes": [
|
||||
"sha256:1e0d40581dd5130ac3160f97e752caff202aa22aa004d468496fa8cba81035e7"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.1.1.post1"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
21
transform.py
Normal file
21
transform.py
Normal file
@ -0,0 +1,21 @@
|
||||
"""Convert zh-cn to zh-tw
|
||||
Refer to https://github.com/BYVoid/OpenCC
|
||||
"""
|
||||
import click
|
||||
import opencc
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.option("-i", "--input", "infile", required=True)
|
||||
@click.option("-o", "--output", "outfile", required=True)
|
||||
@click.option("-c", "--config", "cfg", required=True, default="s2twp.json")
|
||||
def main(infile, outfile, cfg):
|
||||
converter = opencc.OpenCC(cfg)
|
||||
with open(infile, "r") as inf, open(outfile, "w+") as outf:
|
||||
data = inf.readlines()
|
||||
data = list(map(converter.convert, data))
|
||||
outf.writelines(data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user