Skip to content

Commit 9598a1f

Browse files
committed
verb negation, is to be, and implement fixer on the translator
1 parent 490c943 commit 9598a1f

2 files changed

Lines changed: 58 additions & 4 deletions

File tree

src/translator/fixer.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { zip } from "@std/collections/zip";
22
import { mapNullable } from "../misc/misc.ts";
3+
import { AdverbVerb } from "./ast.ts";
34
import * as English from "./ast.ts";
45
import { FilteredError } from "./error.ts";
56
import * as Dictionary from "../dictionary/type.ts";
@@ -220,9 +221,17 @@ function fixComplement(complement: English.Complement): English.Complement {
220221
}
221222
}
222223
function fixAdverbVerb(adverbVerb: English.AdverbVerb): English.AdverbVerb {
224+
const notIndex = adverbVerb.preAdverbs.findIndex((adverb) => adverb.negative);
225+
const [not, adverbs] = adverbVerb.verb.type === "modal" && notIndex !== -1
226+
? [
227+
adverbVerb.preAdverbs[notIndex],
228+
adverbVerb.preAdverbs.toSpliced(notIndex, 1),
229+
]
230+
: [null, adverbVerb.preAdverbs];
223231
return {
224232
...adverbVerb,
225-
preAdverbs: fixMultipleAdverbs(adverbVerb.preAdverbs),
233+
preAdverbs: fixMultipleAdverbs(adverbs),
234+
postAdverb: not,
226235
};
227236
}
228237
function fixMultipleVerb(
@@ -234,7 +243,49 @@ function fixMultipleVerb(
234243
throw new FilteredError("modal verb after another verb");
235244
}
236245
}
237-
return newVerb;
246+
const first = newVerb[0];
247+
const notIndex = first.preAdverbs.findIndex((adverb) => adverb.negative);
248+
const newNewVerb: ReadonlyArray<AdverbVerb> =
249+
notIndex !== -1 && first.verb.type !== "modal" &&
250+
first.verb.presentSingular !== "is"
251+
? [
252+
{
253+
verb: {
254+
type: "non-modal",
255+
presentPlural: "do",
256+
presentSingular: "does",
257+
past: "did",
258+
reduplicationCount: 1,
259+
emphasis: false,
260+
},
261+
preAdverbs: [],
262+
postAdverb: first.preAdverbs[notIndex],
263+
},
264+
{
265+
...first,
266+
preAdverbs: first.preAdverbs.toSpliced(notIndex, 1),
267+
},
268+
...newVerb.slice(1),
269+
]
270+
: newVerb;
271+
return [
272+
newNewVerb[0],
273+
...newNewVerb
274+
.slice(1)
275+
.map((verb) =>
276+
verb.verb.type === "non-modal" && verb.verb.presentSingular === "is"
277+
? {
278+
...verb,
279+
verb: {
280+
...verb.verb,
281+
presentPlural: "be",
282+
presentSingular: "be",
283+
past: "been",
284+
},
285+
}
286+
: verb
287+
),
288+
];
238289
}
239290
function fixVerbPhrase(verb: English.VerbPhrase): English.VerbPhrase {
240291
switch (verb.type) {

src/translator/sentence.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as TokiPona from "../parser/ast.ts";
55
import { definitionAsPlainString } from "../translator_legacy/as_string.ts";
66
import * as English from "./ast.ts";
77
import { clause, contextClause, unwrapSingleWord } from "./clause.ts";
8+
import { fixMultipleSentences } from "./fixer.ts";
89
import { fromSimpleDefinition, getReduplicationCount } from "./word_unit.ts";
910
import { TranslationTodoError } from "./error.ts";
1011
import { noEmphasis, word } from "./word.ts";
@@ -216,7 +217,8 @@ export function multipleSentences(
216217
.map((definition): English.MultipleSentences => ({
217218
type: "free form",
218219
text: definition,
219-
}));
220+
}))
221+
.map(fixMultipleSentences);
220222
}
221223
case "sentences":
222224
return IterableResult.combine(
@@ -227,6 +229,7 @@ export function multipleSentences(
227229
.map((sentences): English.MultipleSentences => ({
228230
type: "sentences",
229231
sentences,
230-
}));
232+
}))
233+
.map(fixMultipleSentences);
231234
}
232235
}

0 commit comments

Comments
 (0)