fasdfsa commited on
Commit
c903252
·
1 Parent(s): 01a8e32

add unt 擬音, unt 過往切韻擬音

Browse files
Files changed (7) hide show
  1. README.md +2 -0
  2. derive-lib.mjs +12 -6
  3. readme.txt +1 -0
  4. server.mjs +2 -3
  5. static/app.js +28 -1
  6. static/index.html +7 -0
  7. static/styles.css +0 -1
README.md CHANGED
@@ -5,6 +5,8 @@
5
  当前内置方案:
6
  - 切韵拼音(TUPA)
7
  - 推導盛唐(平水韻)擬音(High Tang)
 
 
8
 
9
  本项目后端使用 **Node.js + Express**,推导逻辑基于 **tshet-uinh + tshet-uinh-examples**(与原站同源生态)。
10
 
 
5
  当前内置方案:
6
  - 切韵拼音(TUPA)
7
  - 推導盛唐(平水韻)擬音(High Tang)
8
+ - unt 擬音(unt)
9
+ - unt 過往切韻擬音(unt_legacy)
10
 
11
  本项目后端使用 **Node.js + Express**,推导逻辑基于 **tshet-uinh + tshet-uinh-examples**(与原站同源生态)。
12
 
derive-lib.mjs CHANGED
@@ -65,17 +65,23 @@ function tokensFromCharText(text, derivePron) {
65
  }
66
 
67
  function getDeriver(scheme) {
68
- if (scheme === "tupa") return Examples.tupa({});
69
- if (scheme === "high_tang") return Examples.high_tang({});
 
 
 
 
 
 
70
  throw new Error(`Unsupported scheme: ${scheme}`);
71
  }
72
 
