Skip to content

Commit

Permalink
(1)變更十五音【標音格式】;(2)另存新檔改變命名方式。
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJui committed Jan 6, 2025
1 parent ffe6abb commit 2a1f38c
Show file tree
Hide file tree
Showing 33 changed files with 3,380 additions and 186 deletions.
Binary file modified Documents/D110_雅俗通十五音字典轉換工具.xlsx
Binary file not shown.
17 changes: 17 additions & 0 deletions Documents/URS_004_匯出漢字.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# URS-004 匯出漢字

## 摘要

將【漢字注音】工作表,列號:5、9、13、17、21...,將:D、E、F、G、H...、R 欄中之
漢字匯出,製成【純文字檔】。

## 匯出流程

1. 開啟【漢字注音】工作表。
2. 自列號:5、9、13、...各列,逐列檢查欄位:D、E、F、G、H...、R,若列、欄交織
所代表之儲存格內有值,則:
1. 將 5D 儲存格內之漢字取出,寫入【純文字檔】。
2. 將 D、E、F、G、H...、R 欄之漢字,寫入【純文字檔】。
3. 重複步驟 2,直至檢查完所有列。
4. 關閉【漢字注音】工作表。
5. 儲存【純文字檔】。
Binary file modified Ho_Lok_Ue.db
Binary file not shown.
23 changes: 2 additions & 21 deletions a701_作業中活頁檔填入漢字.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import xlwings as xw

from mod_file_access import get_han_ji_khoo, get_sound_type
from mod_file_access import get_han_ji_khoo, get_sound_type, save_as_new_file
from p702_Ca_Han_Ji_Thak_Im import ca_han_ji_thak_im
from p709_reset_han_ji_cells import reset_han_ji_cells
from p710_thiam_han_ji import fill_hanji_in_cells
Expand Down Expand Up @@ -57,23 +57,4 @@
# sys.exit(2)

# 將檔案存放路徑設為【專案根目錄】之下
try:
file_name = str(wb.names['TITLE'].refers_to_range.value).strip()
except KeyError:
print("未找到命名範圍 'TITLE',使用預設名稱")
# file_name = "Tai_Gi_Zu_Im_Bun.xlsx" # 提供一個預設檔案名稱
setting_sheet = wb.sheets["env"]
file_name = str(
setting_sheet.range("C4").value
).strip()

# 設定檔案輸出路徑,存於專案根目錄下的 output2 資料夾
output_path = wb.names['OUTPUT_PATH'].refers_to_range.value
new_file_path = os.path.join(
".\\{0}".format(output_path),
f"【河洛話注音】{file_name}.xlsx")

# 儲存新建立的工作簿
wb.save(new_file_path)

print(f"待注音漢字已備妥: {new_file_path}")
save_as_new_file(wb=wb)
22 changes: 3 additions & 19 deletions a702_查找及填入漢字標音.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import xlwings as xw

from mod_file_access import get_han_ji_khoo, get_sound_type
from mod_file_access import get_han_ji_khoo, get_sound_type, save_as_new_file
from p702_Ca_Han_Ji_Thak_Im import ca_han_ji_thak_im

# ==============================================================================
Expand Down Expand Up @@ -92,25 +92,9 @@
# ==============================================================================
# (4) A750: 將 Tai_Gi_Zu_Im_Bun.xlsx 檔案,依 env 工作表的設定,另存新檔到指定目錄。
# ==============================================================================
try:
file_name = str(wb.names["TITLE"].refers_to_range.value).strip()
except KeyError:
# print("未找到命名範圍 'TITLE',使用預設名稱")
# file_name = "default_file_name.xlsx" # 提供一個預設檔案名稱
setting_sheet = wb.sheets["env"]
file_name = str(setting_sheet.range("C4").value).strip()

# 設定檔案輸出路徑,存於專案根目錄下的 output2 資料夾
output_path = wb.names["OUTPUT_PATH"].refers_to_range.value
new_file_path = os.path.join(
".\\{0}".format(output_path), f"【河洛話注音】{file_name}.xlsx"
)

# 儲存新建立的工作簿
wb.save(new_file_path)
print(f"新檔案已儲存至: {new_file_path}")
save_as_new_file(wb=wb)
# wb.close()

# 保存 Excel 檔案
# wb.close()
print("程式執行完畢!")
sys.exit(0)
107 changes: 0 additions & 107 deletions a702_查找及填入漢字標音_bak.py

This file was deleted.

23 changes: 2 additions & 21 deletions a703_製作標音網頁.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import xlwings as xw

from mod_file_access import get_named_value
from mod_file_access import get_named_value, save_as_new_file
from p730_Tng_Sing_Bang_Iah import tng_sing_bang_iah

# 指定虛擬環境的 Python 路徑
Expand Down Expand Up @@ -41,25 +41,6 @@
tng_sing_bang_iah(wb=wb, sheet_name='漢字注音', cell='V3', page_type='含頁頭')

# (3) A750: 將 Tai_Gi_Zu_Im_Bun.xlsx 檔案,依 env 工作表的設定,另存新檔到指定目錄。
try:
file_name = str(wb.names['TITLE'].refers_to_range.value).strip()
except KeyError:
# print("未找到命名範圍 'TITLE',使用預設名稱")
# file_name = "default_file_name.xlsx" # 提供一個預設檔案名稱
setting_sheet = wb.sheets["env"]
file_name = str(
setting_sheet.range("C4").value
).strip()

