| import pandas as pd | |
| import re | |
| # Receives a .csv file with three columns (the third will be filled/overwritten) | |
| # Replaces the pronunciation of the kanji between parenthesis by the kanji that | |
| # is in the first column. | |
| def main(): | |
| with open('jkeywords.csv', encoding='utf-8') as f: | |
| df = pd.read_csv(f, sep='\t', names=["kanji", "oldkey", "newkey"], | |
| encoding='utf8') | |
| df.fillna('', inplace=True) # make empty fields strings too, not floats. | |
| # select the normal or japanese parenthesis and it's contents only if it only | |
| # have kanas in between them. | |
| regex = re.compile("[(|(][ぁ-ー]+[)|)]", re.UNICODE) | |
| for index, row in df.iterrows(): | |
| ok = row['oldkey'] | |
| if ok == "": | |
| continue | |
| kanji = row['kanji'] | |
| s = "" | |
| for word in ok.split("、"): # japanese comma | |
| tmp, n = regex.subn(kanji, word) | |
| if n == 0: | |
| tmp = kanji # when the reading is for the whole kanji alone | |
| s += tmp + "、" | |
| row['newkey'] = s[:-1] # remove the trailing comma | |
| #print(df) | |
| df.to_csv('processed.csv', sep='\t', header=False, index=False) | |
| main() |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file
| 一 (ひと)つ 一tsuu | |
| 二 (ふた)つ | |
| 三 (みっ)つ | |
| 四 (よっ)つ | |
| 五 (いつ)つ | |
| 六 (むっ)つ | |
| 七 (なな)つ | |
| 八 (やっ)つ | |
| 九 (ここの)つ | |
| 十 じゅう | |
| 口 くち | |
| 日 ひ | |
| 月 つき、(ゲツ)曜日 | |
| 田 た | |
| 目 め | |
| 古 (ふる)い | |
| 吾 ゴ、(ゴ)人 | |
| 冒 (ボウ)険 | |
| 朋 (ホウ)輩、(ホウ)友 | |
| 明 (あか)るい、説(メイ) | |
| 唱 暗(ショウ)、(とな)える | |
| 晶 結(ショウ) | |
| 品 (シナ)物、作(ヒン) | |
| 呂 お風(ロ) | |
| 昌 (ショウ)運 | |
| 早 朝(はや)い | |
| 旭 (キョク)日、あさひ | |
| 世 (セ)代、(セ)界、よ | |
| 胃 (い)腸 | |
| 旦 (ダン)那、一(タン) | |
| 胆 大(タン)な、きも | |
| 亘 連(コウ)、(コウ)古 | |
| 凹 (オウ)レンズ | |
| 凸 (トツ)レンズ | |
| 旧 (キュウ)暦、復(キュウ) | |
| 自 (ジ)分 | |
| 白 (しろ)い | |
| 百 ヒャク | |
| 中 なか、(チュウ)止 | |
| 千 (セン)円 | |
| 舌 した | |
| 升 一(ショウ)、ます | |
| 昇 上(ショウ)、(ショウ)進、(のぼ)る |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file
| 一 (ひと)つ 一つ | |
| 二 (ふた)つ 二つ | |
| 三 (みっ)つ 三つ | |
| 四 (よっ)つ 四つ | |
| 五 (いつ)つ 五つ | |
| 六 (むっ)つ 六つ | |
| 七 (なな)つ 七つ | |
| 八 (やっ)つ 八つ | |
| 九 (ここの)つ 九つ | |
| 十 じゅう 十 | |
| 口 くち 口 | |
| 日 ひ 日 | |
| 月 つき、(ゲツ)曜日 月、月曜日 | |
| 田 た 田 | |
| 目 め 目 | |
| 古 (ふる)い 古い | |
| 吾 ゴ、(ゴ)人 吾、吾人 | |
| 冒 (ボウ)険 冒険 | |
| 朋 (ホウ)輩、(ホウ)友 朋輩、朋友 | |
| 明 (あか)るい、説(メイ) 明るい、説明 | |
| 唱 暗(ショウ)、(とな)える 暗唱、唱える | |
| 晶 結(ショウ) 結晶 | |
| 品 (シナ)物、作(ヒン) 品物、作品 | |
| 呂 お風(ロ) お風呂 | |
| 昌 (ショウ)運 昌運 | |
| 早 朝(はや)い 朝早い | |
| 旭 (キョク)日、あさひ 旭日、旭 | |
| 世 (セ)代、(セ)界、よ 世代、世界、世 | |
| 胃 (い)腸 胃腸 | |
| 旦 (ダン)那、一(タン) 旦那、一旦 | |
| 胆 大(タン)な、きも 大胆な、胆 | |
| 亘 連(コウ)、(コウ)古 連亘、亘古 | |
| 凹 (オウ)レンズ 凹レンズ | |
| 凸 (トツ)レンズ 凸レンズ | |
| 旧 (キュウ)暦、復(キュウ) 旧暦、復旧 | |
| 自 (ジ)分 自分 | |
| 白 (しろ)い 白い | |
| 百 ヒャク 百 | |
| 中 なか、(チュウ)止 中、中止 | |
| 千 (セン)円 千円 | |
| 舌 した 舌 | |
| 升 一(ショウ)、ます 一升、升 | |
| 昇 上(ショウ)、(ショウ)進、(のぼ)る 上昇、昇進、昇る |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment