Skip to content

Commit

Permalink
fix(data): order of iter音韻地位
Browse files Browse the repository at this point in the history
Now it iterates 音韻地位's in 廣韻 first, while query字頭/音韻地位 still
prefers 王三 to 廣韻.
  • Loading branch information
syimyuzya committed Aug 22, 2024
1 parent a8dd8d2 commit 4244d50
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/lib/資料.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,13 @@ function insertInto<K, V, T extends Map<K, V[]> = Map<K, V[]>>(map: T, key: KeyO
}
}

(function 早期廣韻外字() {
for (const [字頭, 描述, 反切, 釋義, 韻目] of [
['韻', '云合三B真去', '爲捃', '為捃反音和一', '震'],
['忘', '明三C陽平', '武方', '遺又武放不記曰忘', '陽'],
] as const) {
const 編碼 = encode音韻編碼(音韻地位.from描述(描述));
const record = { 字頭, 編碼, 反切, 釋義, 來源: { 文獻: '王三' as const, 韻目 } };
insertInto(m字頭檢索, 字頭, record);
insertInto(m音韻編碼檢索, 編碼, record);
function prependValuesInto<K, V, T extends Map<K, V[]> = Map<K, V[]>>(map: T, key: KeyOfMap<T>, values: ValueOfMap<T>) {
if (!map.has(key)) {
map.set(key, [...values]);
} else {
map.set(key, [...values, ...map.get(key)!]);
}
})();
}

(function 解析廣韻資料() {
const patternOuter = /([\w$]{3})(..)(.)(.*?\n)/gu;
Expand All @@ -76,6 +72,27 @@ function insertInto<K, V, T extends Map<K, V[]> = Map<K, V[]>>(map: T, key: KeyO
}
})();

(function 早期廣韻外字() {
const by字頭 = new Map<string, 內部檢索結果[]>();
const by編碼 = new Map<string, 內部檢索結果[]>();
for (const [字頭, 描述, 反切, 釋義, 韻目] of [
['韻', '云合三B真去', '爲捃', '為捃反音和一', '震'],
['忘', '明三C陽平', '武方', '遺又武放不記曰忘', '陽'],
] as const) {
const 編碼 = encode音韻編碼(音韻地位.from描述(描述));
const record = { 字頭, 編碼, 反切, 釋義, 來源: { 文獻: '王三' as const, 韻目 } };
insertInto(by字頭, 字頭, record);
insertInto(by編碼, 編碼, record);
}

for (const [字頭, 各條目] of by字頭.entries()) {
prependValuesInto(m字頭檢索, 字頭, 各條目);
}
for (const [編碼, 各條目] of by編碼.entries()) {
prependValuesInto(m音韻編碼檢索, 編碼, 各條目);
}
})();

function 結果from內部結果(內部結果: 內部檢索結果): 檢索結果 {
const { 字頭, 編碼, 來源, ...rest } = 內部結果;
return {
Expand Down

0 comments on commit 4244d50

Please sign in to comment.