@reintent/lib/vocab
A vocabulary for a choice: its possibilities, the words that say each, and what each means to the host (its data).
The core needs none of it; the libraries that talk with a person or a model do: a sentence is read against the words, a model is shown the labels, the host draws the data.
const Size = vocab({
usual: { label: '寻常', words: ['正常'], hatScale: 1 },
absurd: { label: '大得离谱', words: ['离谱'], hatScale: 1.95 },
}, { ordered: true });
// in a component (a read by identity, not by call order: it may sit under an `if`):
const hat = Size.read('hat', { of: 'man', label: '帽子有多大', aka: ['帽子'], default: 'big', ask: true });
hat.kind // what the evaluation goes on
hat.hatScale // data for the host, directly in λA reprogramming that adds a possibility writes a new vocabulary (Size.extend({ … })) into a new program: kinds are the program's, and only a reprogramming changes them (0007 R1).
Interfaces
About
Defined in: packages/lib/src/vocab.ts
What ChoiceRead.about holds for a choice read through a vocabulary.
Properties
| Property | Type | Description |
|---|---|---|
aka | readonly string[] | Words that name the choice itself ("帽子"). |
gesture? | Gesture | The drag that reaches it (@reintent/lib/gesture). |
kinds | Record<string, Omit<KindAbout, "data">> | - |
label? | string | - |
less | readonly string[] | - |
more | readonly string[] | Words for a step along an ordered choice. |
ordered | boolean | - |
thing? | object | The thing it is a choice of, and its words ("他"). |
thing.aka | readonly string[] | - |
thing.label? | string | - |
view? | readonly string[] | What it moves in the picture: the view's paths (man.hat, wardrobe.door.right). |
KindAbout
Defined in: packages/lib/src/vocab.ts
Type Parameters
| Type Parameter | Default type |
|---|---|
D | unknown |
Properties
Vocab
Defined in: packages/lib/src/vocab.ts
Type Parameters
| Type Parameter |
|---|
K extends string |
D |
Properties
| Property | Type |
|---|---|
kinds | readonly K[] |
less | readonly string[] |
more | readonly string[] |
ordered | boolean |
table | Record<K, KindAbout<D>> |
Methods
about()
about(name, opts?): About;Defined in: packages/lib/src/vocab.ts
Human-readable metadata for a choice, without its host data.
Parameters
| Parameter | Type |
|---|---|
name | string |
opts? | AboutOptions<K> |
Returns
choices()
choices(): Choices<Value<K, D>>;Defined in: packages/lib/src/vocab.ts
The possibilities, equally weighted.
Returns
decl()
decl<O>(opts?): VocabDecl<K, D> & { readonly [k in "given" | "applies" | "forbid"]: O[k] };Defined in: packages/lib/src/vocab.ts
The choice as a field of an entity's declaration (0015): the same possibilities, words and
question as read with these options, so a sentence is recognized the same way. What only a
read says (of, ask, otherwise, uses) is said where it is read.
Type Parameters
| Type Parameter | Default type |
|---|---|
O extends DeclOptions<K> | Record<never, never> |
Parameters
| Parameter | Type |
|---|---|
opts? | O |
Returns
VocabDecl<K, D> & { readonly [k in "given" | "applies" | "forbid"]: O[k] }
extend()
extend<S>(more): Vocab<K | keyof S & string, D>;Defined in: packages/lib/src/vocab.ts
The vocabulary with possibilities more, after the last (what a reprogramming writes).
Type Parameters
| Type Parameter |
|---|
S extends Record<string, KindSpec> |
Parameters
| Parameter | Type |
|---|---|
more | S |
Returns
Vocab<K | keyof S & string, D>
read()
read(name, opts): Value<K, D>;Defined in: packages/lib/src/vocab.ts
Read the choice { of, name } with this vocabulary.
Parameters
| Parameter | Type |
|---|---|
name | string |
opts | ReadOptions<K> |
Returns
Value<K, D>
Type Aliases
AboutOptions
type AboutOptions<K> = Pick<ReadOptions<K>, "label" | "aka" | "thing" | "gesture" | "view">;Defined in: packages/lib/src/vocab.ts
What a vocabulary puts into a choice's about, besides its possibilities' words.
Type Parameters
| Type Parameter |
|---|
K extends string |
DeclOptions
type DeclOptions<K> = AboutOptions<K> & object;Defined in: packages/lib/src/vocab.ts
A choice declared with a vocabulary (0015): what read takes, less what only a read says.
Type Declaration
| Name | Type | Description |
|---|---|---|
applies? | Condition | - |
default? | K | - |
forbid? | readonly object[] | - |
given? | readonly string[] | - |
judge? | string | false | The question System One is asked (default: the label, as read); false: not judged. |
prior? | Partial<Record<K, number>> | - |
Type Parameters
| Type Parameter |
|---|
K extends string |
KindSpec
type KindSpec = object & Record<string, unknown>;Defined in: packages/lib/src/vocab.ts
Type Declaration
| Name | Type |
|---|---|
label? | string |
words? | readonly string[] |
ReadOptions
type ReadOptions<K> = object;Defined in: packages/lib/src/vocab.ts
Type Parameters
| Type Parameter |
|---|
K extends string |
Properties
| Property | Type | Description |
|---|---|---|
aka? | readonly string[] | - |
ask? | boolean | Asks a person while unresolved, after System One when it is judged (ask: ['human']). |
default | K | - |
gesture? | Gesture | The drag that reaches it, into about (@reintent/lib/gesture). |
judge? | string | false | The question System One is asked (default: the label); false: not judged. |
label? | string | - |
of | string | - |
open? | boolean | - |
otherwise? | Otherwise | Deprecated Say what to do when it cannot settle with an enclosing <World onUnresolved> (0046). |
thing? | About["thing"] | - |
uses? | Record<string, unknown> | What System One reads (0008 §8). |
view? | readonly string[] | What it moves in the picture, into about: the view's paths. |
Value
type Value<K, D> = K extends string ? object & D : never;Defined in: packages/lib/src/vocab.ts
A possibility's tag and host data, taken from the current vocabulary.
Type Parameters
| Type Parameter |
|---|
K extends string |
D |
VocabDecl
type VocabDecl<K, D> = object;Defined in: packages/lib/src/vocab.ts
A vocabulary's choice as a declaration's field: its kinds with their data, its words in about.
Type Parameters
| Type Parameter |
|---|
K extends string |
D |
Properties
| Property | Modifier | Type |
|---|---|---|
about | readonly | Json |
applies? | readonly | Condition |
default? | readonly | K |
forbid? | readonly | readonly object[] |
given? | readonly | readonly string[] |
judge? | readonly | string |
kinds | readonly | { readonly [k in K]: D } |
prior? | readonly | object |
Variables
LESS
const LESS: readonly string[];Defined in: packages/lib/src/vocab.ts
MORE
const MORE: readonly string[];Defined in: packages/lib/src/vocab.ts
The words for a step along any ordered choice that names none of its own.
Functions
half()
function half(
label,
locale,
fallback?
): string;Defined in: packages/lib/src/vocab.ts
A label in a reader's language, from a bilingual one ("床头 · the bed's head").
Parameters
| Parameter | Type | Default value |
|---|---|---|
label | string | undefined | undefined |
locale | Lang | undefined |
fallback | string | '' |
Returns
string
kindAbout()
function kindAbout(r, kind): Omit<KindAbout<unknown>, "data"> | undefined;Defined in: packages/lib/src/vocab.ts
A possibility of a choice as its read knows it.
Parameters
| Parameter | Type |
|---|---|
r | ChoiceRead |
kind | unknown |
Returns
Omit<KindAbout<unknown>, "data"> | undefined
vocab()
function vocab<S>(spec, opts?): Vocab<keyof S & string, Data<S>>;Defined in: packages/lib/src/vocab.ts
A possibility's value is { kind, ...data }, its name as its tag. Data with a kind of its own
throws: it would hide the tag.
Type Parameters
| Type Parameter |
|---|
S extends Record<string, KindSpec> |
Parameters
| Parameter | Type |
|---|---|
spec | S |
opts | Opts |
Returns
Vocab<keyof S & string, Data<S>>
Example
import { createIntent, host, type HostNode } from '@reintent/core';
import { vocab } from '@reintent/lib/vocab';
// Each possibility: a label, the words that say it, and what it means to the host.
const Size = vocab(
{
small: { label: 'small', words: ['small', 'little'], scale: 0.8 },
usual: { label: 'usual', words: ['usual', 'normal'], scale: 1 },
big: { label: 'big', words: ['big', 'large'], scale: 1.5 },
},
{ ordered: true },
);
function Man() {
const hat = Size.read('hat', {
of: 'man',
label: 'the hat',
aka: ['hat'],
default: 'usual',
judge: false,
});
return host('man', { hat });
}
const intent = createIntent({ program: <Man /> });
intent.decide({ of: 'man', name: 'hat' }, 'big');
const man = intent.realize().tree as HostNode;
console.log(man.props.hat); // → { kind: 'big', scale: 1.5 }Last updated on
Edit on GitHub