Skip to content

Commit

Permalink
[ja] refactor irregular verbs + ksb -tari form (#1394)
Browse files Browse the repository at this point in the history
* add たまう irregular verb

* add たゆたう

* more irregular verbs

* add kansai-ben tari

* bench

* add 訪う

* remove 負う from irregular verbs

* remove incorrect irregular verbs

* fix

* function to generate irregular inflections

* Rename

* rename

* refactor

* lint

* naming
  • Loading branch information
khaitruong922 authored Sep 9, 2024
1 parent aaa1617 commit 6735039
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 104 deletions.
1 change: 1 addition & 0 deletions benches/japanese-language-transformer.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ describe('japanese language transformer', () => {
'買うて',
'買うた',
'買うたら',
'買うたり',
];

const basicTransformations = [...adjectiveInflections, ...verbInflections, ...inflectionCombinations];
Expand Down
126 changes: 54 additions & 72 deletions ext/js/language/ja/japanese-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,35 @@ const shimauEnglishDescription = '1. Shows a sense of regret/surprise when you d
const passiveEnglishDescription = '1. Indicates an action received from an action performer.\n' +
'2. Expresses respect for the subject of action performer.\n';

const ikuVerbs = ['いく', '行く', '逝く', '往く'];
const godanUSpecialVerbs = ['こう', 'とう', '請う', '乞う', '問う', '訪う', '宣う', '曰う', '給う', '賜う', '揺蕩う'];
const fuVerbTeConjugations = [
['のたまう', 'のたもう'],
['たまう', 'たもう'],
['たゆたう', 'たゆとう'],
];

/** @typedef {keyof typeof conditions} Condition */
/**
* @param {'て' | 'た' | 'たら' | 'たり'} suffix
* @param {Condition[]} conditionsIn
* @param {Condition[]} conditionsOut
* @returns {import('language-transformer').SuffixRule<Condition>[]}
*/
function irregularVerbInflections(suffix, conditionsIn, conditionsOut) {
const inflections = [];
for (const verb of ikuVerbs) {
inflections.push(suffixInflection(`${verb[0]}${suffix}`, verb, conditionsIn, conditionsOut));
}
for (const verb of godanUSpecialVerbs) {
inflections.push(suffixInflection(`${verb}${suffix}`, verb, conditionsIn, conditionsOut));
}
for (const [verb, teRoot] of fuVerbTeConjugations) {
inflections.push(suffixInflection(`${teRoot}${suffix}`, verb, conditionsIn, conditionsOut));
}
return inflections;
}

const conditions = {
'v': {
name: 'Verb',
Expand Down Expand Up @@ -526,24 +555,7 @@ export const japaneseTransforms = {
suffixInflection('きたら', 'くる', [], ['vk']),
suffixInflection('来たら', '来る', [], ['vk']),
suffixInflection('來たら', '來る', [], ['vk']),
suffixInflection('いったら', 'いく', [], ['v5']),
suffixInflection('おうたら', 'おう', [], ['v5']),
suffixInflection('こうたら', 'こう', [], ['v5']),
suffixInflection('そうたら', 'そう', [], ['v5']),
suffixInflection('とうたら', 'とう', [], ['v5']),
suffixInflection('行ったら', '行く', [], ['v5']),
suffixInflection('逝ったら', '逝く', [], ['v5']),
suffixInflection('往ったら', '往く', [], ['v5']),
suffixInflection('請うたら', '請う', [], ['v5']),
suffixInflection('乞うたら', '乞う', [], ['v5']),
suffixInflection('恋うたら', '恋う', [], ['v5']),
suffixInflection('問うたら', '問う', [], ['v5']),
suffixInflection('負うたら', '負う', [], ['v5']),
suffixInflection('沿うたら', '沿う', [], ['v5']),
suffixInflection('添うたら', '添う', [], ['v5']),
suffixInflection('副うたら', '副う', [], ['v5']),
suffixInflection('厭うたら', '厭う', [], ['v5']),
suffixInflection('のたもうたら', 'のたまう', [], ['v5']),
...irregularVerbInflections('たら', [], ['v5']),
suffixInflection('ましたら', 'ます', [], ['-masu']),
],
},
Expand Down Expand Up @@ -577,24 +589,7 @@ export const japaneseTransforms = {
suffixInflection('きたり', 'くる', [], ['vk']),
suffixInflection('来たり', '来る', [], ['vk']),
suffixInflection('來たり', '來る', [], ['vk']),
suffixInflection('いったり', 'いく', [], ['v5']),
suffixInflection('おうたり', 'おう', [], ['v5']),
suffixInflection('こうたり', 'こう', [], ['v5']),
suffixInflection('そうたり', 'そう', [], ['v5']),
suffixInflection('とうたり', 'とう', [], ['v5']),
suffixInflection('行ったり', '行く', [], ['v5']),
suffixInflection('逝ったり', '逝く', [], ['v5']),
suffixInflection('往ったり', '往く', [], ['v5']),
suffixInflection('請うたり', '請う', [], ['v5']),
suffixInflection('乞うたり', '乞う', [], ['v5']),
suffixInflection('恋うたり', '恋う', [], ['v5']),
suffixInflection('問うたり', '問う', [], ['v5']),
suffixInflection('負うたり', '負う', [], ['v5']),
suffixInflection('沿うたり', '沿う', [], ['v5']),
suffixInflection('添うたり', '添う', [], ['v5']),
suffixInflection('副うたり', '副う', [], ['v5']),
suffixInflection('厭うたり', '厭う', [], ['v5']),
suffixInflection('のたもうたり', 'のたまう', [], ['v5']),
...irregularVerbInflections('たり', [], ['v5']),
],
},
'-te': {
Expand Down Expand Up @@ -627,24 +622,7 @@ export const japaneseTransforms = {
suffixInflection('きて', 'くる', ['-te'], ['vk']),
suffixInflection('来て', '来る', ['-te'], ['vk']),
suffixInflection('來て', '來る', ['-te'], ['vk']),
suffixInflection('いって', 'いく', ['-te'], ['v5']),
suffixInflection('おうて', 'おう', ['-te'], ['v5']),
suffixInflection('こうて', 'こう', ['-te'], ['v5']),
suffixInflection('そうて', 'そう', ['-te'], ['v5']),
suffixInflection('とうて', 'とう', ['-te'], ['v5']),
suffixInflection('行って', '行く', ['-te'], ['v5']),
suffixInflection('逝って', '逝く', ['-te'], ['v5']),
suffixInflection('往って', '往く', ['-te'], ['v5']),
suffixInflection('請うて', '請う', ['-te'], ['v5']),
suffixInflection('乞うて', '乞う', ['-te'], ['v5']),
suffixInflection('恋うて', '恋う', ['-te'], ['v5']),
suffixInflection('問うて', '問う', ['-te'], ['v5']),
suffixInflection('負うて', '負う', ['-te'], ['v5']),
suffixInflection('沿うて', '沿う', ['-te'], ['v5']),
suffixInflection('添うて', '添う', ['-te'], ['v5']),
suffixInflection('副うて', '副う', ['-te'], ['v5']),
suffixInflection('厭うて', '厭う', ['-te'], ['v5']),
suffixInflection('のたもうて', 'のたまう', ['-te'], ['v5']),
...irregularVerbInflections('て', ['-te'], ['v5']),
suffixInflection('まして', 'ます', [], ['-masu']),
],
},
Expand Down Expand Up @@ -1180,24 +1158,7 @@ export const japaneseTransforms = {
suffixInflection('きた', 'くる', ['past'], ['vk']),
suffixInflection('来た', '来る', ['past'], ['vk']),
suffixInflection('來た', '來る', ['past'], ['vk']),
suffixInflection('いった', 'いく', ['past'], ['v5']),
suffixInflection('おうた', 'おう', ['past'], ['v5']),
suffixInflection('こうた', 'こう', ['past'], ['v5']),
suffixInflection('そうた', 'そう', ['past'], ['v5']),
suffixInflection('とうた', 'とう', ['past'], ['v5']),
suffixInflection('行った', '行く', ['past'], ['v5']),
suffixInflection('逝った', '逝く', ['past'], ['v5']),
suffixInflection('往った', '往く', ['past'], ['v5']),
suffixInflection('請うた', '請う', ['past'], ['v5']),
suffixInflection('乞うた', '乞う', ['past'], ['v5']),
suffixInflection('恋うた', '恋う', ['past'], ['v5']),
suffixInflection('問うた', '問う', ['past'], ['v5']),
suffixInflection('負うた', '負う', ['past'], ['v5']),
suffixInflection('沿うた', '沿う', ['past'], ['v5']),
suffixInflection('添うた', '添う', ['past'], ['v5']),
suffixInflection('副うた', '副う', ['past'], ['v5']),
suffixInflection('厭うた', '厭う', ['past'], ['v5']),
suffixInflection('のたもうた', 'のたまう', ['past'], ['v5']),
...irregularVerbInflections('た', ['past'], ['v5']),
suffixInflection('ました', 'ます', ['past'], ['-masu']),
suffixInflection('でした', '', ['past'], ['-masen']),
suffixInflection('かった', '', ['past'], ['-masen', '-n']),
Expand Down Expand Up @@ -1634,6 +1595,27 @@ export const japaneseTransforms = {
suffixInflection('ゆうたら', 'いったら', [], []),
],
},
'kansai-ben -tari': {
name: 'kansai-ben',
description: '-tari form of kansai-ben terms',
rules: [
suffixInflection('うたり', 'ったり', [], []),
suffixInflection('おうたり', 'あったり', [], []),
suffixInflection('こうたり', 'かったり', [], []),
suffixInflection('ごうたり', 'がったり', [], []),
suffixInflection('そうたり', 'さったり', [], []),
suffixInflection('ぞうたり', 'ざったり', [], []),
suffixInflection('とうたり', 'たったり', [], []),
suffixInflection('どうたり', 'だったり', [], []),
suffixInflection('のうたり', 'なったり', [], []),
suffixInflection('ほうたり', 'はったり', [], []),
suffixInflection('ぼうたり', 'ばったり', [], []),
suffixInflection('もうたり', 'まったり', [], []),
suffixInflection('ろうたり', 'らったり', [], []),
suffixInflection('ようたり', 'やったり', [], []),
suffixInflection('ゆうたり', 'いったり', [], []),
],
},
'kansai-ben -ku': {
name: 'kansai-ben',
description: '-ku stem of kansai-ben adjectives',
Expand Down
75 changes: 43 additions & 32 deletions test/language/japanese-transforms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1261,61 +1261,63 @@ const tests = [
{term: 'のたまう', source: 'のたもうたら', rule: 'v5', reasons: ['-tara']},
{term: 'のたまう', source: 'のたもうたり', rule: 'v5', reasons: ['-tari']},

{term: 'おう', source: 'おうて', rule: 'v5', reasons: ['-te']},
{term: '宣う', source: '宣うて', rule: 'v5', reasons: ['-te']},
{term: '宣う', source: '宣うた', rule: 'v5', reasons: ['-ta']},
{term: '宣う', source: '宣うたら', rule: 'v5', reasons: ['-tara']},
{term: '宣う', source: '宣うたり', rule: 'v5', reasons: ['-tari']},

{term: '曰う', source: '曰うて', rule: 'v5', reasons: ['-te']},
{term: '曰う', source: '曰うた', rule: 'v5', reasons: ['-ta']},
{term: '曰う', source: '曰うたら', rule: 'v5', reasons: ['-tara']},
{term: '曰う', source: '曰うたり', rule: 'v5', reasons: ['-tari']},

{term: 'たまう', source: 'たもうて', rule: 'v5', reasons: ['-te']},
{term: 'たまう', source: 'たもうた', rule: 'v5', reasons: ['-ta']},
{term: 'たまう', source: 'たもうたら', rule: 'v5', reasons: ['-tara']},
{term: 'たまう', source: 'たもうたり', rule: 'v5', reasons: ['-tari']},

{term: '給う', source: '給うて', rule: 'v5', reasons: ['-te']},
{term: '給う', source: '給うた', rule: 'v5', reasons: ['-ta']},
{term: '給う', source: '給うたら', rule: 'v5', reasons: ['-tara']},
{term: '給う', source: '給うたり', rule: 'v5', reasons: ['-tari']},

{term: '賜う', source: '賜うて', rule: 'v5', reasons: ['-te']},
{term: '賜う', source: '賜うた', rule: 'v5', reasons: ['-ta']},
{term: '賜う', source: '賜うたら', rule: 'v5', reasons: ['-tara']},
{term: '賜う', source: '賜うたり', rule: 'v5', reasons: ['-tari']},

{term: 'たゆたう', source: 'たゆとうて', rule: 'v5', reasons: ['-te']},
{term: 'たゆたう', source: 'たゆとうた', rule: 'v5', reasons: ['-ta']},
{term: 'たゆたう', source: 'たゆとうたら', rule: 'v5', reasons: ['-tara']},
{term: 'たゆたう', source: 'たゆとうたり', rule: 'v5', reasons: ['-tari']},

{term: 'こう', source: 'こうて', rule: 'v5', reasons: ['-te']},
{term: 'そう', source: 'そうて', rule: 'v5', reasons: ['-te']},
{term: 'とう', source: 'とうて', rule: 'v5', reasons: ['-te']},
{term: '請う', source: '請うて', rule: 'v5', reasons: ['-te']},
{term: '乞う', source: '乞うて', rule: 'v5', reasons: ['-te']},
{term: '恋う', source: '恋うて', rule: 'v5', reasons: ['-te']},
{term: '問う', source: '問うて', rule: 'v5', reasons: ['-te']},
{term: '負う', source: '負うて', rule: 'v5', reasons: ['-te']},
{term: '沿う', source: '沿うて', rule: 'v5', reasons: ['-te']},
{term: '添う', source: '添うて', rule: 'v5', reasons: ['-te']},
{term: '副う', source: '副うて', rule: 'v5', reasons: ['-te']},
{term: '厭う', source: '厭うて', rule: 'v5', reasons: ['-te']},
{term: '訪う', source: '訪うて', rule: 'v5', reasons: ['-te']},

{term: 'おう', source: 'おうた', rule: 'v5', reasons: ['-ta']},
{term: 'こう', source: 'こうた', rule: 'v5', reasons: ['-ta']},
{term: 'そう', source: 'そうた', rule: 'v5', reasons: ['-ta']},
{term: 'とう', source: 'とうた', rule: 'v5', reasons: ['-ta']},
{term: '請う', source: '請うた', rule: 'v5', reasons: ['-ta']},
{term: '乞う', source: '乞うた', rule: 'v5', reasons: ['-ta']},
{term: '恋う', source: '恋うた', rule: 'v5', reasons: ['-ta']},
{term: '問う', source: '問うた', rule: 'v5', reasons: ['-ta']},
{term: '負う', source: '負うた', rule: 'v5', reasons: ['-ta']},
{term: '沿う', source: '沿うた', rule: 'v5', reasons: ['-ta']},
{term: '添う', source: '添うた', rule: 'v5', reasons: ['-ta']},
{term: '副う', source: '副うた', rule: 'v5', reasons: ['-ta']},
{term: '厭う', source: '厭うた', rule: 'v5', reasons: ['-ta']},
{term: '訪う', source: '訪うた', rule: 'v5', reasons: ['-ta']},

{term: 'おう', source: 'おうたら', rule: 'v5', reasons: ['-tara']},
{term: 'こう', source: 'こうたら', rule: 'v5', reasons: ['-tara']},
{term: 'そう', source: 'そうたら', rule: 'v5', reasons: ['-tara']},
{term: 'とう', source: 'とうたら', rule: 'v5', reasons: ['-tara']},
{term: '請う', source: '請うたら', rule: 'v5', reasons: ['-tara']},
{term: '乞う', source: '乞うたら', rule: 'v5', reasons: ['-tara']},
{term: '恋う', source: '恋うたら', rule: 'v5', reasons: ['-tara']},
{term: '問う', source: '問うたら', rule: 'v5', reasons: ['-tara']},
{term: '負う', source: '負うたら', rule: 'v5', reasons: ['-tara']},
{term: '沿う', source: '沿うたら', rule: 'v5', reasons: ['-tara']},
{term: '添う', source: '添うたら', rule: 'v5', reasons: ['-tara']},
{term: '副う', source: '副うたら', rule: 'v5', reasons: ['-tara']},
{term: '厭う', source: '厭うたら', rule: 'v5', reasons: ['-tara']},
{term: '訪う', source: '訪うたら', rule: 'v5', reasons: ['-tara']},

{term: 'おう', source: 'おうたり', rule: 'v5', reasons: ['-tari']},
{term: 'こう', source: 'こうたり', rule: 'v5', reasons: ['-tari']},
{term: 'そう', source: 'そうたり', rule: 'v5', reasons: ['-tari']},
{term: 'とう', source: 'とうたり', rule: 'v5', reasons: ['-tari']},
{term: '請う', source: '請うたり', rule: 'v5', reasons: ['-tari']},
{term: '乞う', source: '乞うたり', rule: 'v5', reasons: ['-tari']},
{term: '恋う', source: '恋うたり', rule: 'v5', reasons: ['-tari']},
{term: '問う', source: '問うたり', rule: 'v5', reasons: ['-tari']},
{term: '負う', source: '負うたり', rule: 'v5', reasons: ['-tari']},
{term: '沿う', source: '沿うたり', rule: 'v5', reasons: ['-tari']},
{term: '添う', source: '添うたり', rule: 'v5', reasons: ['-tari']},
{term: '副う', source: '副うたり', rule: 'v5', reasons: ['-tari']},
{term: '厭う', source: '厭うたり', rule: 'v5', reasons: ['-tari']},
{term: '訪う', source: '訪うたり', rule: 'v5', reasons: ['-tari']},
],
},
{
Expand Down Expand Up @@ -1418,6 +1420,15 @@ const tests = [
{term: 'はう', source: 'ほうたら', rule: null, reasons: ['-tara', 'kansai-ben -tara']},
],
},
{
category: '-tari form of kansai-ben terms',
valid: true,
tests: [
{term: '買う', source: '買うたり', rule: null, reasons: ['-tari', 'kansai-ben -tari']},
{term: 'かう', source: 'こうたり', rule: null, reasons: ['-tari', 'kansai-ben -tari']},
{term: 'はう', source: 'ほうたり', rule: null, reasons: ['-tari', 'kansai-ben -tari']},
],
},
];
/* eslint-enable @stylistic/no-multi-spaces */

Expand Down

0 comments on commit 6735039

Please sign in to comment.