推导 广州、上海 方言,普通话
Browse files- README.md +3 -0
- derive-lib.mjs +3 -0
- static/app.js +16 -1
- static/index.html +6 -0
README.md
CHANGED
|
@@ -7,6 +7,9 @@
|
|
| 7 |
- 推導盛唐(平水韻)擬音(High Tang)
|
| 8 |
- unt 擬音(unt)
|
| 9 |
- unt 過往切韻擬音(unt_legacy)
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
本项目后端使用 **Node.js + Express**,推导逻辑基于 **tshet-uinh + tshet-uinh-examples**(与原站同源生态)。
|
| 12 |
|
|
|
|
| 7 |
- 推導盛唐(平水韻)擬音(High Tang)
|
| 8 |
- unt 擬音(unt)
|
| 9 |
- unt 過往切韻擬音(unt_legacy)
|
| 10 |
+
- 推導普通話(putonghua)
|
| 11 |
+
- 推導廣州話(gwongzau)
|
| 12 |
+
- 推導上海話(zaonhe)
|
| 13 |
|
| 14 |
本项目后端使用 **Node.js + Express**,推导逻辑基于 **tshet-uinh + tshet-uinh-examples**(与原站同源生态)。
|
| 15 |
|
derive-lib.mjs
CHANGED
|
@@ -73,6 +73,9 @@ function getDeriverWithOptions(scheme, 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 |
|
|
|
|
| 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 |
+
if (scheme === "putonghua") return Examples.putonghua(options ?? {});
|
| 77 |
+
if (scheme === "gwongzau") return Examples.gwongzau(options ?? {});
|
| 78 |
+
if (scheme === "zaonhe") return Examples.zaonhe(options ?? {});
|
| 79 |
throw new Error(`Unsupported scheme: ${scheme}`);
|
| 80 |
}
|
| 81 |
|
static/app.js
CHANGED
|
@@ -3,19 +3,27 @@ const $ = sel => document.querySelector(sel);
|
|
| 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;
|
|
|
|
| 10 |
|
| 11 |
function setBusy(busy) {
|
| 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 = "";
|
|
@@ -25,9 +33,11 @@ function syncSchemeUI() {
|
|
| 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;
|
|
@@ -106,10 +116,15 @@ btnDerive.addEventListener("click", async () => {
|
|
| 106 |
outputEl.textContent = "推导中…";
|
| 107 |
try {
|
| 108 |
lastScheme = schemeEl.value;
|
|
|
|
| 109 |
const resp = await fetch("/api/derive", {
|
| 110 |
method: "POST",
|
| 111 |
headers: { "Content-Type": "application/json" },
|
| 112 |
-
body: JSON.stringify({
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
});
|
| 114 |
if (!resp.ok) throw new Error(await resp.text());
|
| 115 |
const data = await resp.json();
|
|
|
|
| 3 |
const inputEl = $("#input");
|
| 4 |
const outputEl = $("#output");
|
| 5 |
const schemeEl = $("#scheme");
|
| 6 |
+
const dialectEl = $("#dialect");
|
| 7 |
const untVersionEl = $("#unt-version");
|
| 8 |
const btnDerive = $("#btn-derive");
|
| 9 |
const btnCopy = $("#btn-copy");
|
| 10 |
let lastScheme = schemeEl.value;
|
| 11 |
+
let lastDialect = dialectEl.value;
|
| 12 |
|
| 13 |
function setBusy(busy) {
|
| 14 |
btnDerive.disabled = busy;
|
| 15 |
btnCopy.disabled = busy;
|
| 16 |
schemeEl.disabled = busy;
|
| 17 |
+
dialectEl.disabled = busy;
|
| 18 |
untVersionEl.disabled = busy;
|
| 19 |
}
|
| 20 |
|
| 21 |
function syncSchemeUI() {
|
| 22 |
+
// 选择了方言推导时,隐藏 unt 过往版本选项
|
| 23 |
+
if (dialectEl.value) {
|
| 24 |
+
untVersionEl.style.display = "none";
|
| 25 |
+
return;
|
| 26 |
+
}
|
| 27 |
// 只有 unt_legacy 需要版本选项
|
| 28 |
if (schemeEl.value === "unt_legacy") {
|
| 29 |
untVersionEl.style.display = "";
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
schemeEl.addEventListener("change", syncSchemeUI);
|
| 36 |
+
dialectEl.addEventListener("change", syncSchemeUI);
|
| 37 |
syncSchemeUI();
|
| 38 |
|
| 39 |
function buildOptionsForScheme() {
|
| 40 |
+
if (dialectEl.value) return undefined;
|
| 41 |
if (schemeEl.value !== "unt_legacy") return undefined;
|
| 42 |
// 这些字符串需要与 tshet-uinh-examples/unt_legacy 方案里「版本」选项的文案匹配
|
| 43 |
const v = untVersionEl.value;
|
|
|
|
| 116 |
outputEl.textContent = "推导中…";
|
| 117 |
try {
|
| 118 |
lastScheme = schemeEl.value;
|
| 119 |
+
lastDialect = dialectEl.value;
|
| 120 |
const resp = await fetch("/api/derive", {
|
| 121 |
method: "POST",
|
| 122 |
headers: { "Content-Type": "application/json" },
|
| 123 |
+
body: JSON.stringify({
|
| 124 |
+
text: inputEl.value,
|
| 125 |
+
scheme: dialectEl.value || schemeEl.value,
|
| 126 |
+
options: buildOptionsForScheme(),
|
| 127 |
+
}),
|
| 128 |
});
|
| 129 |
if (!resp.ok) throw new Error(await resp.text());
|
| 130 |
const data = await resp.json();
|
static/index.html
CHANGED
|
@@ -19,6 +19,12 @@
|
|
| 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>
|
|
|
|
| 19 |
<option value="unt_legacy">unt 過往切韻擬音</option>
|
| 20 |
<option value="tupa_high_tang">切韵拼音 + 盛唐拟音(对照)</option>
|
| 21 |
</select>
|
| 22 |
+
<select id="dialect" title="推導現代方言(普通話/廣州話/上海話)">
|
| 23 |
+
<option value="" selected>(不推導方言)</option>
|
| 24 |
+
<option value="putonghua">推導普通話</option>
|
| 25 |
+
<option value="gwongzau">推導廣州話</option>
|
| 26 |
+
<option value="zaonhe">推導上海話</option>
|
| 27 |
+
</select>
|
| 28 |
<select id="unt-version" title="unt 過往切韻擬音版本" style="display: none">
|
| 29 |
<option value="2020J">2020:切韻擬音 J</option>
|
| 30 |
<option value="2022L" selected>2022:切韻擬音 L</option>
|