Skip to content

Commit

Permalink
Handle covert leaves differently, add "PRO", remove "v0"
Browse files Browse the repository at this point in the history
  • Loading branch information
lynn committed Sep 5, 2023
1 parent 6f6df95 commit d4d1b3b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 73 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' || tree.word === 'functional') {
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' && c.word !== 'functional') {
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' && sa.word !== 'functional') {
if (sa.word !== 'covert') {
speechAct = sa.word.text;
}
const cp = tree.left;
Expand Down
7 changes: 1 addition & 6 deletions src/draw-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ export function placeLeaf(
const gloss =
typeof leaf.word === 'string' ? undefined : leaf.word.entry?.gloss;
const label = getLabel(leaf);
const word =
leaf.word === 'functional'
? undefined
: leaf.word === 'covert'
? '∅'
: leaf.word.text;
const word = leaf.word === 'covert' ? leaf.value : leaf.word.text;
const denotation =
'denotation' in leaf && leaf.denotation !== null
? toPlainText(leaf.denotation)
Expand Down
3 changes: 1 addition & 2 deletions src/english.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function leafText(tree: Tree): string {
throw new Error('Unexpected non-leaf ' + tree.label);
}
if (tree.word === 'covert') return '';
if (tree.word === 'functional') return '';
return tree.word.text;
}

