Skip to content

Commit 881051c

Browse files
authored
Merge pull request #6 from neverRare/master
0.1.0
2 parents c53894c + 3eb3b29 commit 881051c

File tree

4 files changed

+114
-31
lines changed

4 files changed

+114
-31
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 0.1.0
4+
5+
- Add "(adjective) in (adjective) way" translation.
6+
- Handle complicated phrase as error.
7+
- Rearrange output to make adjective phrase appear first.
8+
- Add basic "la" translation: "given X, Y" and "if X, then Y".
9+
- Fix multiple _o_ error being triggered when there's only one _o_.
10+
- Update translation list:
11+
- _ante_ – change "other" into "different", "different" have broader meaning than "other".
12+
313
## 0.0.2
414

515
For this version. Major bugs related to phrase translation has been fixed. The translation lists has been updated as well.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ These are the terminology used in [limitations]
3636

3737
The following are currently unrecognized (non-definitive but pedantic).
3838

39+
- Full sentences: It can only translate phrases for now. The following limitations pretends the translator can translate full sentences, this is because these are planned limitations.
3940
- Non-pu vocabulary with exception to "pu" ("tonsi" is included in the vocabulary)
4041
- Multiple sentences
4142
- Comma as sentence separator (commas are treated as decoration and ignored)

main.js