# 設定檔案輸出路徑,存於專案根目錄下的 output2 資料夾
output_path = wb.names['OUTPUT_PATH'].refers_to_range.value
new_file_path = os.path.join(
".\\{0}".format(output_path),
f"【河洛話注音】{file_name}.xlsx")

# 儲存新建立的工作簿
wb.save(new_file_path)

# 保存 Excel 檔案
save_as_new_file(wb=wb)
# wb.close()

21 changes: 6 additions & 15 deletions a704_製作其它漢字標音.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

import xlwings as xw

from mod_file_access import copy_excel_sheet, reset_han_ji_piau_im_cells
from mod_file_access import (
copy_excel_sheet,
reset_han_ji_piau_im_cells,
save_as_new_file,
)
from p704_漢字以十五音標注音 import han_ji_piau_im

# (0) 取得專案根目錄。
Expand Down Expand Up @@ -45,17 +49,4 @@
# tng_sing_bang_iah(wb, '漢字注音', 'V3')

# (4) A750: 將 Tai_Gi_Zu_Im_Bun.xlsx 檔案,依 env 工作表的設定,另存新檔到指定目錄。
try:
file_name = str(wb.names['TITLE'].refers_to_range.value).strip()
except KeyError:
setting_sheet = wb.sheets["env"]
file_name = str(setting_sheet.range("C4").value).strip()

# 設定檔案輸出路徑,存於專案根目錄下的 output2 資料夾
output_path = wb.names['OUTPUT_PATH'].refers_to_range.value
new_file_path = os.path.join(
".\\{0}".format(output_path),
f"【{piau_im_huat}{file_name}.xlsx")

# 儲存新建立的工作簿
wb.save(new_file_path)
save_as_new_file(wb=wb)
24 changes: 24 additions & 0 deletions mod_file_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ def load_module_function(module_name, function_name):
module = importlib.import_module(module_name)
return getattr(module, function_name)

#----------------------------------------------------------------
# 依 env 工作表的設定,另存新檔到指定目錄。
#----------------------------------------------------------------
def save_as_new_file(wb):
try:
file_name = str(wb.names['TITLE'].refers_to_range.value).strip()
except KeyError:
# print("未找到命名範圍 'TITLE',使用預設名稱")
# file_name = "default_file_name.xlsx" # 提供一個預設檔案名稱
setting_sheet = wb.sheets["env"]
file_name = str(setting_sheet.range("C4").value).strip()

# 設定檔案輸出路徑,存於專案根目錄下的 output2 資料夾
output_path = wb.names['OUTPUT_PATH'].refers_to_range.value
hue_im = 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")

# 儲存新建立的工作簿
wb.save(new_file_path)
print(f"新檔案已儲存至: {new_file_path}")

#----------------------------------------------------------------
# 查詢語音類型,若未設定則預設為文讀音
#----------------------------------------------------------------
Expand Down
35 changes: 32 additions & 3 deletions mod_標音.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ def split_hong_im_hu_ho(hong_im_hu_ho):

def choose_piau_im_method(piau_im, zu_im_huat, siann_bu, un_bu, tiau_ho):
"""選擇並執行對應的注音方法"""
if zu_im_huat == "十五音":
if zu_im_huat == "雅俗通":
return piau_im.NST_piau_im(siann_bu, un_bu, tiau_ho)
elif zu_im_huat == "十五音":
return piau_im.SNI_piau_im(siann_bu, un_bu, tiau_ho)
elif zu_im_huat == "白話字":
return piau_im.POJ_piau_im(siann_bu, un_bu, tiau_ho)
Expand Down Expand Up @@ -700,7 +702,34 @@ def Cu_Hong_Im_Hu_Ho_Tiau_Hu(self, tai_lo_tiau_ho):
return 方音符號調號.get(tai_lo_tiau_ho, None)

#================================================================
# 雅俗通十五音(SNI:Nga-Siok-Thong)
# 雅俗通十五音(Nga-Siok-Thong)
#================================================================
def NST_piau_im(self, siann_bu, un_bu, tiau_ho):
piau_im_huat = "雅俗通"
Tiau_Ho_Remap = {
1: "上平",
2: "上上",
3: "上去",
4: "上入",
5: "下平",
6: "下上",
7: "下去",
8: "下入",
}

# 將上標數字替換為普通數字
tiau_ho = replace_superscript_digits(str(tiau_ho))
tiau_ho = 7 if int(tiau_ho) == 6 else int(tiau_ho)

siann = self.Siann_Bu_Dict[siann_bu][piau_im_huat]
un = self.Un_Bu_Dict[un_bu][piau_im_huat]
# tiau = self.TONE_MARKS[piau_im_huat][int(tiau_ho)]
tiau = Tiau_Ho_Remap[tiau_ho]
piau_im = f"{un}{tiau}{siann}"
return piau_im

#================================================================
# 雅俗通十五音(SNI:Sip-Ngoo-Im)
#================================================================
def SNI_piau_im(self, siann_bu, un_bu, tiau_ho):
piau_im_huat = "十五音"
Expand All @@ -722,7 +751,7 @@ def SNI_piau_im(self, siann_bu, un_bu, tiau_ho):
un = self.Un_Bu_Dict[un_bu][piau_im_huat]
# tiau = self.TONE_MARKS[piau_im_huat][int(tiau_ho)]
tiau = Tiau_Ho_Remap[tiau_ho]
piau_im = f"{un}{tiau}{siann}"
piau_im = f"{siann}{un}{tiau}"
return piau_im

#================================================================
Expand Down
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions tmp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
°¶°¹±


Loading

0 comments on commit 2a1f38c

Please sign in to comment.