Expand Down Expand Up @@ -364,7 +363,7 @@ function branchToEnglish(tree: Branch<Tree>): Constituent {
{ she: 'necessarily', ao: 'would', daı: 'possibly', ea: 'could' }[
bare(leafText(modal))
] ?? '?';
if (c.word === 'covert' || c.word === 'functional') {
if (c.word === 'covert') {
return { text: eng };
} else {
return {
Expand Down
3 changes: 1 addition & 2 deletions src/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const {
makeAdjunctPT,
makeBranch,
makeBranchCovertLeft,
makeBranchFunctionalLeft,
makeConn,
makeCovertLeaf,
makeLeaf,
Expand Down Expand Up @@ -110,7 +109,7 @@ const grammar: Grammar = {
{"name": "DP", "symbols": ["D", "nP"], "postprocess": makeBranch('DP')},
{"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": "nP", "symbols": ["CPdet"], "postprocess": makeBranchCovertLeft('nP', 'n')},
{"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', "𝘷'")},
Expand Down
3 changes: 0 additions & 3 deletions src/latex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export function toLatex(tree: Tree | DTree): string {
const children = tree.children.map(toLatex).join(' ');
return `[${label} ${children}]`;
} else {
if (tree.word === 'functional') {
return `[${label}]`;
}
if (tree.word === 'covert') {
return `[${label} [$\\varnothing$]]`;
}
Expand Down
30 changes: 10 additions & 20 deletions src/semantics/denote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,12 @@ const littleVAgent = λ('e', ['s'], c =>
// λ𝘗. 𝘗
const na = λ(['e', 't'], [], c => v(0, c));

function denoteLittleV(toaq: string | null): Expr {
function denoteLittleV(toaq: string | null): Expr | null {
switch (toaq) {
case null:
case 'CAUSE':
return littleVAgent;
case 'BE':
return null;
case 'nä':
return na;
default:
Expand Down Expand Up @@ -415,9 +417,7 @@ function denoteLeaf(leaf: Leaf, cCommand: StrictTree | null): DTree {

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

denotation = denoteLittleV(toaq);
} else if (leaf.label === '𝘷0') {
denotation = null;
} else if (leaf.label === 'Asp') {
let toaq: string;
if (leaf.word === 'functional') {
throw new Error('Functional Asp');
} else 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 @@ -543,9 +538,7 @@ function denoteLeaf(leaf: Leaf, cCommand: StrictTree | null): DTree {

denotation = denoteAspect(toaq);
} else if (leaf.label === 'T') {
if (leaf.word === 'functional') {
throw new Error('Functional T');
} else 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 @@ -556,9 +549,7 @@ function denoteLeaf(leaf: Leaf, cCommand: StrictTree | null): DTree {
denotation = null;
} else if (leaf.label === 'SA') {
let toaq: string;
if (leaf.word === 'functional') {
throw new Error('Functional SA');
} else 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 Expand Up @@ -771,7 +762,6 @@ function getCompositionRule(left: DTree, right: DTree): CompositionRule {
switch (left.label) {
case 'V':
case 'Asp':
case '𝘷0':
case 'n':
return functionalApplication;
case 'T':
Expand Down
22 changes: 11 additions & 11 deletions src/serial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { Branch, Label, Tree } from './tree';

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

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

export function getFrame(verb: Tree): string {
if ('word' in verb) {
if (verb.word === 'covert') throw new Error('covert verb?');
if (verb.word === 'functional') throw new Error('functional verb?');
if (verb.word.entry?.type === 'predicate') {
return verb.word.entry.frame;
} else {
Expand Down Expand Up @@ -42,7 +41,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
if (arity === 1) {
return {
label: '𝘷P',
left: { label: '𝘷0', word: 'functional' },
left: { label: '𝘷', word: 'covert', value: 'BE' },
right: { label: 'VP', left: verbs[0], right: args[0] },
};
} else if (arity === 2) {
Expand All @@ -51,7 +50,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
left: args[0],
right: {
label: "𝘷'",
left: { label: '𝘷', word: 'functional' },
left: { label: '𝘷', word: 'covert', value: 'CAUSE' },
right: { label: 'VP', left: verbs[0], right: args[1] },
},
};
Expand All @@ -61,7 +60,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
left: args[0],
right: {
label: "𝘷'",
left: { label: '𝘷', word: 'functional' },
left: { label: '𝘷', word: 'covert', value: 'CAUSE' },
right: {
label: 'VP',
left: args[1],
Expand Down Expand Up @@ -95,7 +94,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
if (arity === 1) {
return {
label: '𝘷P',
left: { label: '𝘷0', word: 'functional' },
left: { label: '𝘷', word: 'covert', value: 'BE' },
right: { label: 'VP', left: verbs[0], right: inner },
};
} else if (arity === 2) {
Expand All @@ -104,7 +103,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
left: args[0],
right: {
label: "𝘷'",
left: { label: '𝘷', word: 'functional' },
left: { label: '𝘷', word: 'covert', value: 'CAUSE' },
right: { label: 'VP', left: verbs[0], right: inner },
},
};
Expand All @@ -114,7 +113,7 @@ function serialTovP(verbs: Tree[], args: Tree[]): Tree {
left: args[0],
right: {
label: "𝘷'",
left: { label: '𝘷', word: 'functional' },
left: { label: '𝘷', word: 'covert', value: 'CAUSE' },
right: {
label: 'VP',
left: args[1],
Expand All @@ -137,18 +136,19 @@ function attachAdjective(VP: Tree, vP: Tree): Tree {
left: {
label: 'a',
word: 'covert', // TODO ki
value: '∅',
},
right: {
// TODO: oh god, adjectives can have T and Asp?
// needs rework in nearley grammar
label: 'CPrel',
left: { label: 'C', word: 'covert' },
left: { label: 'C', word: 'covert', value: '∅' },
right: {
label: 'TP',
left: { label: 'T', word: 'covert' },
left: { label: 'T', word: 'covert', value: '∅' },
right: {
label: 'AspP',
left: { label: 'Asp', word: 'covert' },
left: { label: 'Asp', word: 'covert', value: '∅' },
right: vP,
},
},
Expand Down
6 changes: 1 addition & 5 deletions src/textual-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { Tree } from './tree';
function ttree_converted(data: Tree): { label: string; branches: any } {
if ('word' in data) {
const b =
data.word === 'covert'
? '∅'
: data.word === 'functional'
? '🅵'
: data.word.text.toLowerCase();
data.word === 'covert' ? data.value : data.word.text.toLowerCase();
return { label: data.label, branches: [b] };
} else if ('left' in data) {
return {
Expand Down
3 changes: 1 addition & 2 deletions src/toaq.ne
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {
makeAdjunctPT,
makeBranch,
makeBranchCovertLeft,
makeBranchFunctionalLeft,
makeConn,
makeCovertLeaf,
makeLeaf,
Expand Down Expand Up @@ -61,7 +60,7 @@ DP -> Focus DP {% makeBranch('FocusP') %}
# (sá) ꝡë hao
nP -> nP CPrel {% makeBranch('nP') %}
# (sá) ∅ hao
nP -> CPdet {% makeBranchFunctionalLeft('nP', 'n') %}
nP -> CPdet {% makeBranchCovertLeft('nP', 'n') %}

# ní bï pu hao
Clause -> term Bi Clause {% make3L('TopicP', "Topic'") %}
Expand Down
35 changes: 16 additions & 19 deletions src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export type Label =
| "Topic'"
| 'TopicP'
| '𝘷'
| '𝘷0'
| "𝘷'"
| 'V'
| "V'"
Expand All @@ -87,11 +86,7 @@ export function containsWords(
stopLabels: Label[],
): boolean {
if ('word' in tree) {
return (
tree.word !== 'covert' &&
tree.word !== 'functional' &&
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 @@ -116,13 +111,25 @@ export function isQuestion(tree: Tree): boolean {
);
}

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

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 Down Expand Up @@ -189,16 +196,6 @@ export function makeBranch(label: Label) {
};
}

export function makeBranchFunctionalLeft(label: Label, functionalLabel: Label) {
return ([right]: [Tree, Tree]) => {
return {
label,
left: { label: functionalLabel, word: 'functional' },
right,
};
};
}

export function makeBranchCovertLeft(label: Label, covertLabel: Label) {
return ([right]: [Tree, Tree]) => {
return {
Expand Down Expand Up @@ -366,7 +363,7 @@ export function makeT1ModalvP([modal, tp]: [Tree, Tree]) {
label: "𝘷'",
left: {
label: '𝘷',
word: 'functional',
word: 'covert',
},
right: tp,
},
Expand Down

0 comments on commit d4d1b3b

Please sign in to comment.