Lines changed: 102 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ const ADJECTIVE = {
268268
ale: ["all"],
269269
ali: ["all"],
270270
anpa: ["bottom"],
271-
ante: ["other"],
271+
ante: ["different", "other"],
272272
awen: ["staying"],
273273
esun: [],
274274
ijo: [],
@@ -521,9 +521,11 @@ function translatePhraseToAdverb(phrase) {
521521
return translations;
522522
}
523523
/**
524-
* translates phrase into adjective
524+
* translates phrase into adjective without "in X way"
525+
*
526+
* this doesn't handle whole phrase emphasis
525527
*/
526-
function translatePhraseToAdjective(phrase) {
528+
function translatePhraseToSimpleAdjective(phrase) {
527529
let translations = ADJECTIVE[phrase.headword].slice();
528530
if (phrase.emphasis === "headword") {
529531
translations = translations.flatMap((word) => [`so ${word}`, `(${word})`]);
@@ -548,16 +550,13 @@ function translatePhraseToAdjective(phrase) {
548550
break;
549551
case "pi":
550552
translations = translations.flatMap((word) =>
551-
translatePhraseToAdjective(modifier).map(
553+
translatePhraseToSimpleAdjective(modifier).map(
552554
(adverb) => `${adverb} ${word}`
553555
)
554556
);
555557
break;
556558
}
557559
}
558-
if (phrase.emphasis === "whole") {
559-
translations = translations.map((translation) => `(${translation})`);
560-
}
561560
return translations;
562561
}
563562
/**
@@ -599,7 +598,7 @@ function translatePhraseToSimpleNoun(phrase) {
599598
break;
600599
case "pi":
601600
translations = translations.flatMap((word) =>
602-
translatePhraseToAdjective(modifier).map(
601+
translatePhraseToSimpleAdjective(modifier).map(
603602
(adjective) => `${adjective} ${word}`
604603
)
605604
);
@@ -608,6 +607,52 @@ function translatePhraseToSimpleNoun(phrase) {
608607
}
609608
return translations;
610609
}
610+
/**
611+
* translates phrase into adjective phrase with "in X way"
612+
*/
613+
function translatePhraseToAdjective(phrase) {
614+
let translations = translatePhraseToSimpleAdjective(phrase);
615+
for (const [i, item] of phrase.modifiers.entries()) {
616+
const heads = translatePhraseToSimpleAdjective({
617+
...phrase,
618+
modifiers: [
619+
...phrase.modifiers.slice(0, i),
620+
...phrase.modifiers.slice(i + 1),
621+
],
622+
});
623+
switch (item.type) {
624+
case "proper word":
625+
continue;
626+
case "word":
627+
if (item.emphasized) {
628+
for (const head of heads) {
629+
for (const adjective of ADJECTIVE[item.word]) {
630+
translations.push(`${head} in (${adjective}) way`);
631+
}
632+
}
633+
} else {
634+
for (const head of heads) {
635+
for (const adjective of ADJECTIVE[item.word]) {
636+
translations.push(`${head} in ${adjective} way`);
637+
}
638+
}
639+
}
640+
break;
641+
case "pi":
642+
const phrases = translatePhraseToSimpleAdjective(item);
643+
for (const head of heads) {
644+
for (const phrase of phrases) {
645+
translations.push(`${head} in ${phrase} way`);
646+
}
647+
}
648+
break;
649+
}
650+
}
651+
if (phrase.emphasis === "whole") {
652+
translations = translations.map((translation) => `(${translation})`);
653+
}
654+
return translations;
655+
}
611656
/**
612657
* translates phrase into noun phrase with "of"s
613658
*/
@@ -654,43 +699,70 @@ function translatePhraseToNoun(phrase) {
654699
}
655700
return translations;
656701
}
657-
/**
658-
* translates clauses before la
659-
*/
660-
function translateLaClause(clause) {
661-
switch (clause.type) {
662-
case "phrase":
663-
const translations = translatePhraseToNoun(clause);
664-
if (translations.length === 0) {
665-
throw new UntranslatableError("complicated phrase");
666-
}
667-
return translations;
668-
default:
669-
throw new Error("todo");
670-
}
671-
}
702+
// /**
703+
// * translates clauses before la
704+
// */
705+
// function translateLaClause(clause) {
706+
// switch (clause.type) {
707+
// case "phrase":
708+
// const translations = [
709+
// ...translatePhraseToAdjective(clause),
710+
// ...translatePhraseToNoun(clause),
711+
// ];
712+
// if (translations.length === 0) {
713+
// throw new UntranslatableError("complicated phrase");
714+
// }
715+
// return translations;
716+
// default:
717+
// throw new Error("todo");
718+
// }
719+
// }
672720
/**
673721
* translates clauses after la or without la
674722
*/
675723
function translateFinalClause(clause) {
676724
switch (clause.type) {
677725
case "phrase":
678-
return [
679-
...translatePhraseToNoun(clause),
726+
const translations = [
680727
...translatePhraseToAdjective(clause),
728+
...translatePhraseToNoun(clause),
681729
];
730+
if (translations.length === 0) {
731+
throw new UntranslatableError("complicated phrase");
732+
}
733+
return translations;
682734
default:
683735
throw new Error("todo");
684736
}
685737
}
686738
/**
687739
* translates sentence without a or taso
688740
*/
689-
function translatePureSentence(sentence) {
690-
if (sentence.beforeLa.length > 0) {
691-
throw new Error("todo");
741+
function translatePureSentence(pureSentence) {
742+
let translations = [""];
743+
for (const beforeLa of pureSentence.beforeLa) {
744+
translations = translations.flatMap((sentence) => {
745+
switch (beforeLa.type) {
746+
case "phrase":
747+
return [
748+
...translatePhraseToAdjective(beforeLa).map(
749+
(translation) => `${sentence}if ${translation}, then `
750+
),
751+
...translatePhraseToNoun(beforeLa).map(
752+
(translation) => `${sentence}given ${translation}, `
753+
),
754+
];
755+
default:
756+
throw new Error("todo");
757+
}
758+
});
692759
}
693-
return translateFinalClause(sentence.sentence);
760+
translations = translations.flatMap((sentence) =>
761+
translateFinalClause(pureSentence.sentence).map(
762+
(translation) => `${sentence}${translation}`
763+
)
764+
);
765+
return translations;
694766
}
695767
function translateSentence(sentence) {
696768
let start;
@@ -893,7 +965,7 @@ function parseClause(array) {
893965
}
894966
throw new Error("todo");
895967
} else if (array.includes("o")) {
896-
if (array.slice(array.indexOf("o")).includes("o")) {
968+
if (array.slice(array.indexOf("o") + 1).includes("o")) {
897969
throw new UnrecognizedError('Multiple "o"s');
898970
}
899971
throw new Error("todo");

style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
body {
22
margin: 10px;
3-
font-family: sans-serif;
3+
font-family: Andika, sans-serif;
44
}
55
a {
66
color: #0057af;

0 commit comments

Comments
 (0)