Skip to content

Commit

Permalink
The convert: boolean approach
Browse files Browse the repository at this point in the history
  • Loading branch information
lynn committed Sep 5, 2023
1 parent d4d1b3b commit 6b67a27
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 56 deletions.
6 changes: 3 additions & 3 deletions src/boxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function skipFree(tree: Tree): Tree {

function words(tree: Tree): string {
if ('word' in tree) {
if (tree.word === 'covert') {
if (tree.word.covert) {
return '';
} else {
return tree.word.text;
Expand Down Expand Up @@ -91,7 +91,7 @@ function boxifyClause(tree: Tree): BoxClause {
if (!('left' in cp)) throw new Error('bad CP?');
const c = cp.left;
if (!('word' in c)) throw new Error('C without word?');
if (c.word !== 'covert') {
if (!c.word.covert) {
complementizer = c.word.text;
}
for (let node = cp.right; ; ) {
Expand Down Expand Up @@ -149,7 +149,7 @@ export function boxify(tree: Tree): BoxSentence {
const sa = tree.right;
if (sa.label !== 'SA') throw new Error('SAP without SA?');
if (!('word' in sa)) throw new Error('SA without word?');
if (sa.word !== 'covert') {
if (!sa.word.covert) {
speechAct = sa.word.text;
}
const cp = tree.left;
Expand Down
2 changes: 1 addition & 1 deletion src/compact.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Branch, Leaf, Tree, nodeType } from './tree';

function isCovert(tree: Tree): boolean {
return 'word' in tree && typeof tree.word === 'string';
return 'word' in tree && tree.word.covert;
}

export function compact(tree: Tree): Tree {
Expand Down
5 changes: 2 additions & 3 deletions src/draw-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ export function placeLeaf(
ctx: CanvasRenderingContext2D,
leaf: Leaf | (Leaf & { denotation: Expr | null }),
): PlacedLeaf {
const gloss =
typeof leaf.word === 'string' ? undefined : leaf.word.entry?.gloss;
const gloss = leaf.word.covert ? undefined : leaf.word.entry?.gloss;
const label = getLabel(leaf);
const word = leaf.word === 'covert' ? leaf.value : leaf.word.text;
const word = leaf.word.covert ? leaf.word.value : leaf.word.text;
const denotation =
'denotation' in leaf && leaf.denotation !== null
? toPlainText(leaf.denotation)
Expand Down
6 changes: 3 additions & 3 deletions src/english.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function leafText(tree: Tree): string {
if (!('word' in tree)) {
throw new Error('Unexpected non-leaf ' + tree.label);
}
if (tree.word === 'covert') return '';
if (tree.word.covert) return '';
return tree.word.text;
}

Expand Down Expand Up @@ -47,7 +47,7 @@ function verbToEnglish(tree: Tree): string {
}

function serialToEnglish(serial: Tree): string {
if ('word' in serial && serial.word === 'covert') return '';
if ('word' in serial && serial.word.covert) return '';
if (serial.label !== '*Serial') throw new Error('non-*Serial serial');
if (!('children' in serial)) throw new Error('non-Rose serial');
return serial.children.map(x => verbToEnglish(x)).join('-');
Expand Down Expand Up @@ -363,7 +363,7 @@ function branchToEnglish(tree: Branch<Tree>): Constituent {
{ she: 'necessarily', ao: 'would', daı: 'possibly', ea: 'could' }[
bare(leafText(modal))
] ?? '?';
if (c.word === 'covert') {
if (c.word.covert) {
return { text: eng };
} else {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/latex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function toLatex(tree: Tree | DTree): string {
const children = tree.children.map(toLatex).join(' ');
return `[${label} ${children}]`;
} else {
if (tree.word === 'covert') {
if (tree.word.covert) {
return `[${label} [$\\varnothing$]]`;
}

Expand Down
14 changes: 7 additions & 7 deletions src/semantics/denote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,14 @@ function denoteLeaf(leaf: Leaf, cCommand: StrictTree | null): DTree {
let bindings = noBindings;

if (leaf.label === 'V') {
if (typeof leaf.word === 'string') throw new Error();
if (leaf.word.covert) throw new Error('covert V');
const entry = leaf.word.entry;
if (!entry) throw new Error();
if (entry.type !== 'predicate') throw new Error();

denotation = denoteVerb(entry.toaq, entry.frame.split(' ').length);
} else if (leaf.label === 'DP') {
if (leaf.word === 'covert') {
if (leaf.word.covert) {
denotation = hoa;
bindings = covertHoaBindings;
} else if (leaf.word.entry === undefined) {
Expand Down Expand Up @@ -518,8 +518,8 @@ function denoteLeaf(leaf: Leaf, cCommand: StrictTree | null): DTree {
};
} else if (leaf.label === '𝘷') {
let toaq: string | null;
if (leaf.word === 'covert') {
toaq = leaf.value;
if (leaf.word.covert) {
toaq = leaf.word.value;
} else if (leaf.word.entry === undefined) {
throw new Error(`Unrecognized 𝘷: ${leaf.word.text}`);
} else {
Expand All @@ -528,7 +528,7 @@ function denoteLeaf(leaf: Leaf, cCommand: StrictTree | null): DTree {
denotation = denoteLittleV(toaq);
} else if (leaf.label === 'Asp') {
let toaq: string;
if (leaf.word === 'covert') {
if (leaf.word.covert) {
toaq = 'tam';
} else if (leaf.word.entry === undefined) {
throw new Error(`Unrecognized Asp: ${leaf.word.text}`);
Expand All @@ -538,7 +538,7 @@ function denoteLeaf(leaf: Leaf, cCommand: StrictTree | null): DTree {

denotation = denoteAspect(toaq);
} else if (leaf.label === 'T') {
if (leaf.word === 'covert') {
if (leaf.word.covert) {
denotation = defaultTense;
} else if (leaf.word.entry === undefined) {
throw new Error(`Unrecognized T: ${leaf.word.text}`);
Expand All @@ -549,7 +549,7 @@ function denoteLeaf(leaf: Leaf, cCommand: StrictTree | null): DTree {
denotation = null;
} else if (leaf.label === 'SA') {
let toaq: string;
if (leaf.word === 'covert') {
if (leaf.word.covert) {
toaq = 'da'; // TODO: covert móq
} else if (leaf.word.entry === undefined) {
throw new Error(`Unrecognized SA: ${leaf.word.text}`);
Expand Down
25 changes: 12 additions & 13 deletions src/serial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Branch, Label, Tree } from './tree';

const arityPreservingVerbPrefixes: Label[] = ['buP', 'muP', 'buqP', 'geP'];

const pro: Tree = { label: 'DP', word: 'covert', value: 'PRO' };
const pro: Tree = { label: 'DP', word: { covert: true, value: 'PRO' } };

export function getFrame(verb: Tree): string {
if ('word' in verb) {
if (verb.word === 'covert') throw new Error('covert verb?');
if (verb.word.covert) throw new Error('covert verb?');
if (verb.word.entry?.type === 'predicate') {
return verb.word.entry.frame;
} else {
Expand Down Expand Up @@ -41,7 +41,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
if (arity === 1) {
return {
label: '𝘷P',
left: { label: '𝘷', word: 'covert', value: 'BE' },
left: { label: '𝘷', word: { covert: true, value: 'BE' } },
right: { label: 'VP', left: verbs[0], right: args[0] },
};
} else if (arity === 2) {
Expand All @@ -50,7 +50,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
left: args[0],
right: {
label: "𝘷'",
left: { label: '𝘷', word: 'covert', value: 'CAUSE' },
left: { label: '𝘷', word: { covert: true, value: 'CAUSE' } },
right: { label: 'VP', left: verbs[0], right: args[1] },
},
};
Expand All @@ -60,7 +60,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
left: args[0],
right: {
label: "𝘷'",
left: { label: '𝘷', word: 'covert', value: 'CAUSE' },
left: { label: '𝘷', word: { covert: true, value: 'CAUSE' } },
right: {
label: 'VP',
left: args[1],
Expand Down Expand Up @@ -94,7 +94,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
if (arity === 1) {
return {
label: '𝘷P',
left: { label: '𝘷', word: 'covert', value: 'BE' },
left: { label: '𝘷', word: { covert: true, value: 'BE' } },
right: { label: 'VP', left: verbs[0], right: inner },
};
} else if (arity === 2) {
Expand All @@ -103,7 +103,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
left: args[0],
right: {
label: "𝘷'",
left: { label: '𝘷', word: 'covert', value: 'CAUSE' },
left: { label: '𝘷', word: { covert: true, value: 'CAUSE' } },
right: { label: 'VP', left: verbs[0], right: inner },
},
};
Expand All @@ -113,7 +113,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
left: args[0],
right: {
label: "𝘷'",
left: { label: '𝘷', word: 'covert', value: 'CAUSE' },
left: { label: '𝘷', word: { covert: true, value: 'CAUSE' } },
right: {
label: 'VP',
left: args[1],
Expand All @@ -135,20 +135,19 @@ function attachAdjective(VP: Tree, vP: Tree): Tree {
label: 'aP',
left: {
label: 'a',
word: 'covert', // TODO ki
value: '∅',
word: { covert: true, value: '∅' }, // TODO ki
},
right: {
// TODO: oh god, adjectives can have T and Asp?
// needs rework in nearley grammar
label: 'CPrel',
left: { label: 'C', word: 'covert', value: '∅' },
left: { label: 'C', word: { covert: true, value: '∅' } },
right: {
label: 'TP',
left: { label: 'T', word: 'covert', value: '∅' },
left: { label: 'T', word: { covert: true, value: '∅' } },
right: {
label: 'AspP',
left: { label: 'Asp', word: 'covert', value: '∅' },
left: { label: 'Asp', word: { covert: true, value: '∅' } },
right: vP,
},
},
Expand Down
3 changes: 1 addition & 2 deletions src/textual-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Tree } from './tree';

function ttree_converted(data: Tree): { label: string; branches: any } {
if ('word' in data) {
const b =
data.word === 'covert' ? data.value : data.word.text.toLowerCase();
const b = data.word.covert ? data.word.value : data.word.text.toLowerCase();
return { label: data.label, branches: [b] };
} else if ('left' in data) {
return {
Expand Down
47 changes: 24 additions & 23 deletions src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ import { bare, clean, ToaqToken, tone } from './tokenize';
import { Tone } from './types';

export interface Word {
covert: false;
index: number | undefined;
text: string;
bare: string;
tone: Tone;
entry: Entry | undefined;
}

type CovertValue = '∅' | 'BE' | 'CAUSE' | 'PRO';

export interface CovertWord {
covert: true;
value: CovertValue;
}

export type Label =
| '*Serial'
| '*𝘷P'
Expand Down Expand Up @@ -86,7 +94,7 @@ export function containsWords(
stopLabels: Label[],
): boolean {
if ('word' in tree) {
return tree.word !== 'covert' && words.includes(clean(tree.word.text));
return !tree.word.covert && words.includes(clean(tree.word.text));
} else if ('left' in tree) {
return (
(!stopLabels.includes(tree.left.label) &&
Expand All @@ -111,25 +119,13 @@ export function isQuestion(tree: Tree): boolean {
);
}

export interface OvertLeaf {
export interface Leaf {
label: Label;
id?: string;
movedTo?: string;
word: Word;
word: Word | CovertWord;
}

type CovertValue = '∅' | 'BE' | 'CAUSE' | 'PRO';

export interface CovertLeaf {
label: Label;
id?: string;
movedTo?: string;
word: 'covert';
value: CovertValue;
}

export type Leaf = OvertLeaf | CovertLeaf;

export interface Branch<T> {
label: Label;
left: T;
Expand All @@ -154,6 +150,7 @@ export function makeWord([token]: [ToaqToken]): Word {
const lemmaForm = token.value.toLowerCase().normalize();
const bareWord = bare(token.value);
return {
covert: false,
index: token.index,
text: token.value,
bare: bareWord,
Expand Down Expand Up @@ -182,7 +179,7 @@ export function makeLeaf(label: Label) {
export function makeCovertLeaf(label: Label) {
return () => ({
label,
word: 'covert',
word: { covert: true, value: '∅' },
});
}

Expand All @@ -200,7 +197,7 @@ export function makeBranchCovertLeft(label: Label, covertLabel: Label) {
return ([right]: [Tree, Tree]) => {
return {
label,
left: { label: covertLabel, word: 'covert' },
left: { label: covertLabel, word: { covert: true, value: '∅' } },
right,
};
};
Expand Down Expand Up @@ -245,7 +242,7 @@ export function makeSingleChild(label: Label) {

export function makeOptLeaf(label: Label) {
return ([leaf]: [Leaf | undefined]) => {
return leaf ?? { label, word: 'covert' };
return leaf ?? { label, word: { covert: true, value: '∅' } };
};
}

Expand Down Expand Up @@ -302,7 +299,7 @@ export function makevPdet([serial]: [Tree], location: number, reject: Object) {
}
return {
label: '*𝘷P',
children: [serial, { label: 'DP', word: 'covert' }],
children: [serial, { label: 'DP', word: { covert: true, value: '∅' } }],
};
}

Expand Down Expand Up @@ -356,14 +353,14 @@ export function makeT1ModalvP([modal, tp]: [Tree, Tree]) {
left: modal,
right: {
label: 'CP',
word: 'covert',
word: { covert: true, value: '∅' },
},
},
right: {
label: "𝘷'",
left: {
label: '𝘷',
word: 'covert',
word: { covert: true, value: 'BE' },
},
right: tp,
},
Expand Down Expand Up @@ -396,13 +393,17 @@ export function makePrefixP([prefix, verb]: [Tree, Tree]) {
export function makeRetroactiveCleft([tp, vgo, clause]: [Tree, Tree, Tree]) {
return {
label: '𝘷P',
left: { label: 'CP', left: { label: 'C', word: 'covert' }, right: tp },
left: {
label: 'CP',
left: { label: 'C', word: { covert: true, value: '∅' } },
right: tp,
},
right: {
label: "𝘷'",
left: vgo,
right: {
label: 'CPrel',
left: { label: 'C', word: 'covert' },
left: { label: 'C', word: { covert: true, value: '∅' } },
right: clause,
},
},
Expand Down

0 comments on commit 6b67a27

Please sign in to comment.