Skip to content

Commit

Permalink
Merge branch 'main' into uliloewi/main
Browse files Browse the repository at this point in the history
  • Loading branch information
graphemecluster committed Nov 27, 2024
2 parents b40fd9c + 11c80be commit a036be6
Show file tree
Hide file tree
Showing 28 changed files with 1,365 additions and 201 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build

on:
workflow_dispatch:
push:
branches: [main, dev, dev-*]
pull_request:
branches: [main]
release:
types: [created]

jobs:
build:
name: ${{ github.event_name == 'release' && 'Publish to NPM' || (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.repository == 'nk2028/tshet-uinh-examples' && github.ref == 'refs/heads/main')) && 'Publish to Tencent Cloud COS' || 'Test' }}
runs-on: ubuntu-latest
steps:
- name: Checkout latest code
uses: actions/checkout@v4

# Build
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Build
run: python build.py > index.js

# Test
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: https://registry.npmjs.org/
- name: Install Node.js dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Run tests
run: npm test

# Publish to NPM
- if: github.event_name == 'release'
name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}

# Publish to Tencent Cloud COS
- if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.repository == 'nk2028/tshet-uinh-examples' && github.ref == 'refs/heads/main')
name: Install coscmd
run: sudo pip install coscmd
- if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.repository == 'nk2028/tshet-uinh-examples' && github.ref == 'refs/heads/main')
name: Configure coscmd
env:
SECRET_ID: ${{ secrets.SecretId }}
SECRET_KEY: ${{ secrets.SecretKey }}
run: coscmd config -a $SECRET_ID -s $SECRET_KEY -b nk2028-1305783649 -r ap-guangzhou
- if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.repository == 'nk2028/tshet-uinh-examples' && github.ref == 'refs/heads/main')
name: Publish static files to COS
run: coscmd upload -rs --delete -f . /tshet-uinh-examples --ignore '*/.*,*/node_modules/*,./test/*,./build.py,./package.json,./package-lock.json'
43 changes: 0 additions & 43 deletions .github/workflows/publish-cos.yml

This file was deleted.

36 changes: 0 additions & 36 deletions .github/workflows/publish-npm.yml

This file was deleted.

35 changes: 0 additions & 35 deletions .github/workflows/test.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "ms-python.python"]
"recommendations": ["ms-python.python"]
}
40 changes: 20 additions & 20 deletions ayaka_v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* @author Ayaka
*/

/** @type { 音韻地位['屬於'] } */
const is = (...x) => 音韻地位.屬於(...x);
/** @type { 音韻地位['判斷'] } */
const when = (...x) => 音韻地位.判斷(...x);

// 1. 選項

if (!音韻地位) return [
Expand All @@ -21,21 +26,21 @@ if (!音韻地位) return [
description: ['true: 迥 ク𛅥ィ', 'false: 迥 クヱィ', '僅當開啓假名時生效'].join('\n'),
}],

