Skip to content

Commit

Permalink
修正【雅俗通】標音方法的錯誤
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJui committed Jan 9, 2025
1 parent 0fd8c1d commit bdf8883
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 128 deletions.
3 changes: 2 additions & 1 deletion mod_file_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ def save_as_new_file(wb):
# 設定檔案輸出路徑,存於專案根目錄下的 output2 資料夾
output_path = wb.names['OUTPUT_PATH'].refers_to_range.value
hue_im = wb.names['語音類型'].refers_to_range.value
piau_im_huat = wb.names['標音方法'].refers_to_range.value
im_piat = hue_im[:2] # 取 hue_im 前兩個字元
new_file_path = os.path.join(
".\\{0}".format(output_path),
f"【河洛{im_piat}注音】{file_name}.xlsx")
f"【河洛{im_piat}注音-{piau_im_huat}{file_name}.xlsx")

# 儲存新建立的工作簿
wb.save(new_file_path)
Expand Down
Binary file not shown.
Binary file modified output7/【河洛文讀注音】《般若波羅蜜多心經》.xlsx
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion p701_Clear_Cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def clear_hanji_in_cells(wb, sheet_name='漢字注音', source_cell='V3', clear_
sheet = wb.sheets[sheet_name]

# 取得 V3 儲存格的字串
v3_value = sheet.range(cell).value
v3_value = sheet.range(source_cell).value

# 計算字串的總長度
total_length = len(v3_value)
Expand Down
229 changes: 107 additions & 122 deletions p702_Ca_Han_Ji_Thak_Im.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,133 +89,118 @@ def ca_han_ji_thak_im(wb, sheet_name='漢字注音', cell='V3', hue_im="白話
conn = sqlite3.connect(db_name)
cursor = conn.cursor()

if total_length:
if total_length > (CHARS_PER_ROW * TOTAL_ROWS):
print("可供作業之儲存格數太少,無法進行作業!")
else:
row = 5
index = 0
while index < total_length:
sheet.range((row, 1)).select()

for col in range(start, end):
if index == total_length:
break

col_name = xw.utils.col_name(col)
char = None
cell_value = ""
han_ji = ''
tai_gi_im_piau = ""
han_ji_piau_im = ""
result = None
msg = ""

char = v3_value[index]
if char == "\n":
index += 1
break

cell_value = sheet.range((row, col)).value
if is_punctuation(cell_value):
msg = cell_value
print(f"({row}, {col_name}) = {msg}")
index += 1
continue

# 自儲存格取出【漢字】
han_ji = cell_value
han_ji_u_piau_im = False

# 依據【人工標音】欄是否有輸入,決定【漢字標音】之處理方式
manual_input = sheet.range((row-2, col)).value

if manual_input: # 若有人工輸入之處理作業
if '〔' in manual_input and '〕' in manual_input:
# 將人工輸入的〔台語音標〕轉換成【方音符號】
im_piau = manual_input.split('〔')[1].split('〕')[0]
siann, un, tiau = split_tai_gi_im_piau(im_piau)
tai_gi_im_piau = ''.join([siann, un, tiau])
# 依使用者指定之【標音方法】,將【台語音標】轉換成其所需之【漢字標音】
han_ji_piau_im = tlpa_tng_han_ji_piau_im(
piau_im=piau_im,
piau_im_huat=piau_im_huat,
tai_gi_im_piau=tai_gi_im_piau
)
han_ji_u_piau_im = True
elif '【' in manual_input and '】' in manual_input:
# 將人工輸入的【方音符號】轉換成【台語音標】
han_ji_piau_im = manual_input.split('【')[1].split('】')[0]
siann, un, tiau = split_hong_im_hu_ho(han_ji_piau_im)
# 依使用者指定之【標音方法】,將【台語音標】轉換成其所需之【漢字標音】
tai_gi_im_piau = hong_im_tng_tai_gi_im_piau(
siann=siann,
un=un,
tiau=tiau,
cursor=cursor,
)['台語音標']
han_ji_u_piau_im = True
# 逐字處理字串,並填入對應的儲存格
row = 5
while row < TOTAL_ROWS:
# 設定【作用儲存格】為列首
sheet.range((row, 1)).select()
for col in range(start, end):
msg = ""

# 取得當前字元
cell_value = sheet.range((row, col)).value

if cell_value == '\n':
break

# 若不為【標點符號】,則以【漢字】處理
if not is_punctuation(cell_value):
# 查找漢字讀音
han_ji = cell_value
han_ji_u_piau_im = False

# 依據【人工標音】欄是否有輸入,決定【漢字標音】之處理方式
manual_input = sheet.range((row-2, col)).value

if manual_input: # 若有人工輸入之處理作業
if '〔' in manual_input and '〕' in manual_input:
# 將人工輸入的〔台語音標〕轉換成【方音符號】
im_piau = manual_input.split('〔')[1].split('〕')[0]
siann, un, tiau = split_tai_gi_im_piau(im_piau)
tai_gi_im_piau = ''.join([siann, un, tiau])
# 依使用者指定之【標音方法】,將【台語音標】轉換成其所需之【漢字標音】
han_ji_piau_im = tlpa_tng_han_ji_piau_im(
piau_im=piau_im,
piau_im_huat=piau_im_huat,
tai_gi_im_piau=tai_gi_im_piau
)
han_ji_u_piau_im = True
elif '【' in manual_input and '】' in manual_input:
# 將人工輸入的【方音符號】轉換成【台語音標】
han_ji_piau_im = manual_input.split('【')[1].split('】')[0]
siann, un, tiau = split_hong_im_hu_ho(han_ji_piau_im)
# 依使用者指定之【標音方法】,將【台語音標】轉換成其所需之【漢字標音】
tai_gi_im_piau = hong_im_tng_tai_gi_im_piau(
siann=siann,
un=un,
tiau=tiau,
cursor=cursor,
)['台語音標']
han_ji_u_piau_im = True
else:
# 將人工輸入的【台語音標】,解構為【聲母】、【韻母】、【聲調】
tai_gi_im_piau = manual_input
siann, un, tiau = split_tai_gi_im_piau(tai_gi_im_piau)
# 依指定之【標音方法】,將【台語音標】轉換成其所需之【漢字標音】
han_ji_piau_im = tng_uann_han_ji_piau_im(
piau_im,
piau_im_huat,
siann,
un,
tiau
)
han_ji_u_piau_im = True

# 將人工輸入的【台語音標】置入【破音字庫】Dict
phua_im_ji.ka_phua_im_ji(han_ji, tai_gi_im_piau)
else: # 無人工輸入,則自【漢字庫】查找作業
# 查找【破音字庫】,確認是否有此漢字
found = phua_im_ji.ca_phua_im_ji(han_ji)
# 若【破音字庫】有此漢字
if found:
siann_bu, un_bu, tiau_ho = split_tai_gi_im_piau(found)
tai_gi_im_piau = siann_bu + un_bu + tiau_ho
han_ji_piau_im = tng_uann_han_ji_piau_im(
piau_im,
piau_im_huat,
siann_bu,
un_bu,
tiau_ho
)
han_ji_u_piau_im = True
sheet.range((row, col)).font.color = (255, 0, 0) # 將文字顏色設為【紅色】
sheet.range((row, col)).color = (255, 255, 0) # 將底色設為【黄色】
print(f"漢字:【{han_ji}】之注音【{tai_gi_im_piau}】取自【人工注音字典】。")
# 若【破音字庫】無此漢字,則在資料庫中查找
else:
result = han_ji_ca_piau_im(cursor=cursor, han_ji=han_ji, hue_im=hue_im)
if not result:
msg = f"【{han_ji}】查無此字!"
else:
# 將人工輸入的【台語音標】,解構為【聲母】、【韻母】、【聲調】
tai_gi_im_piau = manual_input
siann, un, tiau = split_tai_gi_im_piau(tai_gi_im_piau)
# 依指定之【標音方法】,將【台語音標】轉換成其所需之【漢字標音】
han_ji_piau_im = tng_uann_han_ji_piau_im(
piau_im,
piau_im_huat,
siann,
un,
tiau
# 依【漢字庫】查找結果,輸出【台語音標】和【漢字標音】
tai_gi_im_piau, han_ji_piau_im = za_ji_kiat_ko_cut_piau_im(
result=result,
han_ji_khoo=han_ji_khoo,
piau_im=piau_im,
piau_im_huat=piau_im_huat
)
han_ji_u_piau_im = True

# 將人工輸入的【台語音標】置入【破音字庫】Dict
phua_im_ji.ka_phua_im_ji(han_ji, tai_gi_im_piau)
else: # 無人工輸入,則自【漢字庫】查找作業
# 查找【破音字庫】,確認是否有此漢字
found = phua_im_ji.ca_phua_im_ji(han_ji)
# 若【破音字庫】有此漢字
if found:
siann_bu, un_bu, tiau_ho = split_tai_gi_im_piau(found)
tai_gi_im_piau = siann_bu + un_bu + tiau_ho
han_ji_piau_im = tng_uann_han_ji_piau_im(
piau_im,
piau_im_huat,
siann_bu,
un_bu,
tiau_ho
)
han_ji_u_piau_im = True
sheet.range((row, col)).font.color = (255, 0, 0) # 將文字顏色設為【紅色】
sheet.range((row, col)).color = (255, 255, 0) # 將底色設為【黄色】
print(f"漢字:【{han_ji}】之注音【{tai_gi_im_piau}】取自【人工注音字典】。")
# 若【破音字庫】無此漢字,則在資料庫中查找
else:
result = han_ji_ca_piau_im(cursor=cursor, han_ji=han_ji, hue_im=hue_im)
if not result:
msg = f"【{han_ji}】查無此字!"
else:
# 依【漢字庫】查找結果,輸出【台語音標】和【漢字標音】
tai_gi_im_piau, han_ji_piau_im = za_ji_kiat_ko_cut_piau_im(
result=result,
han_ji_khoo=han_ji_khoo,
piau_im=piau_im,
piau_im_huat=piau_im_huat
)
han_ji_u_piau_im = True

if han_ji_u_piau_im:
sheet.range((row - 1, col)).value = tai_gi_im_piau
sheet.range((row + 1, col)).value = han_ji_piau_im
msg = f"{han_ji}: [{tai_gi_im_piau}] /【{han_ji_piau_im}】"

print(f"({row}, {col_name}) = {msg}")
index += 1

row += 4
print("\n")
print("已完成【台語音標】和【方音符號】標注工作。")
if han_ji_u_piau_im:
sheet.range((row - 1, col)).value = tai_gi_im_piau
sheet.range((row + 1, col)).value = han_ji_piau_im
msg = f"{han_ji}: [{tai_gi_im_piau}] /【{han_ji_piau_im}】"

col_name = xw.utils.col_name(col)
print(f"({row}, {col_name}) = {msg}")

# 每處理 15 個字元後,換到下一行
row += 4
print("\n")

print("已完成【台語音標】和【方音符號】標注工作。")

# 關閉資料庫連線
conn.close()

wb.save()
18 changes: 14 additions & 4 deletions p710_thiam_han_ji.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def fill_hanji_in_cells(wb, sheet_name='漢字注音', cell='V3'):
row = 5
index = 0 # 用來追蹤目前處理到的字元位置

# 逐字處理字串
# 逐字處理字串
while index < total_length: # 使用 while 而非 for,確保處理完整個字串
# 設定當前作用儲存格,根據 `row` 和 `col` 動態選取
sheet.range((row, 1)).select()
Expand All @@ -60,9 +60,15 @@ def fill_hanji_in_cells(wb, sheet_name='漢字注音', cell='V3'):
print(f"自動填入【hiu2】於 {xw.utils.col_name(col)}{row - 2}")

if char == "\n":
# 若遇到換行字元,直接跳過
index += 1
break
char = "=CHAR(10)" # 換行字元

# 重置儲存格:文字顏色(黑色)及填滿色彩(無填滿)
sheet.range((row-2, col), (row+1, col)).color = None
sheet.range((row, col)).font.color = (0, 0, 0)
sheet.range((row, col)).font.color = (0, 0, 0)
sheet.range((row-2, col)).font.color = (255, 0, 0)
sheet.range((row-1, col)).font.color = 0x3399FF # 藍色
sheet.range((row+1, col)).font.color = 0x009900 # 綠色

# 將字元填入對應的儲存格
sheet.range((row, col)).value = char
Expand All @@ -72,6 +78,10 @@ def fill_hanji_in_cells(wb, sheet_name='漢字注音', cell='V3'):

# 更新索引,處理下一個字元
index += 1

# 換行:列數加一,並從下一列的第一個字元開始
if char == "=CHAR(10)":
break
else:
break # 若字串已處理完畢,退出迴圈

Expand Down

0 comments on commit bdf8883

Please sign in to comment.