Skip to content

Commit

Permalink
sema/render: parameterize, add json mode + pprint
Browse files Browse the repository at this point in the history
  • Loading branch information
uakci committed May 13, 2024
1 parent cf77988 commit 508e3f8
Show file tree
Hide file tree
Showing 2 changed files with 248 additions and 68 deletions.
45 changes: 45 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import { denote } from './semantics/denote';
import { ToaqTokenizer } from './morphology/tokenize';
import { toEnglish } from './english/tree';
import { denotationRenderText } from './tree/place';
import { DTree } from './semantics/model';
import {
toPlainText,
toLatex,
toJson,
jsonStringifyCompact,
} from './semantics/render';

function getTrees(argv: {
sentence: string | undefined;
Expand Down Expand Up @@ -197,6 +204,44 @@ yargs
fs.writeFileSync(argv.output as string, toDocument(trees));
},
)
.command(
'denote',
'Full denotation in given format',
yargs => {
yargs.demandOption('sentence');
yargs.option('format', {
type: 'string',
choices: ['text', 'latex', 'json'],
default: 'text',
});
},

function (argv) {
const dtrees = getTrees({ ...argv, semantics: true }) as DTree[];
const format = argv.format as 'text' | 'latex' | 'json';
switch (format) {
case 'text':
for (const dtree of dtrees) {
console.log(toPlainText(dtree.denotation!));
}
break;
case 'latex':
for (const dtree of dtrees) {
console.log(toLatex(dtree.denotation!));
}
break;
case 'json':
console.log(
jsonStringifyCompact(
dtrees.map(({ denotation }) => toJson(denotation!)),
),
);
break;
default:
format satisfies never;
}
},
)
.command(
'test-sentences',
'Test parsing many sentences',
Expand Down
Loading

0 comments on commit 508e3f8

Please sign in to comment.