Skip to content

Commit 15b6af2

Browse files
committed
refactor
1 parent 95329e5 commit 15b6af2

File tree

3 files changed

+52
-51
lines changed

3 files changed

+52
-51
lines changed

src/translator/adjective.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,7 @@ export function compoundAdjective(
7474
adjective({ definition, reduplicationCount: 1, emphasis })
7575
),
7676
)
77-
.map((adjectives): English.AdjectivePhrase => ({
78-
type: "compound",
79-
conjunction: "and",
80-
adjectives,
81-
emphasis: false,
82-
}));
77+
.map((adjectives) => combineAdjective("and", adjectives));
8378
} else {
8479
return IterableResult.errors([
8580
new UntranslatableError("reduplication", "compound adjective"),
@@ -105,3 +100,24 @@ export function extractNegativeFromAdjective(
105100
}
106101
}
107102
}
103+
export function combineAdjective(
104+
conjunction: string,
105+
phrases: ReadonlyArray<English.AdjectivePhrase>,
106+
): English.AdjectivePhrase {
107+
return {
108+
type: "compound",
109+
conjunction,
110+
adjectives: phrases
111+
.flatMap((adjective) => {
112+
if (
113+
adjective.type === "compound" &&
114+
adjective.conjunction === conjunction
115+
) {
116+
return adjective.adjectives;
117+
} else {
118+
return [adjective];
119+
}
120+
}),
121+
emphasis: false,
122+
};
123+
}

src/translator/noun.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,24 @@ export function extractNegativeFromNoun(
170170
}
171171
}
172172
}
173+
export function combineNoun(
174+
conjunction: string,
175+
phrases: ReadonlyArray<English.NounPhrase>,
176+
): English.NounPhrase {
177+
const nouns = phrases
178+
.flatMap((noun) => {
179+
if (
180+
noun.type === "compound" &&
181+
noun.conjunction === conjunction
182+
) {
183+
return noun.nouns;
184+
} else {
185+
return [noun];
186+
}
187+
});
188+
return {
189+
type: "compound",
190+
conjunction,
191+
nouns,
192+
};
193+
}

src/translator/phrase.ts

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as TokiPona from "../parser/ast.ts";
44
import * as Composer from "../parser/composer.ts";
55
import {
66
AdjectiveWithInWay,
7+
combineAdjective,
78
extractNegativeFromAdjective,
89
} from "./adjective.ts";
910
import { extractNegativeFromMultipleAdverbs, NOT } from "./adverb.ts";
@@ -21,7 +22,12 @@ import {
2122
AdverbialModifier,
2223
multipleModifiers,
2324
} from "./modifier.ts";
24-
import { extractNegativeFromNoun, fromNounForms, PartialNoun } from "./noun.ts";
25+
import {
26+
combineNoun,
27+
extractNegativeFromNoun,
28+
fromNounForms,
29+
PartialNoun,
30+
} from "./noun.ts";
2531
import {
2632
extractNegativeFromPreposition,
2733
nounAsPreposition,
@@ -291,48 +297,6 @@ export function phrase(
291297
return IterableResult.errors([new TranslationTodoError(phrase.type)]);
292298
}
293299
}
294-
function compoundNoun(
295-
conjunction: string,
296-
phrases: ReadonlyArray<English.NounPhrase>,
297-
): English.NounPhrase {
298-
const nouns = phrases
299-
.flatMap((noun) => {
300-
if (
301-
noun.type === "compound" &&
302-
noun.conjunction === conjunction
303-
) {
304-
return noun.nouns;
305-
} else {
306-
return [noun];
307-
}
308-
});
309-
return {
310-
type: "compound",
311-
conjunction,
312-
nouns,
313-
};
314-
}
315-
function compoundAdjective(
316-
conjunction: string,
317-
phrases: ReadonlyArray<English.AdjectivePhrase>,
318-
): English.AdjectivePhrase {
319-
return {
320-
type: "compound",
321-
conjunction,
322-
adjectives: phrases
323-
.flatMap((adjective) => {
324-
if (
325-
adjective.type === "compound" &&
326-
adjective.conjunction === conjunction
327-
) {
328-
return adjective.adjectives;
329-
} else {
330-
return [adjective];
331-
}
332-
}),
333-
emphasis: false,
334-
};
335-
}
336300
export function phraseAsVerb(
337301
phrase: PhraseTranslation,
338302
): PartialVerb {
@@ -420,7 +384,7 @@ export function multiplePhrases(
420384
if (phrase.every((phrase) => phrase.type === "noun")) {
421385
return {
422386
type: "noun",
423-
noun: compoundNoun(
387+
noun: combineNoun(
424388
conjunction,
425389
phrase.map((phrase) => phrase.noun),
426390
),
@@ -431,7 +395,7 @@ export function multiplePhrases(
431395
} else {
432396
return {
433397
type: "adjective",
434-
adjective: compoundAdjective(
398+
adjective: combineAdjective(
435399
conjunction,
436400
phrase.map((phrase) => phrase.adjective),
437401
),

0 commit comments

Comments
 (0)