Skip to content

Commit

Permalink
Merge pull request #6 from neverRare/master
Browse files Browse the repository at this point in the history
0.1.0
  • Loading branch information
neverRare authored Jan 11, 2024
2 parents c53894c + 3eb3b29 commit 881051c
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 31 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.1.0

- Add "(adjective) in (adjective) way" translation.
- Handle complicated phrase as error.
- Rearrange output to make adjective phrase appear first.
- Add basic "la" translation: "given X, Y" and "if X, then Y".
- Fix multiple _o_ error being triggered when there's only one _o_.
- Update translation list:
- _ante_ – change "other" into "different", "different" have broader meaning than "other".

## 0.0.2

For this version. Major bugs related to phrase translation has been fixed. The translation lists has been updated as well.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ These are the terminology used in [limitations]

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

- 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.
- Non-pu vocabulary with exception to "pu" ("tonsi" is included in the vocabulary)
- Multiple sentences
- Comma as sentence separator (commas are treated as decoration and ignored)
Expand Down
132 changes: 102 additions & 30 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ const ADJECTIVE = {
ale: ["all"],
ali: ["all"],
anpa: ["bottom"],
ante: ["other"],
ante: ["different", "other"],
awen: ["staying"],
esun: [],
ijo: [],
Expand Down Expand Up @@ -521,9 +521,11 @@ function translatePhraseToAdverb(phrase) {
return translations;
}
/**
* translates phrase into adjective
* translates phrase into adjective without "in X way"
*
* this doesn't handle whole phrase emphasis
*/
function translatePhraseToAdjective(phrase) {
function translatePhraseToSimpleAdjective(phrase) {
let translations = ADJECTIVE[phrase.headword].slice();
if (phrase.emphasis === "headword") {
translations = translations.flatMap((word) => [`so ${word}`, `(${word})`]);
Expand All @@ -548,16 +550,13 @@ function translatePhraseToAdjective(phrase) {
break;
case "pi":
translations = translations.flatMap((word) =>
translatePhraseToAdjective(modifier).map(
translatePhraseToSimpleAdjective(modifier).map(
(adverb) => `${adverb} ${word}`
)
);
break;
}
}
if (phrase.emphasis === "whole") {
translations = translations.map((translation) => `(${translation})`);
}
return translations;
}
/**
Expand Down Expand Up @@ -599,7 +598,7 @@ function translatePhraseToSimpleNoun(phrase) {
break;
case "pi":
translations = translations.flatMap((word) =>
translatePhraseToAdjective(modifier).map(
translatePhraseToSimpleAdjective(modifier).map(
(adjective) => `${adjective} ${word}`
)
);
Expand All @@ -608,6 +607,52 @@ function translatePhraseToSimpleNoun(phrase) {
}
return translations;
}
/**
* translates phrase into adjective phrase with "in X way"
*/
function translatePhraseToAdjective(phrase) {
let translations = translatePhraseToSimpleAdjective(phrase);
for (const [i, item] of phrase.modifiers.entries()) {
const heads = translatePhraseToSimpleAdjective({
...phrase,
modifiers: [
...phrase.modifiers.slice(0, i),
...phrase.modifiers.slice(i + 1),
],
});
switch (item.type) {
case "proper word":
continue;
case "word":
if (item.emphasized) {
for (const head of heads) {
for (const adjective of ADJECTIVE[item.word]) {
translations.push(`${head} in (${adjective}) way`);
}
}
} else {
for (const head of heads) {
for (const adjective of ADJECTIVE[item.word]) {
translations.push(`${head} in ${adjective} way`);
}
}
}
break;
case "pi":
const phrases = translatePhraseToSimpleAdjective(item);
for (const head of heads) {
for (const phrase of phrases) {
translations.push(`${head} in ${phrase} way`);
}
}
break;
}
}
if (phrase.emphasis === "whole") {
translations = translations.map((translation) => `(${translation})`);
}
return translations;
}
/**
* translates phrase into noun phrase with "of"s
*/
Expand Down Expand Up @@ -654,43 +699,70 @@ function translatePhraseToNoun(phrase) {
}
return translations;
}
/**
* translates clauses before la
*/
function translateLaClause(clause) {
switch (clause.type) {
case "phrase":
const translations = translatePhraseToNoun(clause);
if (translations.length === 0) {
throw new UntranslatableError("complicated phrase");
}
return translations;
default:
throw new Error("todo");
}
}
// /**
// * translates clauses before la
// */
// function translateLaClause(clause) {
// switch (clause.type) {
// case "phrase":
// const translations = [
// ...translatePhraseToAdjective(clause),
// ...translatePhraseToNoun(clause),
// ];
// if (translations.length === 0) {
// throw new UntranslatableError("complicated phrase");
// }
// return translations;
// default:
// throw new Error("todo");
// }
// }
/**
* translates clauses after la or without la
*/
function translateFinalClause(clause) {
switch (clause.type) {
case "phrase":
return [
...translatePhraseToNoun(clause),
const translations = [
...translatePhraseToAdjective(clause),
...translatePhraseToNoun(clause),
];
if (translations.length === 0) {
throw new UntranslatableError("complicated phrase");
}
return translations;
default:
throw new Error("todo");
}
}
/**
* translates sentence without a or taso
*/
function translatePureSentence(sentence) {
if (sentence.beforeLa.length > 0) {
throw new Error("todo");
function translatePureSentence(pureSentence) {
let translations = [""];
for (const beforeLa of pureSentence.beforeLa) {
translations = translations.flatMap((sentence) => {
switch (beforeLa.type) {
case "phrase":
return [
...translatePhraseToAdjective(beforeLa).map(
(translation) => `${sentence}if ${translation}, then `
),
...translatePhraseToNoun(beforeLa).map(
(translation) => `${sentence}given ${translation}, `
),
];
default:
throw new Error("todo");
}
});
}
return translateFinalClause(sentence.sentence);
translations = translations.flatMap((sentence) =>
translateFinalClause(pureSentence.sentence).map(
(translation) => `${sentence}${translation}`
)
);
return translations;
}
function translateSentence(sentence) {
let start;
Expand Down Expand Up @@ -893,7 +965,7 @@ function parseClause(array) {
}
throw new Error("todo");
} else if (array.includes("o")) {
if (array.slice(array.indexOf("o")).includes("o")) {
if (array.slice(array.indexOf("o") + 1).includes("o")) {
throw new UnrecognizedError('Multiple "o"s');
}
throw new Error("todo");
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
body {
margin: 10px;
font-family: sans-serif;
font-family: Andika, sans-serif;
}
a {
color: #0057af;
Expand Down

0 comments on commit 881051c

Please sign in to comment.