Skip to content

Commit

Permalink
Merge pull request #3 from toaq/no-functional
Browse files Browse the repository at this point in the history
Handle covert leaves differently
  • Loading branch information
lynn committed Sep 5, 2023
2 parents 6f6df95 + ecf1e5c commit 5b87382
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 104 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
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
10 changes: 2 additions & 8 deletions src/draw-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +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 === 'functional'
? undefined
: leaf.word === 'covert'
? '∅'
: 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
7 changes: 3 additions & 4 deletions src/english.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +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 === 'functional') return '';
if (tree.word.covert) return '';
return tree.word.text;
}

Expand Down Expand Up @@ -48,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 @@ -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
5 changes: 1 addition & 4 deletions src/latex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ 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') {
if (tree.word.covert) {
return `[${label} [$\\varnothing$]]`;
}

Expand Down
47 changes: 21 additions & 26 deletions src/semantics/denote.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VerbEntry } from '../dictionary';
import { Branch, Leaf, StrictTree, Word } from '../tree';
import { Branch, CovertValue, Leaf, StrictTree, Word } from '../tree';
import {
after,
afterNear,
Expand Down Expand Up @@ -351,10 +351,19 @@ const littleVAgent = λ('e', ['s'], c =>
// λ𝘗. 𝘗
const na = λ(['e', 't'], [], c => v(0, c));

function denoteLittleV(toaq: string | null): Expr {
switch (toaq) {
case null:
function denoteCovertLittleV(value: CovertValue): Expr | null {
switch (value) {
case 'CAUSE':
return littleVAgent;
case 'BE':
return null;
default:
throw new Error(`Unrecognized 𝘷: ${value}`);
}
}

function denoteOvertLittleV(toaq: string): Expr {
switch (toaq) {
case 'nä':
return na;
default:
Expand Down Expand Up @@ -408,16 +417,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 === '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 @@ -517,23 +524,16 @@ function denoteLeaf(leaf: Leaf, cCommand: StrictTree | null): DTree {
covertResumptive: binding,
};
} else if (leaf.label === '𝘷') {
let toaq: string | null;
if (typeof leaf.word === 'string') {
toaq = null;
if (leaf.word.covert) {
denotation = denoteCovertLittleV(leaf.word.value);
} else if (leaf.word.entry === undefined) {
throw new Error(`Unrecognized 𝘷: ${leaf.word.text}`);
} else {
toaq = leaf.word.entry.toaq;
denotation = denoteOvertLittleV(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 +543,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 +554,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 +767,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
30 changes: 13 additions & 17 deletions src/serial.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Branch, Label, Tree } from './tree';
import { Branch, Label, Tree, makeNull } from './tree';

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

const pro: Tree = { label: 'DP', word: 'covert' };
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 === 'functional') throw new Error('functional 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 @@ -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: true, 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: true, 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: true, 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: true, 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: true, 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: true, value: 'CAUSE' } },
right: {
label: 'VP',
left: args[1],
Expand All @@ -134,21 +133,18 @@ function attachAdjective(VP: Tree, vP: Tree): Tree {
left: VP,
right: {
label: 'aP',
left: {
label: 'a',
word: 'covert', // TODO ki
},
left: makeNull('a'), // TODO ki-
right: {
// TODO: oh god, adjectives can have T and Asp?
// needs rework in nearley grammar
label: 'CPrel',
left: { label: 'C', word: 'covert' },
left: makeNull('C'),
right: {
label: 'TP',
left: { label: 'T', word: 'covert' },
left: makeNull('T'),
right: {
label: 'AspP',
left: { label: 'Asp', word: 'covert' },
left: makeNull('Asp'),
right: vP,
},
},
Expand Down
7 changes: 1 addition & 6 deletions src/textual-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +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.word === 'functional'
? '🅵'
: 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
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
Loading

0 comments on commit 5b87382

Please sign in to comment.