From 005cf449901d24469f632b9e3c66487d59f9e015 Mon Sep 17 00:00:00 2001 From: Lynn Date: Tue, 5 Sep 2023 19:47:23 +0200 Subject: [PATCH] =?UTF-8?q?Boxes=20support=20for=20TP-r=C3=BA-TP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/boxes.ts | 21 ++++++++++++++++++--- src/english.ts | 7 +------ src/tree.ts | 5 +++++ src/web/Boxes.tsx | 35 ++++++++++++++++++++++++++--------- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/boxes.ts b/src/boxes.ts index 8d68629..182f380 100644 --- a/src/boxes.ts +++ b/src/boxes.ts @@ -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 { @@ -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 { @@ -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; @@ -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 { diff --git a/src/english.ts b/src/english.ts index d86f3e0..c4dc22b 100644 --- a/src/english.ts +++ b/src/english.ts @@ -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 { @@ -18,11 +18,6 @@ function leafText(tree: Tree): string { return tree.word.text; } -function assertBranch(tree: Tree): asserts tree is Branch { - if ('left' in tree) return; - throw new Error('Unexpected non-branch ' + tree.label); -} - function leafToEnglish(leaf: Tree): string { const text = leafText(leaf); if (text === '◌́') { diff --git a/src/tree.ts b/src/tree.ts index f2fd4bb..203c0c0 100644 --- a/src/tree.ts +++ b/src/tree.ts @@ -138,6 +138,11 @@ export type Tree = Leaf | Branch | Rose; export type StrictTree = Leaf | Branch; +export function assertBranch(tree: Tree): asserts tree is Branch { + 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); diff --git a/src/web/Boxes.tsx b/src/web/Boxes.tsx index 811bacb..b9f05e1 100644 --- a/src/web/Boxes.tsx +++ b/src/web/Boxes.tsx @@ -49,8 +49,32 @@ function PostFieldBox(props: { postField: PostField }) { ); } +function ClauseInner(props: { clause: BoxClause }) { + const { verbalComplex, postField, conjunction } = props.clause; + return ( + <> + +
{verbalComplex}
+
+ {postField.earlyAdjuncts.length + + postField.arguments.length + + postField.lateAdjuncts.length ? ( + + ) : undefined} + {conjunction && ( + <> + +
{conjunction.word}
+
+ + + )} + + ); +} + function ClauseBox(props: { clause: BoxClause }) { - const { complementizer, topic, verbalComplex, postField } = props.clause; + const { complementizer, topic } = props.clause; return ( @@ -61,14 +85,7 @@ function ClauseBox(props: { clause: BoxClause }) {
{topic}
)} - -
{verbalComplex}
-
- {postField.earlyAdjuncts.length + - postField.arguments.length + - postField.lateAdjuncts.length ? ( - - ) : undefined} +
); }