['音變', [1, {value: null, text: '無'}, '現代日語'], {
['音變', [1, { value: null, text: '無' }, '現代日語'], {
description: [
"'無': 宙 チウ tiu;南 ダム dam;愁 スウ suu",
"'現代日語': 宙 チュウ tyuu;南 ダン dan;愁 スウ suu",
].join('\n'),
}],

// 參考:尉遲治平. 日本悉曇家所傳古漢語調值.
['聲調', [1, {value: null, text: '無'}, '四聲', '四聲(數字)', '四聲(調值)', '六聲(調值)', '六聲(符號)', '八聲', '八聲(數字)', '八聲(調值)']],
['聲調', [1, { value: null, text: '無' }, '四聲', '四聲(數字)', '四聲(調值)', '六聲(調值)', '六聲(符號)', '八聲', '八聲(數字)', '八聲(調值)']],
];

// 2. 輔助函數

const 假名表 = {
a: 'ア', i: 'イ', u: 'ウ', e: 'エ', o: 'オ',
a: 'ア', i: 'イ', u: 'ウ', e: 'エ', o: 'オ',
ka: 'カ', ki: 'キ', ku: 'ク', ke: 'ケ', ko: 'コ',
ga: 'ガ', gi: 'ギ', gu: 'グ', ge: 'ゲ', go: 'ゴ',
sa: 'サ', si: 'シ', su: 'ス', se: 'セ', so: 'ソ',
Expand All @@ -58,15 +63,15 @@ const 拗音表 = {
};

const 韻尾表 = {
'': '', i: 'イ', u: 'ウ',
m: 'ム', n: 'ン', ng: 'ゥ', // ng: 'ィ',
p: 'フ', t: 'ツ', k: 'ク', // k: 'キ',
'': '', 'i': 'イ', 'u': 'ウ',
'm': 'ム', 'n': 'ン', 'ng': 'ゥ', // ng: 'ィ',
'p': 'フ', 't': 'ツ', 'k': 'ク', // k: 'キ',
};

function roma2kata(s) {
const r = /^([kgsztdnpbmyrw]?w??[yw]?)([aiueo])([ptkmngiu]*)$/g; // 將音節分為韻頭、主要元音及韻尾
const match = r.exec(s);
if (match == null) {
if (match === null) {
throw new Error('無法轉換為假名:' + s);
}
const { 1: 韻頭, 2: 主要元音, 3: 韻尾 } = match;
Expand All @@ -84,15 +89,15 @@ function roma2kata(s) {

function kata2hira(s) {
const diff = 'ぁ'.charCodeAt(0) - 'ァ'.charCodeAt(0);
return [...s].map((c) => ({
return [...s].map(c => ({
'𛅤': '𛅐',
'𛅥': '𛅑',
'𛅦': '𛅒',
}[c] ?? String.fromCharCode(c.charCodeAt(0) + diff))).join('');
}

function small2large(s) {
return [...s].map((c) => ({
return [...s].map(c => ({
'𛅤': 'ヰ',
'𛅥': 'ヱ',
'𛅦': 'ヲ',
Expand All @@ -101,11 +106,6 @@ function small2large(s) {

// 3. 推導規則

/** @type { 音韻地位["屬於"] } */
const is = (...x) => 音韻地位.屬於(...x);
/** @type { 音韻地位["判斷"] } */
const when = (...x) => 音韻地位.判斷(...x);

function 聲母規則() {
return when([
// 脣音
Expand Down Expand Up @@ -336,7 +336,7 @@ function 韻母規則() {
let 聲母 = 聲母規則();
let 韻母 = 韻母規則();

if (is('入聲')) {
if (is`入聲`) {
if (韻母.endsWith('m')) 韻母 = 韻母.slice(0, -1) + 'p';
else if (韻母.endsWith('n')) 韻母 = 韻母.slice(0, -1) + 't';
else if (韻母.endsWith('ng')) 韻母 = 韻母.slice(0, -2) + 'k';
Expand Down Expand Up @@ -364,7 +364,7 @@ function 聲調規則() {
}

if (選項.聲調 === '六聲(符號)') {
if (is('入聲 全濁')) {
if (is`入聲 全濁`) {
if (韻母.endsWith('p')) 韻母 = 韻母.slice(0, -1) + 'b';
else if (韻母.endsWith('t')) 韻母 = 韻母.slice(0, -1) + 'd';
else if (韻母.endsWith('k')) 韻母 = 韻母.slice(0, -1) + 'g';
Expand Down Expand Up @@ -401,7 +401,7 @@ function 聲調規則() {

let 聲調 = 聲調規則();

if (韻母.startsWith('w') && (!is('牙喉音') || is('A類 或 以母'))) 韻母 = 韻母.slice(1);
if (韻母.startsWith('w') && is`非 牙喉音A類 或 以母`) 韻母 = 韻母.slice(1);

// 4. 音變規則

Expand Down Expand Up @@ -429,9 +429,9 @@ if (['平假名', '片假名'].includes(選項.書寫系統)) {
if (選項.音變 === '現代日語') {
if (聲母 === 'p') 聲母 = 'h'; // 甫 pu -> hu

if (韻母.endsWith('t')) 韻母 = 韻母 + 'u'; // 遏 at -> atu
else if (韻母.endsWith('ek')) 韻母 = 韻母 + 'i'; // 席 sek -> seki
else if (韻母.endsWith('k')) 韻母 = 韻母 + 'u'; // 澤 tak -> taku
if (韻母.endsWith('t')) 韻母 += 'u'; // 遏 at -> atu
else if (韻母.endsWith('ek')) 韻母 += 'i'; // 席 sek -> seki
else if (韻母.endsWith('k')) 韻母 += 'u'; // 澤 tak -> taku
}

if (選項.書寫系統 === '平文式羅馬字') {
Expand Down
7 changes: 5 additions & 2 deletions baxter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
* @author Ayaka
*/

/** @type { 音韻地位['屬於'] } */
const is = (...x) => 音韻地位.屬於(...x);
/** @type { 音韻地位['判斷'] } */
const when = (...x) => 音韻地位.判斷(...x);

if (!音韻地位) return [
// 版本可選 '1992' 或 '2014',預設值為 '2014'
['版本', [2, '1992', '2014']],
];

const is = (...x) => 音韻地位.屬於(...x);

let 聲母 = {
: 'p', : 'ph', : 'b', : 'm',
: 't', : 'th', : 'd', : 'n', : 'l',
Expand Down
Loading

0 comments on commit a036be6

Please sign in to comment.