Skip to content

Commit

Permalink
TP-rú-TP conjunction
Browse files Browse the repository at this point in the history
  • Loading branch information
lynn committed Sep 5, 2023
1 parent 6993c4b commit 7792ce4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
49 changes: 38 additions & 11 deletions src/english.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ function assertBranch(tree: Tree): asserts tree is Branch<Tree> {
}

function leafToEnglish(leaf: Tree): string {
const text = leafText(leaf);
if (text === '◌́') {
return 'the';
}
return new Glosser(true).glossWord(leafText(leaf));
}

function verbToEnglish(tree: Tree): string {
if ('word' in tree) {
return leafToEnglish(tree);
} else if ('left' in tree) {
if (tree.label === 'EvAP') {
let k = new ClauseTranslator();
k.processClause(tree.right);
return 'event of ' + k.emit();
}
const right = verbToEnglish(tree.right);
if (tree.label === 'mıP') {
return right.replace(/\b\w/, m => m.toUpperCase());
Expand Down Expand Up @@ -63,6 +72,7 @@ class ClauseTranslator {
objects: Constituent[] = [];
lateAdjuncts: string[] = [];
modals: string[] = [];
conjunct?: string = undefined;
constructor(toaqSpeechAct?: string) {
this.toaqSpeechAct = toaqSpeechAct;
}
Expand Down Expand Up @@ -131,9 +141,13 @@ class ClauseTranslator {
case "𝘷'":
node = node.right;
break;
case '&P':
this.conjunct = treeToEnglish(node.right).text;
node = node.left;
break;
default:
console.log(node);
throw new Error('unimplemented: ' + node.label);
throw new Error('unimplemented in processClause: ' + node.label);
}
} else {
throw new Error('unexpected leaf in clause');
Expand Down Expand Up @@ -252,28 +266,32 @@ class ClauseTranslator {
auxiliary += nt;
}
const verb = this.verb
? conjugate(this.verb, verbForm, auxiliary ? false : past)
? mode === 'DP'
? this.verb
: conjugate(this.verb, verbForm, auxiliary ? false : past)
: '';

const earlyAdjuncts = this.earlyAdjuncts.map(x => x + ',');
const subject = this.subject?.text ?? '';
const objects = this.objects.map(x => x.text);

if (this.toaqComplementizer === 'ma') {
order = [
auxiliary,
...this.earlyAdjuncts,
...earlyAdjuncts,
subject,
auxiliary2,
preVerb,
verb,
postVerb,
...objects,
...this.lateAdjuncts,
this.conjunct ?? '',
];
} else {
order = [
complementizer,
...this.earlyAdjuncts,
...earlyAdjuncts,
subject,
auxiliary ?? '',
auxiliary2,
Expand All @@ -282,6 +300,7 @@ class ClauseTranslator {
postVerb,
...objects,
...this.lateAdjuncts,
this.conjunct ?? '',
];
}

Expand Down Expand Up @@ -309,6 +328,11 @@ function branchToEnglish(tree: Branch<Tree>): Constituent {
translator.processCP(tree);
return { text: translator.emit() };
}
if (tree.label === 'TP') {
const translator = new ClauseTranslator();
translator.processClause(tree);
return { text: translator.emit() };
}
if (tree.label === 'DP') {
const d = tree.left;
const nP = tree.right as Branch<Tree>;
Expand All @@ -327,7 +351,9 @@ function branchToEnglish(tree: Branch<Tree>): Constituent {
assertBranch(tree.right);
const serial = tree.right.left;
const object = tree.right.right;
return { text: serialToEnglish(serial) + ' ' + treeToEnglish(object) };
return {
text: serialToEnglish(serial) + ' ' + treeToEnglish(object).text,
};
} else {
const serial = tree.right;
return { text: serialToEnglish(serial) + 'ly' };
Expand All @@ -352,14 +378,15 @@ function branchToEnglish(tree: Branch<Tree>): Constituent {
}
}
if (tree.label === '&P') {
assertBranch(tree.right);
return {
text:
treeToEnglish(tree.left).text +
' ' +
leafToEnglish(tree.right.left) +
' ' +
treeToEnglish(tree.right.right).text,
treeToEnglish(tree.left).text + ' ' + treeToEnglish(tree.right).text,
person: VerbForm.Plural,
};
}
if (tree.label === "&'") {
return {
text: leafToEnglish(tree.left) + ' ' + treeToEnglish(tree.right).text,
person: VerbForm.Plural,
};
}
Expand Down
10 changes: 6 additions & 4 deletions src/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,19 @@ const grammar: Grammar = {
{"name": "DP", "symbols": ["Focus", "DP"], "postprocess": makeBranch('FocusP')},
{"name": "nP", "symbols": ["nP", "CPrel"], "postprocess": makeBranch('nP')},
{"name": "nP", "symbols": ["CPdet"], "postprocess": makeBranchFunctionalLeft('nP', 'n')},
{"name": "Clause", "symbols": ["MTP"], "postprocess": id},
{"name": "Clause", "symbols": ["term", "Bi", "Clause"], "postprocess": make3L('TopicP', "Topic'")},
{"name": "Clause", "symbols": ["MTP"], "postprocess": id},
{"name": "Clause", "symbols": ["DP", "Na", "CPrelna"], "postprocess": make3L('𝘷P', "𝘷'")},
{"name": "Clause", "symbols": ["ModalP", "Na", "MTP"], "postprocess": make3L('𝘷P', "𝘷'")},
{"name": "ModalP", "symbols": ["ModalT4", "CPsub"], "postprocess": makeBranch('ModalP')},
{"name": "MTP", "symbols": ["TP"], "postprocess": id},
{"name": "MTP", "symbols": ["Modal", "TP"], "postprocess": makeT1ModalvP},
{"name": "MTP", "symbols": ["Sigma", "Modal", "TP"], "postprocess": makeSigmaT1ModalvP},
{"name": "MTP", "symbols": ["TP1"], "postprocess": id},
{"name": "MTP", "symbols": ["Modal", "TP1"], "postprocess": makeT1ModalvP},
{"name": "MTP", "symbols": ["Sigma", "Modal", "TP1"], "postprocess": makeSigmaT1ModalvP},
{"name": "MTPdet", "symbols": ["TPdet"], "postprocess": id},
{"name": "MTPdet", "symbols": ["Modal", "TPdet"], "postprocess": makeT1ModalvP},
{"name": "MTPdet", "symbols": ["Sigma", "Modal", "TPdet"], "postprocess": makeSigmaT1ModalvP},
{"name": "TP1", "symbols": ["TP"], "postprocess": id},
{"name": "TP1", "symbols": ["TP", "Conjunction", "TP1"], "postprocess": makeConn},
{"name": "TP", "symbols": ["AspP"], "postprocess": makeBranchCovertLeft('TP', 'T')},
{"name": "TP", "symbols": ["T1", "AspP"], "postprocess": makeBranch('TP')},
{"name": "TP", "symbols": ["Sigma", "T1", "AspP"], "postprocess": make3L('ΣP', 'TP')},
Expand Down
12 changes: 7 additions & 5 deletions src/toaq.ne
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ nP -> nP CPrel {% makeBranch('nP') %}
# (sá) ∅ hao
nP -> CPdet {% makeBranchFunctionalLeft('nP', 'n') %}

# pu hao
Clause -> MTP {% id %}
# ní bï pu hao
Clause -> term Bi Clause {% make3L('TopicP', "Topic'") %}
# pu hao
Clause -> MTP {% id %}
# jí nä pu hao hóa
Clause -> DP Na CPrelna {% make3L('𝘷P', "𝘷'") %}
# shê ꝡä hao nä jıa hao
Expand All @@ -75,16 +75,18 @@ ModalP -> ModalT4 CPsub {% makeBranch('ModalP') %}
# "MTP" is a TP that can have a t1 modal in front.

# ao pu chum hao jí
MTP -> TP {% id %}
MTP -> Modal TP {% makeT1ModalvP %}
MTP -> Sigma Modal TP {% makeSigmaT1ModalvP %}
MTP -> TP1 {% id %}
MTP -> Modal TP1 {% makeT1ModalvP %}
MTP -> Sigma Modal TP1 {% makeSigmaT1ModalvP %}

# (sá) ao hao
MTPdet -> TPdet {% id %}
MTPdet -> Modal TPdet {% makeT1ModalvP %}
MTPdet -> Sigma Modal TPdet {% makeSigmaT1ModalvP %}

# pu chum hao jí
TP1 -> TP {% id %}
TP1 -> TP Conjunction TP1 {% makeConn %}
TP -> AspP {% makeBranchCovertLeft('TP', 'T') %}
TP -> T1 AspP {% makeBranch('TP') %}
TP -> Sigma T1 AspP {% make3L('ΣP', 'TP') %}
Expand Down

0 comments on commit 7792ce4

Please sign in to comment.