Skip to content

Commit

Permalink
Better English verb conjugation grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
lynn committed Sep 4, 2023
1 parent 891af8a commit 3f7edd3
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 27 deletions.
60 changes: 60 additions & 0 deletions src/english-conjugation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
export enum VerbForm {
First,
Third,
Plural,
Infinitive,
PresentParticiple,
PastParticiple,
}

const irregularVerbs: Record<string, string> = {
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;
}
}
102 changes: 75 additions & 27 deletions src/english.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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,
];
Expand All @@ -221,10 +268,11 @@ class ClauseTranslator {
complementizer,
...this.earlyAdjuncts,
this.subject ?? '',
tense,
aspect,
auxiliary ?? '',
this.verb ?? '',
auxiliary2,
preVerb,
verb,
postVerb,
...this.objects,
...this.lateAdjuncts,
];
Expand Down

0 comments on commit 3f7edd3

Please sign in to comment.