diff --git a/src/english-conjugation.ts b/src/english-conjugation.ts new file mode 100644 index 0000000..f926958 --- /dev/null +++ b/src/english-conjugation.ts @@ -0,0 +1,60 @@ +export enum VerbForm { + First, + Third, + Plural, + Infinitive, + PresentParticiple, + PastParticiple, +} + +const irregularVerbs: Record = { + go: 'go goes went going gone', + do: 'do does did doing done', + be: 'are is were being been', + eat: 'eat eats ate eating eaten', + have: 'have has had having had', +}; + +export function conjugate(verb: string, person: VerbForm, past: boolean) { + if (person === VerbForm.Infinitive) { + return verb; + } + if (verb === 'be' && person == VerbForm.First) { + return 'am'; + } + if (verb === 'be' && person == VerbForm.Third && past) { + return 'was'; + } + const irr = irregularVerbs[verb]; + if (irr) { + const [go, goes, went, going, gone] = irr.split(' '); + if (person === VerbForm.PresentParticiple) { + return going; + } else if (person === VerbForm.PastParticiple) { + return gone; + } else if (past) { + return went; + } else if (person === VerbForm.Third) { + return goes; + } else { + return go; + } + } + if (person === VerbForm.PastParticiple || past) { + return verb.replace(/e$/, '') + 'ed'; + } else if (person === VerbForm.PresentParticiple) { + return verb.replace(/e$/, '') + 'ing'; + } else if (past) { + return verb.replace(/e$/, '') + 'ed'; + } else if (person === VerbForm.Third) { + if (/(s|sh|ch)$/.test(verb)) { + return verb + 'es'; + } else if (/y$/.test(verb)) { + return verb.replace(/y$/, 'ies'); + } else { + return verb + 's'; + } + } else { + return verb; + } +} diff --git a/src/english.ts b/src/english.ts index d19e1e4..421491f 100644 --- a/src/english.ts +++ b/src/english.ts @@ -2,6 +2,7 @@ import { Glosser } from './gloss'; import { parse } from './parse'; import { bare, clean } from './tokenize'; import { Branch, Label, Leaf, Tree, isQuestion } from './tree'; +import { VerbForm, conjugate } from './english-conjugation'; function leafText(tree: Tree): string { if (!('word' in tree)) { @@ -152,67 +153,113 @@ class ClauseTranslator { complementizer = 'if'; break; } - let tense: string = ''; + + let verbForm: VerbForm = VerbForm.Third; + let auxiliary: string = ''; + if (this.negative || this.toaqComplementizer === 'ma') { + auxiliary = 'do'; + verbForm = VerbForm.Infinitive; + } + const nt: string = this.negative ? "n't" : ''; + let postVerb: string = ''; + const past: boolean = this.toaqTense === 'pu'; + switch (this.toaqTense) { case 'pu': - tense = 'did'; break; case 'mala': - tense = 'has ever'; + auxiliary = 'have'; + postVerb = 'ever'; + verbForm = VerbForm.Infinitive; break; case 'sula': - tense = 'ever'; + auxiliary = 'do'; + postVerb = 'ever'; + verbForm = VerbForm.Infinitive; break; case 'jela': - tense = 'will ever'; + auxiliary = 'will'; + postVerb = 'ever'; + verbForm = VerbForm.Infinitive; break; case 'jıa': - tense = 'will'; + auxiliary = 'will'; + verbForm = VerbForm.Infinitive; break; } let aspect: string = ''; + let auxiliary2: string = ''; + let preVerb: string = ''; switch (this.toaqAspect) { case 'luı': - aspect = 'has'; - this.verb += '-en'; + if (!auxiliary || auxiliary === 'do') { + auxiliary = 'have'; + } else { + auxiliary2 = 'have'; + } + verbForm = VerbForm.PastParticiple; break; case 'chum': - aspect = 'is'; - this.verb += '-ing'; + if (!auxiliary || auxiliary === 'do') { + auxiliary = 'be'; + } else { + auxiliary2 = 'be'; + } + verbForm = VerbForm.PresentParticiple; break; case 'za': - aspect = 'is yet to'; + if (!auxiliary || auxiliary === 'do') { + auxiliary = 'be'; + } else { + auxiliary2 = 'be'; + } + preVerb = 'yet to'; + verbForm = VerbForm.Infinitive; break; case 'hoaı': - aspect = 'still'; + preVerb = 'still'; break; case 'haı': - aspect = 'already'; + preVerb = 'already'; break; case 'hıq': - aspect = 'just'; + if (auxiliary === 'do') { + auxiliary = 'have'; + } else { + auxiliary2 = 'have'; + } + preVerb = 'just'; + verbForm = VerbForm.PastParticiple; break; case 'fı': - aspect = 'is about to'; + if (!auxiliary || auxiliary === 'do') { + auxiliary = 'be'; + } else { + auxiliary2 = 'be'; + } + preVerb = 'about to'; + verbForm = VerbForm.Infinitive; break; } - let auxiliary: string = ''; - if (this.negative) { - auxiliary = "don't"; - } - let order: string[]; + if (auxiliary) { + auxiliary = conjugate(auxiliary, VerbForm.Third, past); + auxiliary += nt; + } + const verb = this.verb + ? conjugate(this.verb, verbForm, auxiliary ? false : past) + : ''; if (this.toaqComplementizer === 'ma') { - auxiliary ||= 'do'; order = [ - tense, - aspect, auxiliary, ...this.earlyAdjuncts, this.subject ?? '', - this.verb ?? '', + auxiliary2, + preVerb, + verb, + postVerb, ...this.objects, ...this.lateAdjuncts, ]; @@ -221,10 +268,11 @@ class ClauseTranslator { complementizer, ...this.earlyAdjuncts, this.subject ?? '', - tense, - aspect, auxiliary ?? '', - this.verb ?? '', + auxiliary2, + preVerb, + verb, + postVerb, ...this.objects, ...this.lateAdjuncts, ];