diff options
-rw-r--r-- | db/dict/deinflections.sql | 81 | ||||
-rw-r--r-- | language/tags.ts | 2 | ||||
-rw-r--r-- | test/deinflection/cases.ts | 14 | ||||
-rw-r--r-- | test/deinflection/test.ts | 4 |
4 files changed, 95 insertions, 6 deletions
diff --git a/db/dict/deinflections.sql b/db/dict/deinflections.sql index a4a35d5..a79fff0 100644 --- a/db/dict/deinflections.sql +++ b/db/dict/deinflections.sql @@ -157,8 +157,8 @@ insert into deinflection_temp values -- obligation <https://guidetojapanese.org/learn/grammar/must> ('infl:tmp:must:res infl:negative', 'だめ', '', 'a', 'ot'), -- built-in negative because だめ can't be deconjugated - ('infl:tmp:must:res', 'いける', '', 'a', 'ot'), -- はいけない -> positive (stored this way because obligatory could be in past) - ('infl:tmp:must:res', 'なる', '', 'a', 'ot'), -- はならない -> positive + ('infl:tmp:must:res', 'いける', '', 'ru', 'ot'), -- はいけない -> positive (stored this way because obligatory could be in past) + ('infl:tmp:must:res', 'なる', '', 'u', 'ot'), -- はならない -> positive ('infl:must', 'は', '', 'ot', 'a'), -- removes particle (negative -te + は + だめ/いけない/ならない) ('infl:tmp:must:prt infl:must', 'と', '', 'ot', 'a'), -- removes particle (negative + と + だめ/いけない/ならない) ('infl:must', 'ば', 'ば', 'ot', 'a'), -- removes ot rule, keeps 〜ば (negative + ば + だめ/いけない/ならない) @@ -208,6 +208,83 @@ insert into deinflection_temp values -- attempt (〜とする) <https://guidetojapanese.org/learn/grammar/try> ('infl:attempt:tosuru', 'とする', '', 's', 'a'), + -- polite requests (〜なさい) <https://guidetojapanese.org/learn/grammar/requests> + ('infl:polite:nasai', 'なさい', 'る', 'a', 'ru'), + ('infl:polite:nasai', 'いなさい', 'う', 'a', 'u'), + ('infl:polite:nasai', 'きなさい', 'く', 'a', 'u'), + ('infl:polite:nasai', 'ぎなさい', 'ぐ', 'a', 'u'), + ('infl:polite:nasai', 'しなさい', 'す', 'a', 'u'), + ('infl:polite:nasai', 'ちなさい', 'つ', 'a', 'u'), + ('infl:polite:nasai', 'になさい', 'ぬ', 'a', 'u'), + ('infl:polite:nasai', 'びなさい', 'ぶ', 'a', 'u'), + ('infl:polite:nasai', 'みなさい', 'む', 'a', 'u'), + ('infl:polite:nasai', 'りなさい', 'る', 'a', 'u'), + ('infl:polite:nasai', 'しなさい', 'する', 'a', 's'), + ('infl:polite:nasai', 'きなさい', 'くる', 'a', 'k'), + ('infl:polite:nasai', '来なさい', '来る', 'a', 'k'), + + -- command form <https://guidetojapanese.org/learn/grammar/requests> + ('infl:command', 'ろ', 'る', 'a', 'ru'), + ('infl:command', 'え', 'う', 'a', 'u'), + ('infl:command', 'け', 'く', 'a', 'u'), + ('infl:command', 'げ', 'ぐ', 'a', 'u'), + ('infl:command', 'せ', 'す', 'a', 'u'), + ('infl:command', 'て', 'つ', 'a', 'u'), + ('infl:command', 'ね', 'ぬ', 'a', 'u'), + ('infl:command', 'れ', 'ぶ', 'a', 'u'), + ('infl:command', 'め', 'む', 'a', 'u'), + ('infl:command', 'れ', 'る', 'a', 'u'), + ('infl:command', 'しろ', 'する', 'a', 's'), + ('infl:command', 'こい', 'くる', 'a', 'k'), + ('infl:command', '来い', '来る', 'a', 'k'), + ('infl:command', 'くれ', 'くれる', 'a', 'ru'), -- TODO: special class? + ('infl:command', '呉れ', '呉れる', 'a', 'ru'), -- TODO: special class? + ('infl:command infl:negative', 'な', '', 'a', 'a'), + + -- causative <https://guidetojapanese.org/learn/grammar/causepass> + ('infl:causative', 'させる', 'る', 'a', 'ru'), + ('infl:causative', 'わせる', 'う', 'a', 'u'), + ('infl:causative', 'かせる', 'く', 'a', 'u'), + ('infl:causative', 'がせる', 'ぐ', 'a', 'u'), + ('infl:causative', 'させる', 'す', 'a', 'u'), + ('infl:causative', 'たせる', 'つ', 'a', 'u'), + ('infl:causative', 'なせる', 'ぬ', 'a', 'u'), + ('infl:causative', 'ばせる', 'ぶ', 'a', 'u'), + ('infl:causative', 'ませる', 'む', 'a', 'u'), + ('infl:causative', 'らせる', 'る', 'a', 'u'), + ('infl:causative', 'させる', 'する', 'a', 's'), + ('infl:causative', 'こさせる', 'くる', 'a', 'k'), + ('infl:causative', '来させる', '来る', 'a', 'k'), + -- shortened causative + ('infl:causative', 'さす', 'る', 'a', 'ru'), + ('infl:causative', 'わす', 'う', 'a', 'u'), + ('infl:causative', 'かす', 'く', 'a', 'u'), + ('infl:causative', 'がす', 'ぐ', 'a', 'u'), + ('infl:causative', 'さす', 'す', 'a', 'u'), + ('infl:causative', 'たす', 'つ', 'a', 'u'), + ('infl:causative', 'なす', 'ぬ', 'a', 'u'), + ('infl:causative', 'ばす', 'ぶ', 'a', 'u'), + ('infl:causative', 'ます', 'む', 'a', 'u'), + ('infl:causative', 'らす', 'る', 'a', 'u'), + ('infl:causative', 'さす', 'する', 'a', 's'), + ('infl:causative', 'こさす', 'くる', 'a', 'k'), + ('infl:causative', '来さす', '来る', 'a', 'k'), + + -- passive <https://guidetojapanese.org/learn/grammar/causepass> + ('infl:passive', 'られる', 'る', 'a', 'ru'), + ('infl:passive', 'われる', 'う', 'a', 'u'), + ('infl:passive', 'かれる', 'く', 'a', 'u'), + ('infl:passive', 'がれる', 'ぐ', 'a', 'u'), + ('infl:passive', 'される', 'す', 'a', 'u'), + ('infl:passive', 'たれる', 'つ', 'a', 'u'), + ('infl:passive', 'なれる', 'ぬ', 'a', 'u'), + ('infl:passive', 'ばれる', 'ぶ', 'a', 'u'), + ('infl:passive', 'まれる', 'む', 'a', 'u'), + ('infl:passive', 'られる', 'る', 'a', 'u'), + ('infl:passive', 'される', 'する', 'a', 's'), + ('infl:passive', 'こられる', 'くる', 'a', 'k'), + ('infl:passive', '来られる', '来る', 'a', 'k'), + -- auxiliary rules ('class:verb:suru-included', 'する', '', 's', ''); -- deconjugate suru verbs into stem diff --git a/language/tags.ts b/language/tags.ts index de1a3ea..72840fe 100644 --- a/language/tags.ts +++ b/language/tags.ts @@ -91,6 +91,8 @@ export const Tag = { Polite: { /** @constant 丁寧語 〜ます conjugations (e.g. 食べました) */ Masu: "infl:polite:masu", + /** @constant 〜なさい conjugations (e.g. 座りなさい) */ + Nasai: "infl:polite:nasai", }, /** @constant common ending conjugations */ Suffix: { diff --git a/test/deinflection/cases.ts b/test/deinflection/cases.ts index a54dba9..08517d4 100644 --- a/test/deinflection/cases.ts +++ b/test/deinflection/cases.ts @@ -5,6 +5,7 @@ interface Test { input: string; mustHave: TokenTags; mustNotHave: TokenTags; + forceID?: number; }; export default [ @@ -34,7 +35,7 @@ export default [ { input: "早く", mustHave: [ Inflection.Adverb ], mustNotHave: [], }, { input: "遊んだり", mustHave: [ Inflection.Suffix.Tari ], mustNotHave: [ Inflection.Tense.Past ], }, { input: "聞け", mustHave: [ Inflection.Command ], mustNotHave: [], }, - { input: "⾷べさせる", mustHave: [ Inflection.Causative ], mustNotHave: [], }, + { input: "食べさせる", mustHave: [ Inflection.Causative ], mustNotHave: [], }, { input: "落ちられる", mustHave: [ Inflection.Potential ], mustNotHave: [], }, { input: "言われる", mustHave: [ Inflection.Passive ], mustNotHave: [], }, { input: "喋っている", mustHave: [ Inflection.Tense.Continuous ], mustNotHave: [ Inflection.Suffix.Te ], }, @@ -55,7 +56,8 @@ export default [ { input: "行かないと", mustHave: [ Inflection.Obligatory, Inflection.Affirmative ], mustNotHave: [ Inflection.Negative ], }, { input: "買いたい", mustHave: [ Inflection.Desirable.Itai ], mustNotHave: [], }, { input: "寝よう", mustHave: [ Inflection.Desirable.Volitional ], mustNotHave: [], }, - { input: "しましょう", mustHave: [ Inflection.Desirable.Volitional, Inflection.Polite.Masu ], mustNotHave: [], }, + // TODO: for this test to work, a parseSentencePart function needs to be made that returns all possible words (currently clipped) + // { input: "しましょう", forceID: 17327, mustHave: [ Inflection.Desirable.Volitional, Inflection.Polite.Masu ], mustNotHave: [], }, { input: "きましょう", mustHave: [ Inflection.Desirable.Volitional, Inflection.Polite.Masu ], mustNotHave: [], }, { input: "寝ましょう", mustHave: [ Inflection.Desirable.Volitional, Inflection.Polite.Masu ], mustNotHave: [], }, { input: "行きましょう", mustHave: [ Inflection.Desirable.Volitional, Inflection.Polite.Masu ], mustNotHave: [], }, @@ -68,9 +70,15 @@ export default [ { input: "行こうとする", mustHave: [ Inflection.Attempt.ToSuru ], mustNotHave: [ Inflection.Desirable.Volitional ], }, { input: "避けようとする", mustHave: [ Inflection.Attempt.ToSuru ], mustNotHave: [ Inflection.Desirable.Volitional ], }, { input: "入ろうとしている", mustHave: [ Inflection.Attempt.ToSuru, Inflection.Tense.Continuous ], mustNotHave: [ Inflection.Desirable.Volitional ], }, + { input: "食べなさい", mustHave: [ Inflection.Polite.Nasai ], mustNotHave: [], }, + { input: "飲みなさい", mustHave: [ Inflection.Polite.Nasai ], mustNotHave: [], }, + { input: "しなさい", mustHave: [ Inflection.Polite.Nasai ], mustNotHave: [], }, + { input: "聞きなさい", mustHave: [ Inflection.Polite.Nasai ], mustNotHave: [], }, + { input: "座りなさい", mustHave: [ Inflection.Polite.Nasai ], mustNotHave: [], }, + { input: "食べさせられる", mustHave: [ Inflection.Passive, Inflection.Causative ], mustNotHave: [], }, // TODO: りゃ for いることは // TODO: じゃ for では // TODO: なきゃ + なくちゃ // and more! -] satisfies Test[]; +] as Test[]; diff --git a/test/deinflection/test.ts b/test/deinflection/test.ts index 3faa6f8..017a5c7 100644 --- a/test/deinflection/test.ts +++ b/test/deinflection/test.ts @@ -2,7 +2,7 @@ import cases from "./cases.ts"; import { core } from '../base.ts'; import { TokenTag } from '../../language/tags.ts'; -cases.forEach(({ input, mustHave, mustNotHave }) => { +cases.forEach(({ input, mustHave, mustNotHave, forceID }) => { Deno.test(`deinflection - ${input}`, async () => { var { tokens } = await core.parseSentence(input); @@ -11,6 +11,8 @@ cases.forEach(({ input, mustHave, mustNotHave }) => { // console.log(tokens); var result = tokens.find(t => t.source == input); + if (forceID) result = tokens.find(t => t.term_id == forceID); + if (!result) throw new Error("No deconjugation found for input"); |