Skip to content

Commit

Permalink
Refactor Japanese ます, んかった form (FooSoft#1385)
Browse files Browse the repository at this point in the history
* refactor masu form

* normalize masu mai form

* add tests

* test false positives

* remove maseba

* change n past to n + ta

<rikaitan.link>MzFlODFmZTJkZGNlYTY2ZDAxMTVkYmRiMWUxNjU3YzQ3YTc0ZWZjNgo=</rikaitan.link>
  • Loading branch information
jason-ojisan committed Sep 2, 2024
1 parent 3f42fc3 commit 3960d09
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 93 deletions.
12 changes: 12 additions & 0 deletions benches/japanese-language-transformer.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ describe('japanese language transformer', () => {
'食べん',
'食べんかった',
'食べんばかり',
'食べますまい',
'食べましたら',
'食べますれば',
'食べませんかった',
];

const inflectionCombinations = [
Expand Down Expand Up @@ -151,6 +155,10 @@ describe('japanese language transformer', () => {
'こん',
'こんかった',
'こんばかり',
'きますまい',
'きましたら',
'きますれば',
'きませんかった',
];

const suruInflections = [
Expand Down Expand Up @@ -210,6 +218,10 @@ describe('japanese language transformer', () => {
'せん',
'せんかった',
'せんばかり',
'しますまい',
'しましたら',
'しますれば',
'しませんかった',
];

const kansaibenInflections = [
Expand Down
130 changes: 55 additions & 75 deletions ext/js/language/ja/japanese-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const conditions = {
},
],
isDictionaryForm: true,
subConditions: ['v5d', 'v5m', 'v5s'],
subConditions: ['v5d', 'v5s'],
},
'v5d': {
name: 'Godan verb, dictionary form',
Expand All @@ -88,10 +88,6 @@ const conditions = {
],
isDictionaryForm: false,
},
'v5m': {
name: 'Godan verb, polite (masu) form',
isDictionaryForm: false,
},
'v5s': {
name: 'Godan verb, short causative form',
isDictionaryForm: false,
Expand Down Expand Up @@ -136,6 +132,14 @@ const conditions = {
],
isDictionaryForm: true,
},
'-masu': {
name: 'Polite -masu ending',
isDictionaryForm: false,
},
'-masen': {
name: 'Polite negative -masen ending',
isDictionaryForm: false,
},
'-te': {
name: 'Intermediate -te endings for progressive or perfect tense',
isDictionaryForm: false,
Expand All @@ -152,6 +156,10 @@ const conditions = {
name: '-ta past form ending',
isDictionaryForm: false,
},
'-n': {
name: '-n negative ending',
isDictionaryForm: false,
},
'-na': {
name: 'Intermediate -na ending (imperative negative)',
isDictionaryForm: false,
Expand Down Expand Up @@ -194,6 +202,7 @@ export const japaneseTransforms = {
suffixInflection('べば', 'ぶ', ['-ba'], ['v5']),
suffixInflection('めば', 'む', ['-ba'], ['v5']),
suffixInflection('れば', 'る', ['-ba'], ['v1', 'v5', 'vk', 'vs', 'vz']),
suffixInflection('れば', '', ['-ba'], ['-masu']),
],
},
'-ya': {
Expand Down Expand Up @@ -535,6 +544,7 @@ export const japaneseTransforms = {
suffixInflection('副うたら', '副う', [], ['v5']),
suffixInflection('厭うたら', '厭う', [], ['v5']),
suffixInflection('のたもうたら', 'のたまう', [], ['v5']),
suffixInflection('ましたら', 'ます', [], ['-masu']),
],
},
'-tari': {
Expand Down Expand Up @@ -635,7 +645,7 @@ export const japaneseTransforms = {
suffixInflection('副うて', '副う', ['-te'], ['v5']),
suffixInflection('厭うて', '厭う', ['-te'], ['v5']),
suffixInflection('のたもうて', 'のたまう', ['-te'], ['v5']),
suffixInflection('まして', 'ます', [], ['v']),
suffixInflection('まして', 'ます', [], ['-masu']),
],
},
'-zu': {
Expand Down Expand Up @@ -712,54 +722,22 @@ export const japaneseTransforms = {
},
],
rules: [
suffixInflection('ん', 'る', [], ['v1']),
suffixInflection('かん', 'く', [], ['v5']),
suffixInflection('がん', 'ぐ', [], ['v5']),
suffixInflection('さん', 'す', [], ['v5']),
suffixInflection('たん', 'つ', [], ['v5']),
suffixInflection('なん', 'ぬ', [], ['v5']),
suffixInflection('ばん', 'ぶ', [], ['v5']),
suffixInflection('まん', 'む', [], ['v5']),
suffixInflection('らん', 'る', [], ['v5']),
suffixInflection('わん', 'う', [], ['v5']),
suffixInflection('ぜん', 'ずる', [], ['vz']),
suffixInflection('せん', 'する', [], ['vs']),
suffixInflection('為ん', '為る', [], ['vs']),
suffixInflection('こん', 'くる', [], ['vk']),
suffixInflection('来ん', '来る', [], ['vk']),
suffixInflection('來ん', '來る', [], ['vk']),
],
},
'-n past': {
name: '-n',
description: 'Past negative form of verbs; a sound change of ぬ.\n' +
'Usage: Attach んかった to the irrealis form (mizenkei) of verbs.\n' +
'する becomes せんかった',
i18n: [
{
language: 'ja',
name: '~んかった',
description: '打消の過去を示す。なかった。',
},
],
rules: [
suffixInflection('んかった', 'る', [], ['v1']),
suffixInflection('かんかった', 'く', [], ['v5']),
suffixInflection('がんかった', 'ぐ', [], ['v5']),
suffixInflection('さんかった', 'す', [], ['v5']),
suffixInflection('たんかった', 'つ', [], ['v5']),
suffixInflection('なんかった', 'ぬ', [], ['v5']),
suffixInflection('ばんかった', 'ぶ', [], ['v5']),
suffixInflection('まんかった', 'む', [], ['v5']),
suffixInflection('らんかった', 'る', [], ['v5']),
suffixInflection('わんかった', 'う', [], ['v5']),
suffixInflection('ぜんかった', 'ずる', [], ['vz']),
suffixInflection('せんかった', 'する', [], ['vs']),
suffixInflection('為んかった', '為る', [], ['vs']),
suffixInflection('こんかった', 'くる', [], ['vk']),
suffixInflection('来んかった', '来る', [], ['vk']),
suffixInflection('來んかった', '來る', [], ['vk']),
suffixInflection('ませんかった', 'ません', [], ['v']),
suffixInflection('ん', 'る', ['-n'], ['v1']),
suffixInflection('かん', 'く', ['-n'], ['v5']),
suffixInflection('がん', 'ぐ', ['-n'], ['v5']),
suffixInflection('さん', 'す', ['-n'], ['v5']),
suffixInflection('たん', 'つ', ['-n'], ['v5']),
suffixInflection('なん', 'ぬ', ['-n'], ['v5']),
suffixInflection('ばん', 'ぶ', ['-n'], ['v5']),
suffixInflection('まん', 'む', ['-n'], ['v5']),
suffixInflection('らん', 'る', ['-n'], ['v5']),
suffixInflection('わん', 'う', ['-n'], ['v5']),
suffixInflection('ぜん', 'ずる', ['-n'], ['vz']),
suffixInflection('せん', 'する', ['-n'], ['vs']),
suffixInflection('為ん', '為る', ['-n'], ['vs']),
suffixInflection('こん', 'くる', ['-n'], ['vk']),
suffixInflection('来ん', '来る', ['-n'], ['vk']),
suffixInflection('來ん', '來る', ['-n'], ['vk']),
],
},
'-nbakari': {
Expand Down Expand Up @@ -1090,7 +1068,7 @@ export const japaneseTransforms = {
suffixInflection('こない', 'くる', ['adj-i'], ['vk']),
suffixInflection('来ない', '来る', ['adj-i'], ['vk']),
suffixInflection('來ない', '來る', ['adj-i'], ['vk']),
suffixInflection('ません', 'ます', ['v'], ['v']),
suffixInflection('ません', 'ます', ['-masen'], ['-masu']),
],
},
'-sa': {
Expand Down Expand Up @@ -1188,8 +1166,9 @@ export const japaneseTransforms = {
suffixInflection('副うた', '副う', ['past'], ['v5']),
suffixInflection('厭うた', '厭う', ['past'], ['v5']),
suffixInflection('のたもうた', 'のたまう', ['past'], ['v5']),
suffixInflection('ました', 'ます', ['past'], ['v']),
suffixInflection('ませんでした', 'ません', ['past'], ['v']),
suffixInflection('ました', 'ます', ['past'], ['-masu']),
suffixInflection('でした', '', ['past'], ['-masen']),
suffixInflection('かった', '', ['past'], ['-masen', '-n']),
],
},
'-masu': {
Expand All @@ -1203,23 +1182,23 @@ export const japaneseTransforms = {
},
],
rules: [
suffixInflection('ます', 'る', ['v1'], ['v1']),
suffixInflection('います', 'う', ['v5m'], ['v5d', 'v5s']),
suffixInflection('きます', 'く', ['v5m'], ['v5d', 'v5s']),
suffixInflection('ぎます', 'ぐ', ['v5m'], ['v5d', 'v5s']),
suffixInflection('します', 'す', ['v5m'], ['v5d', 'v5s']),
suffixInflection('ちます', 'つ', ['v5m'], ['v5d', 'v5s']),
suffixInflection('にます', 'ぬ', ['v5m'], ['v5d', 'v5s']),
suffixInflection('びます', 'ぶ', ['v5m'], ['v5d', 'v5s']),
suffixInflection('みます', 'む', ['v5m'], ['v5d', 'v5s']),
suffixInflection('ります', 'る', ['v5m'], ['v5d', 'v5s']),
suffixInflection('じます', 'ずる', ['vz'], ['vz']),
suffixInflection('します', 'する', ['vs'], ['vs']),
suffixInflection('為ます', '為る', ['vs'], ['vs']),
suffixInflection('きます', 'くる', ['vk'], ['vk']),
suffixInflection('来ます', '来る', ['vk'], ['vk']),
suffixInflection('來ます', '來る', ['vk'], ['vk']),
suffixInflection('くあります', 'い', ['v'], ['adj-i']),
suffixInflection('ます', 'る', ['-masu'], ['v1']),
suffixInflection('います', 'う', ['-masu'], ['v5d', 'v5s']),
suffixInflection('きます', 'く', ['-masu'], ['v5d', 'v5s']),
suffixInflection('ぎます', 'ぐ', ['-masu'], ['v5d', 'v5s']),
suffixInflection('します', 'す', ['-masu'], ['v5d', 'v5s']),
suffixInflection('ちます', 'つ', ['-masu'], ['v5d', 'v5s']),
suffixInflection('にます', 'ぬ', ['-masu'], ['v5d', 'v5s']),
suffixInflection('びます', 'ぶ', ['-masu'], ['v5d', 'v5s']),
suffixInflection('みます', 'む', ['-masu'], ['v5d', 'v5s']),
suffixInflection('ります', 'る', ['-masu'], ['v5d', 'v5s']),
suffixInflection('じます', 'ずる', ['-masu'], ['vz']),
suffixInflection('します', 'する', ['-masu'], ['vs']),
suffixInflection('為ます', '為る', ['-masu'], ['vs']),
suffixInflection('きます', 'くる', ['-masu'], ['vk']),
suffixInflection('来ます', '来る', ['-masu'], ['vk']),
suffixInflection('來ます', '來る', ['-masu'], ['vk']),
suffixInflection('くあります', 'い', ['-masu'], ['adj-i']),
],
},
'potential': {
Expand Down Expand Up @@ -1307,7 +1286,7 @@ export const japaneseTransforms = {
suffixInflection('こよう', 'くる', [], ['vk']),
suffixInflection('来よう', '来る', [], ['vk']),
suffixInflection('來よう', '來る', [], ['vk']),
suffixInflection('ましょう', 'ます', [], ['v']),
suffixInflection('ましょう', 'ます', [], ['-masu']),
suffixInflection('かろう', 'い', [], ['adj-i']),
],
},
Expand Down Expand Up @@ -1336,6 +1315,7 @@ export const japaneseTransforms = {
suffixInflection('こまい', 'くる', [], ['vk']),
suffixInflection('来まい', '来る', [], ['vk']),
suffixInflection('來まい', '來る', [], ['vk']),
suffixInflection('まい', '', [], ['-masu']),
],
},
'causative-passive': {
Expand Down
Loading

0 comments on commit 3960d09

Please sign in to comment.