Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test and incorporate char.tsv to improve syllable error rate #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*.dict.yaml
char.csv
build
dist
*.egg-info
.mypy_cache
tojyutping_wrong_sentences.txt
tojyutping_correct_sentences.txt
25 changes: 23 additions & 2 deletions preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
t2s = OpenCC('t2s').convert

os.system('wget -nc https://raw.githubusercontent.com/rime/rime-cantonese/5b6d334/jyut6ping3.dict.yaml')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much will the results be affected if we eliminate the downstream file and grab all files from upstream? Presuming we are going with this, let’s make upstream a submodule instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think submodule would be hard to maintain

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will? Isn’t a submodule just an SHA, as if we manually amend the link regularly in this file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Then it may not be a problem

os.system('wget -nc https://raw.githubusercontent.com/CanCLID/rime-cantonese-upstream/main/char.csv')

def freq_str_to_float(s):
'''Convert frequency data in the dictionary file to float.
Expand All @@ -19,7 +20,7 @@ def freq_str_to_float(s):

DEFAULT_FREQ = 0.07

def build_dict(d, filepath):
def build_yaml_dict(d, filepath):
'''Create a dictionary of all the words with jyutping data.
If there are multiple possibilities, the one with higher frequency is used.
'''
Expand Down Expand Up @@ -55,14 +56,34 @@ def build_dict(d, filepath):
if should_change:
d[字] = (粵拼, 詞頻)

import csv

def build_char_dict(d, filepath):
'''Create a dictionary of all the characters with jyutping data.
If there are multiple possibilities, the 預設 version is used.
'''
with open(filepath) as csvfile:
csvreader = csv.reader(csvfile, delimiter=',')
for row in csvreader:
詞頻 = row[2]
if 詞頻 == "預設":
字 = row[0]
粵拼 = row[1]
if 字 in d and d[字][1] > DEFAULT_FREQ:
# do not override existing frequent pronunciations from yaml dict
continue
else:
d[字] = (粵拼, DEFAULT_FREQ)

def write_dict(d):
with open('src/ToJyutping/jyut6ping3.simple.dict.yaml', 'w') as f:
for k, v in d.items():
print(k + '\t' + v, file=f)

def main():
d = {}
build_dict(d, 'jyut6ping3.dict.yaml')
build_yaml_dict(d, 'jyut6ping3.dict.yaml')
build_char_dict(d, 'char.csv')

d_t = {k: v[0] for k, v in d.items()}
d_cn = {t2s(k): v for k, v in d_t.items()}
Expand Down
Empty file removed tests/.placeholder
Empty file.
Loading