Skip to content

Commit

Permalink
Boxes support for TP-rú-TP
Browse files Browse the repository at this point in the history
  • Loading branch information
lynn committed Sep 5, 2023
1 parent 7792ce4 commit 005cf44
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
21 changes: 18 additions & 3 deletions src/boxes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parse } from './parse';
import { Glosser } from './gloss';
import { inTone } from './tokenize';
import { Branch, Tree, isQuestion } from './tree';
import { Branch, Tree, assertBranch, isQuestion } from './tree';
import { Tone } from './types';

export interface PostField {
Expand All @@ -10,12 +10,18 @@ export interface PostField {
lateAdjuncts: string[];
}

export interface AndClause {
word: string;
clause: BoxClause;
}

export interface BoxClause {
/// If empty, means covert "ꝡa"
complementizer: string;
topic?: string;
verbalComplex: string;
postField: PostField;
conjunction?: AndClause;
}

export interface BoxSentence {
Expand Down Expand Up @@ -80,6 +86,7 @@ function boxifyClause(tree: Tree): BoxClause {
let topic: string | undefined = undefined;
let verbalComplexWords = [];
let postField: PostField | undefined = undefined;
let conjunction: AndClause | undefined = undefined;
const cp = skipFree(tree);
if (!('left' in cp)) throw new Error('bad CP?');
const c = cp.left;
Expand Down Expand Up @@ -114,16 +121,24 @@ function boxifyClause(tree: Tree): BoxClause {
w && verbalComplexWords.push(w);
node = node.right;
break;
case '&P':
assertBranch(node.right);
conjunction = {
word: words(node.right.left),
clause: boxifyClause(node.right.right),
};
node = node.left;
break;
default:
console.log(node);
throw new Error('unimplemented: ' + node.label);
throw new Error('unimplemented in boxifyClause: ' + node.label);
}
} else {
throw new Error('unexpected leaf in clause');
}
}
const verbalComplex = verbalComplexWords.join(' ').trim();
return { complementizer, topic, verbalComplex, postField };
return { complementizer, topic, verbalComplex, postField, conjunction };
}

export function boxify(tree: Tree): BoxSentence {
Expand Down
7 changes: 1 addition & 6 deletions src/english.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Glosser } from './gloss';
import { parse } from './parse';
import { bare, clean } from './tokenize';
import { Branch, Label, Leaf, Tree, isQuestion } from './tree';
import { Branch, Label, Leaf, Tree, assertBranch, isQuestion } from './tree';
import { VerbForm, conjugate } from './english-conjugation';

interface Constituent {
Expand All @@ -18,11 +18,6 @@ function leafText(tree: Tree): string {
return tree.word.text;
}

function assertBranch(tree: Tree): asserts tree is Branch<Tree> {
if ('left' in tree) return;
throw new Error('Unexpected non-branch ' + tree.label);
}

function leafToEnglish(leaf: Tree): string {
const text = leafText(leaf);
if (text === '◌́') {
Expand Down
5 changes: 5 additions & 0 deletions src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ export type Tree = Leaf | Branch<Tree> | Rose<Tree>;

export type StrictTree = Leaf | Branch<StrictTree>;

export function assertBranch(tree: Tree): asserts tree is Branch<Tree> {
if ('left' in tree) return;
throw new Error('Unexpected non-branch ' + tree.label);
}

export function makeWord([token]: [ToaqToken]): Word {
const lemmaForm = token.value.toLowerCase().normalize();
const bareWord = bare(token.value);
Expand Down
35 changes: 26 additions & 9 deletions src/web/Boxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,32 @@ function PostFieldBox(props: { postField: PostField }) {
);
}

function ClauseInner(props: { clause: BoxClause }) {
const { verbalComplex, postField, conjunction } = props.clause;
return (
<>
<Box color="green" label="Verbal complex">
<div className="boxes-toaq">{verbalComplex}</div>
</Box>
{postField.earlyAdjuncts.length +
postField.arguments.length +
postField.lateAdjuncts.length ? (
<PostFieldBox postField={postField} />
) : undefined}
{conjunction && (
<>
<Box color="gray" label="Conjunction">
<div className="boxes-toaq">{conjunction.word}</div>
</Box>
<ClauseInner clause={conjunction.clause} />
</>
)}
</>
);
}

function ClauseBox(props: { clause: BoxClause }) {
const { complementizer, topic, verbalComplex, postField } = props.clause;
const { complementizer, topic } = props.clause;
return (
<Box color="red" label="Clause">
<Box color="orange" label="Comp.">
Expand All @@ -61,14 +85,7 @@ function ClauseBox(props: { clause: BoxClause }) {
<div className="boxes-toaq">{topic}</div>
</Box>
)}
<Box color="green" label="Verbal complex">
<div className="boxes-toaq">{verbalComplex}</div>
</Box>
{postField.earlyAdjuncts.length +
postField.arguments.length +
postField.lateAdjuncts.length ? (
<PostFieldBox postField={postField} />
) : undefined}
<ClauseInner clause={props.clause} />
</Box>
);
}
Expand Down

0 comments on commit 005cf44

Please sign in to comment.