Spaces:
Running
Running
Download yi_script_bridge_engine.js from Valendir/yi-chinese-dictionary: direct link, hf CLI and curl.
- Browser
- Download file 6.76 kB
-
https://huggingface.co/spaces/Valendir/yi-chinese-dictionary/resolve/main/yi_script_bridge_engine.js
- Command line
-
hf download hf://spaces/Valendir/yi-chinese-dictionary/yi_script_bridge_engine.js
-
curl -L -o yi_script_bridge_engine.js https://huggingface.co/spaces/Valendir/yi-chinese-dictionary/resolve/main/yi_script_bridge_engine.js
6.76 kB
| // ============================================================================ | |
| // 彝汉大词典 · 引擎 2:全彝文跨文种桥接与古今字形对照引擎 | |
| // Pan-Yi Multi-Script Bridge: Liangshan Standard ↔ Sichuan Bimo Old Yi | |
| // ↔ Universal Classical Yi (4,120) ↔ Stone Forest Sani Yi (1,052) | |
| // ============================================================================ | |
| (function (root) { | |
| 'use strict'; | |
| const SCRIPT_META = { | |
| nuosu: { | |
| code: 'nuosu', | |
| name: '凉山规范彝文', | |
| shortName: '凉山规范', | |
| badge: 'Unicode U+A000–A48C', | |
| dialect: '北部方言 · 圣乍诺苏话', | |
| fontClass: 'yi-nuosu', | |
| desc: '1980年国务院批准推行的现代音节文字,含1,165个标准编码字符(819基础音节+345次高变调音节+叠音符ꀕ)及55个部首。' | |
| }, | |
| sichuanOld: { | |
| code: 'sichuanOld', | |
| name: '四川传统古彝文', | |
| shortName: '四川古彝', | |
| badge: '拉普陀 · 毕摩老彝文', | |
| dialect: '四川凉山传统毕摩文献', | |
| fontClass: 'yi-sichuan-old', | |
| desc: '源自《四川彝文(拉普陀)》2025公益字库(阿布木乃等整理),收录凉山地区毕摩典籍传统正体与异体古彝字,与凉山规范音节一一对照。' | |
| }, | |
| universal: { | |
| code: 'universal', | |
| name: '滇川黔桂通用彝文', | |
| shortName: '通用古彝', | |
| badge: '《通用彝文字典》第二版 · 4,120字', | |
| dialect: '超方言(贯通云贵川桂六大方言)', | |
| fontClass: 'yi-universal', | |
| desc: '汇集四川、云南、贵州、广西四省区六大方言13个调查点的超方言表意通用古彝字,配67部首与多地实测IPA读音。' | |
| }, | |
| sani: { | |
| code: 'sani', | |
| name: '石林撒尼古彝文', | |
| shortName: '撒尼古彝', | |
| badge: '《彝汉简明词典》1984 · BabelStone', | |
| dialect: '东南方言 · 云南石林撒尼话', | |
| fontClass: 'yi-sani', | |
| desc: '依据1984年云南民族出版社《彝汉简明词典》与 BabelStone Sani Yi (SIL OFL) 整理,收录1,052词头、400余异体字与严式松紧元音标注。' | |
| }, | |
| dialect: { | |
| code: 'dialect', | |
| name: '六大方言实测对勘', | |
| shortName: '方言对勘', | |
| badge: 'CLDF / 孙宏开 / 阿细先基', | |
| dialect: '北·东·南·东南·西·中六大方言全覆', | |
| fontClass: 'yi-ipa-head', | |
| desc: '融合孙宏开《藏缅语语音和词汇》(1991)、Yang拉罗方言(2011)、Castro鹤庆调查(2010)、Sagart汉藏同源库(2019)与《阿细先基》植物词库。' | |
| } | |
| }; | |
| function getSichuanOldForNuosu(yiStr) { | |
| const map = (root.YI_AUX_DATA && root.YI_AUX_DATA.sichuanOldMap) || {}; | |
| const primary = []; | |
| const variants = []; | |
| for (const ch of String(yiStr || '')) { | |
| if (ch === '\ua015' && primary.length) { | |
| primary.push(primary[primary.length - 1]); | |
| continue; | |
| } | |
| const g = map[ch]; | |
| if (!g) return { primary: '', variants: [] }; | |
| const arr = Array.from(g); | |
| primary.push(arr[0]); | |
| if (String(yiStr).length === 1 && arr.length > 1) { | |
| variants.push(...arr.slice(1)); | |
| } | |
| } | |
| return { primary: primary.join(''), variants }; | |
| } | |
| function convertInputToAllScripts(rawInput, lexicon) { | |
| const q = String(rawInput || '').trim(); | |
| if (!q) return null; | |
| const hasNuosu = /[\ua000-\ua4cf]/.test(q); | |
| const hasLatin = /^[a-zA-Z\s\-']+$/.test(q); | |
| const hasChinese = /[\u4e00-\u9fff]/.test(q); | |
| let nuosuText = ''; | |
| let pinyinText = ''; | |
| let ipaText = ''; | |
| let sichuanPrimary = ''; | |
| let sichuanVariants = []; | |
| const universalMatches = []; | |
| const saniMatches = []; | |
| const nuosuMatches = []; | |
| if (hasNuosu) { | |
| nuosuText = q; | |
| pinyinText = root.YiPhonologyEngine ? root.YiPhonologyEngine.yiToPinyin(q) : ''; | |
| ipaText = root.YiPhonologyEngine ? root.YiPhonologyEngine.yiToIpa(q) : ''; | |
| } else if (hasLatin && root.YiPhonologyEngine) { | |
| nuosuText = root.YiPhonologyEngine.pinyinToYi(q); | |
| pinyinText = q.toLowerCase(); | |
| ipaText = nuosuText ? root.YiPhonologyEngine.yiToIpa(nuosuText) : ''; | |
| } | |
| if (nuosuText) { | |
| const oldRes = getSichuanOldForNuosu(nuosuText); | |
| sichuanPrimary = oldRes.primary; | |
| sichuanVariants = oldRes.variants; | |
| } | |
| // Search live lexicon for exact/close cross-script equivalents (ranked: verified primary sense first!) | |
| if (Array.isArray(lexicon)) { | |
| const nuosuScored = []; | |
| for (let i = 0; i < lexicon.length; i++) { | |
| const e = lexicon[i]; | |
| if (hasChinese) { | |
| const rawParts = (e.glossZh || '').split(/[;;,,、]+/).map(s => s.replace(/[((][^))]*[))]/g, '').trim()).filter(Boolean); | |
| const firstMatch = rawParts[0] === q; | |
| const anyMatch = firstMatch || rawParts.includes(q) || e.glossZh === q; | |
| if (!anyMatch) continue; | |
| if (e.script === 'nuosu') { | |
| const sc = (firstMatch ? 100 : 40) + (e.status === 'verified' ? 50 : 0) + (e.lemma.length <= 2 ? 20 : 0) - rawParts.length * 2; | |
| nuosuScored.push([sc, e]); | |
| } else if (e.script === 'universal' && universalMatches.length < 10) { | |
| universalMatches.push(e); | |
| } else if (e.script === 'sani' && saniMatches.length < 8) { | |
| saniMatches.push(e); | |
| } | |
| } else if (nuosuText) { | |
| if (e.script === 'nuosu' && e.lemma === nuosuText) { | |
| nuosuMatches.push(e); | |
| const uChars = (e.scripts && e.scripts.universal) || []; | |
| if (uChars.length) { | |
| for (let j = 0; j < lexicon.length && universalMatches.length < 8; j++) { | |
| if (lexicon[j].script === 'universal' && uChars.includes(lexicon[j].lemma)) { | |
| universalMatches.push(lexicon[j]); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| if (nuosuScored.length) { | |
| nuosuScored.sort((a, b) => b[0] - a[0]); | |
| nuosuMatches.push(...nuosuScored.slice(0, 8).map(x => x[1])); | |
| } | |
| if (hasChinese && !nuosuText && nuosuMatches.length) { | |
| const best = nuosuMatches[0]; | |
| nuosuText = best.lemma; | |
| pinyinText = best.pinyin; | |
| ipaText = best.ipa; | |
| const oldRes = getSichuanOldForNuosu(nuosuText); | |
| sichuanPrimary = oldRes.primary; | |
| sichuanVariants = oldRes.variants; | |
| } | |
| } | |
| return { | |
| query: q, | |
| nuosuText, | |
| pinyinText, | |
| ipaText, | |
| sichuanPrimary, | |
| sichuanVariants, | |
| nuosuMatches, | |
| universalMatches, | |
| saniMatches | |
| }; | |
| } | |
| root.YiScriptBridge = { | |
| SCRIPT_META, | |
| getSichuanOldForNuosu, | |
| convertInputToAllScripts | |
| }; | |
| })(window); | |