Skip to content

Commit b8cabd9

Browse files
committed
use numbers as english words for numbers less than 21
1 parent 8696cd4 commit b8cabd9

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/translator/modifier.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { determiner } from "./determiner.ts";
88
import { ExhaustedError, TranslationTodoError } from "./error.ts";
99
import { nanpa } from "./nanpa.ts";
1010
import { noun } from "./noun.ts";
11-
import { number } from "./number.ts";
11+
import { number, numberAsText } from "./number.ts";
1212
import { phrase } from "./phrase.ts";
1313
import { pronoun } from "./pronoun.ts";
1414
import { noEmphasis, word } from "./word.ts";
@@ -53,7 +53,7 @@ function defaultModifier(wordUnit: TokiPona.WordUnit) {
5353
type: "determiner",
5454
determiner: {
5555
determiner: word({
56-
word: `${number}`,
56+
word: numberAsText(number),
5757
reduplicationCount: 1,
5858
emphasis,
5959
}),

src/translator/number.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@ import { IterableResult } from "../compound.ts";
44
import { dictionary } from "../dictionary.ts";
55
import { FilteredError } from "./error.ts";
66

7+
const WORDS = [
8+
"zero",
9+
"one",
10+
"two",
11+
"three",
12+
"four",
13+
"five",
14+
"six",
15+
"seven",
16+
"eight",
17+
"nine",
18+
"ten",
19+
"eleven",
20+
"twelve",
21+
"thirteen",
22+
"fourteen",
23+
"fifteen",
24+
"sixteen",
25+
"seventeen",
26+
"eighteen",
27+
"nineteen",
28+
"twenty",
29+
];
730
function singleNumber(word: string) {
831
return IterableResult.fromArray(dictionary.get(word)!.definitions)
932
.filterMap((definition) =>
@@ -81,3 +104,10 @@ export function number(numbers: ReadonlyArray<string>): IterableResult<number> {
81104
return IterableResult.combine(...numbers.map(singleNumber))
82105
.flatMap(combineNumbers);
83106
}
107+
export function numberAsText(number: number): string {
108+
if (number <= 20) {
109+
return WORDS[number];
110+
} else {
111+
return `${number}`;
112+
}
113+
}

src/translator/word_unit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { adjective, compoundAdjective } from "./adjective.ts";
66
import * as English from "./ast.ts";
77
import { TranslationTodoError } from "./error.ts";
88
import { PartialNoun, partialNoun } from "./noun.ts";
9-
import { number } from "./number.ts";
9+
import { number, numberAsText } from "./number.ts";
1010
import { partialPronoun, Place } from "./pronoun.ts";
1111
import { PartialVerb, partialVerb } from "./verb.ts";
1212
import { word } from "./word.ts";
@@ -118,7 +118,7 @@ export function wordUnit(
118118
type: "noun",
119119
determiners: [],
120120
adjectives: [],
121-
singular: `${number}`,
121+
singular: numberAsText(number),
122122
plural: null,
123123
reduplicationCount: 1,
124124
emphasis: wordUnit.emphasis != null,

0 commit comments

Comments
 (0)