73
- export function derive({ scheme = "tupa", text = "" } = {}) {
74
  const s = scheme.toString();
75
  const t = text.toString();
76
  if (s === "tupa_high_tang") {
77
- const deriveTupa = getDeriver("tupa");
78
- const deriveHighTang = getDeriver("high_tang");
79
  const tokens = /[\s\S]\([^)]+\)/.test(t)
80
  ? // 兼容旧格式:括号内地位直接推导(两套方案)
81
  (() => {
@@ -114,7 +120,7 @@ export function derive({ scheme = "tupa", text = "" } = {}) {
114
  return { scheme: s, tokens };
115
  }
116
 
117
- const derivePron = getDeriver(s);
118
  // 兼容两种输入:
119
  // 1) 旧格式:風(幫三C東平) —— 直接用括号内地位推导
120
  // 2) 新格式:只输入汉字 —— 按字头查資料推导
 
65
  }
66
 
67
  function getDeriver(scheme) {
68
+ return getDeriverWithOptions(scheme, undefined);
69
+ }
70
+
71
+ function getDeriverWithOptions(scheme, options) {
72
+ if (scheme === "tupa") return Examples.tupa(options ?? {});
73
+ if (scheme === "high_tang") return Examples.high_tang(options ?? {});
74
+ if (scheme === "unt") return Examples.unt(options ?? {});
75
+ if (scheme === "unt_legacy") return Examples.unt_legacy(options ?? {});
76
  throw new Error(`Unsupported scheme: ${scheme}`);
77
  }
78
 
79
+ export function derive({ scheme = "tupa", text = "", options = undefined } = {}) {
80
  const s = scheme.toString();
81
  const t = text.toString();
82
  if (s === "tupa_high_tang") {
83
+ const deriveTupa = getDeriverWithOptions("tupa", undefined);
84
+ const deriveHighTang = getDeriverWithOptions("high_tang", undefined);
85
  const tokens = /[\s\S]\([^)]+\)/.test(t)
86
  ? // 兼容旧格式:括号内地位直接推导(两套方案)
87
  (() => {
 
120
  return { scheme: s, tokens };
121
  }
122
 
123
+ const derivePron = getDeriverWithOptions(s, options);
124
  // 兼容两种输入:
125
  // 1) 旧格式:風(幫三C東平) —— 直接用括号内地位推导
126
  // 2) 新格式:只输入汉字 —— 按字头查資料推导
readme.txt CHANGED
@@ -2,3 +2,4 @@
2
  see https://nk2028.shn.hk/tshet-uinh-autoderiver/
3
  切韻音系自動推導器
4
 
 
 
2
  see https://nk2028.shn.hk/tshet-uinh-autoderiver/
3
  切韻音系自動推導器
4
 
5
+ see doc/平水韵拟音.md
server.mjs CHANGED
@@ -20,8 +20,8 @@ app.get("/", (_req, res) => {
20
 
21
  app.post("/api/derive", (req, res) => {
22
  try {
23
- const { scheme = "tupa", text = "" } = req.body || {};
24
- res.json(derive({ scheme, text }));
25
  } catch (e) {
26
  res.status(400).send(e?.message ? String(e.message) : String(e));
27
  }
@@ -32,4 +32,3 @@ app.listen(port, () => {
32
  // eslint-disable-next-line no-console
33
  console.log(`Server listening on http://127.0.0.1:${port}`);
34
  });
35
-
 
20
 
21
  app.post("/api/derive", (req, res) => {
22
  try {
23
+ const { scheme = "tupa", text = "", options = undefined } = req.body || {};
24
+ res.json(derive({ scheme, text, options }));
25
  } catch (e) {
26
  res.status(400).send(e?.message ? String(e.message) : String(e));
27
  }
 
32
  // eslint-disable-next-line no-console
33
  console.log(`Server listening on http://127.0.0.1:${port}`);
34
  });
 
static/app.js CHANGED
@@ -3,6 +3,7 @@ const $ = sel => document.querySelector(sel);
3
  const inputEl = $("#input");
4
  const outputEl = $("#output");
5
  const schemeEl = $("#scheme");
 
6
  const btnDerive = $("#btn-derive");
7
  const btnCopy = $("#btn-copy");
8
  let lastScheme = schemeEl.value;
@@ -11,6 +12,32 @@ function setBusy(busy) {
11
  btnDerive.disabled = busy;
12
  btnCopy.disabled = busy;
13
  schemeEl.disabled = busy;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  }
15
 
16
  // 如果用户直接用文件方式打开(file://),API 将不可用
@@ -82,7 +109,7 @@ btnDerive.addEventListener("click", async () => {
82
  const resp = await fetch("/api/derive", {
83
  method: "POST",
84
  headers: { "Content-Type": "application/json" },
85
- body: JSON.stringify({ text: inputEl.value, scheme: schemeEl.value }),
86
  });
87
  if (!resp.ok) throw new Error(await resp.text());
88
  const data = await resp.json();
 
3
  const inputEl = $("#input");
4
  const outputEl = $("#output");
5
  const schemeEl = $("#scheme");
6
+ const untVersionEl = $("#unt-version");
7
  const btnDerive = $("#btn-derive");
8
  const btnCopy = $("#btn-copy");
9
  let lastScheme = schemeEl.value;
 
12
  btnDerive.disabled = busy;
13
  btnCopy.disabled = busy;
14
  schemeEl.disabled = busy;
15
+ untVersionEl.disabled = busy;
16
+ }
17
+
18
+ function syncSchemeUI() {
19
+ // 只有 unt_legacy 需要版本选项
20
+ if (schemeEl.value === "unt_legacy") {
21
+ untVersionEl.style.display = "";
22
+ } else {
23
+ untVersionEl.style.display = "none";
24
+ }
25
+ }
26
+
27
+ schemeEl.addEventListener("change", syncSchemeUI);
28
+ syncSchemeUI();
29
+
30
+ function buildOptionsForScheme() {
31
+ if (schemeEl.value !== "unt_legacy") return undefined;
32
+ // 这些字符串需要与 tshet-uinh-examples/unt_legacy 方案里「版本」选项的文案匹配
33
+ const v = untVersionEl.value;
34
+ const 版本 =
35
+ v === "2020J"
36
+ ? "2020:切韻擬音 J(原版)"
37
+ : v === "2023P"
38
+ ? "2023:切韻通俗擬音"
39
+ : "2022:切韻擬音 L";
40
+ return { 版本 };
41
  }
42
 
43
  // 如果用户直接用文件方式打开(file://),API 将不可用
 
109
  const resp = await fetch("/api/derive", {
110
  method: "POST",
111
  headers: { "Content-Type": "application/json" },
112
+ body: JSON.stringify({ text: inputEl.value, scheme: schemeEl.value, options: buildOptionsForScheme() }),
113
  });
114
  if (!resp.ok) throw new Error(await resp.text());
115
  const data = await resp.json();
static/index.html CHANGED
@@ -15,8 +15,15 @@
15
  <select id="scheme">
16
  <option value="tupa">切韵拼音(TUPA)</option>
17
  <option value="high_tang">推導盛唐(平水韻)擬音</option>
 
 
18
  <option value="tupa_high_tang">切韵拼音 + 盛唐拟音(对照)</option>
19
  </select>
 
 
 
 
 
20
  </div>
21
  </header>
22
 
 
15
  <select id="scheme">
16
  <option value="tupa">切韵拼音(TUPA)</option>
17
  <option value="high_tang">推導盛唐(平水韻)擬音</option>
18
+ <option value="unt">unt 擬音</option>
19
+ <option value="unt_legacy">unt 過往切韻擬音</option>
20
  <option value="tupa_high_tang">切韵拼音 + 盛唐拟音(对照)</option>
21
  </select>
22
+ <select id="unt-version" title="unt 過往切韻擬音版本" style="display: none">
23
+ <option value="2020J">2020:切韻擬音 J</option>
24
+ <option value="2022L" selected>2022:切韻擬音 L</option>
25
+ <option value="2023P">2023:切韻通俗擬音</option>
26
+ </select>
27
  </div>
28
  </header>
29
 
static/styles.css CHANGED
@@ -107,4 +107,3 @@ rt {
107
  font-size: 12px;
108
  color: #6f2dbd;
109
  }
110
-
 
107
  font-size: 12px;
108
  color: #6f2dbd;
109
  }