mirror of
https://github.com/moeru-ai/airi.git
synced 2026-10-31 03:44:38 +08:00
@proj-airi/mathjson
Types and small helpers for the MathJSON of the speech transformers. The package has no dependency.
Use it for
- The type of a lowered formula:
MathJson,MathJsonFunction, andMathJsonNumber. - Reading or building nodes:
headOf,argsOf,isFunction,isNumber,isSymbol,text,textOf, andnothing.
Do not use it for
- Parsing or reading formulas. Use
@proj-airi/speech-transformer-math. - Full MathJSON with evaluation. Use
@cortex-js/compute-engine.
Shape
The shape follows MathJSON. A function is an array with its head first, a string is a
symbol, and a quoted string, for example 'kg', is text. The speech transformers add heads for reading, for example
Apply, Bracket, and Chemistry.
const expression: MathJson = ['Add', 'x', { num: '1' }]
headOf(expression) // => 'Add'
Checks
pnpm -F @proj-airi/mathjson typecheck