Words and sentences
Give a choice the words that say it, and read what a person types against them, with no model.
Sam would rather type to the card than hunt for buttons: “make it funny”, “don't make it funny”, “the title, bigger”. Each of these names a possibility the card already has. A lookup in the card's own words can answer it, and System One is never asked. Some sentences still need more: a question back to Sam, a reprogramming, or System One reading them as something said of the whole card.
A vocabulary
The tones as a vocabulary. Each has a label, the words that say it, and its colours:
/** @jsxImportSource @reintent/core */
import { host } from '@reintent/core';
import { vocab } from '@reintent/lib/vocab';
export type Person = { to: string; age: number; from: string };
export const GRANDMA: Person = { to: 'Grandma', age: 90, from: 'Sam' };
/** Each tone: a label, the words that say it, and what it means to the card (its colours). */
export const Tone = vocab({
warm: { label: 'warm', words: ['warm', 'cosy'], background: '#fdebd3', accent: '#b5562b' },
funny: { label: 'funny', words: ['funny', 'a joke'], background: '#fff2a8', accent: '#7a4fd6' },
formal: { label: 'formal', words: ['formal', 'proper'], background: '#f1eee8', accent: '#2b2b2b' },
});
export function title(p: Person, tone: string) {
if (tone === 'formal') return `Many happy returns, ${p.to}.`;
if (tone === 'warm') return `Happy ${p.age}th birthday, ${p.to}!`;
return `${p.age} laps around the sun, ${p.to}!`;
}
export default function Card() {
// A possibility and its data, in one value: { kind, background, accent }.
const tone = Tone.read('tone', {
of: 'card',
label: 'the tone',
aka: ['tone'],
default: 'warm',
judge: false,
});
return host('div', {
style: { maxWidth: 380, padding: 24, borderRadius: 12, background: tone.background, color: '#3a2a1c' },
children: [
host('h1', { style: { color: tone.accent }, children: title(GRANDMA, tone.kind) }),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: `— ${GRANDMA.from}` }),
],
});
}
Starting…
Starting…
Nothing logged.
vocab(spec) turns the table into a Vocab. Each entry is a KindSpec: label and words, and everything else is data for the host. Tone.read(name, { of, default }) reads the choice { of, name } (the options are ReadOptions). The value it returns is a Value, the possibility's name as kind with its data next to it: { kind: 'warm', background, accent }. The card draws tone.background directly, so the colours live next to the words.
Pick formal in Choices, and the card turns grey. judge: false keeps System One out of it. With a question there instead, read judges the choice as a question with ask: ['model'] does.
The read also carries the words, for a panel or a model. kindAbout(read, kind) gives back a possibility's label and words, its KindAbout without the data.
Reading a sentence
Now the card has two choices, its tone and its colours. Sam's app (App.tsx, a React host as in Quick start, showing an Intent it holds with <ReintentView intent>) shows a row of sentences Sam can type, and passes each to recognize:
/** @jsxImportSource @reintent/core */
import { host } from '@reintent/core';
import { vocab } from '@reintent/lib/vocab';
export type Person = { to: string; age: number; from: string };
export const GRANDMA: Person = { to: 'Grandma', age: 90, from: 'Sam' };
export const Tone = vocab({
warm: { label: 'warm', words: ['warm', 'cosy'] },
funny: { label: 'funny', words: ['funny', 'a joke'] },
formal: { label: 'formal', words: ['formal', 'proper'] },
});
/** The card's colours: “warm” is a word of these too. */
export const Colours = vocab({
warm: { label: 'warm', words: ['warm', 'peach'], background: '#fdebd3', accent: '#b5562b' },
cool: { label: 'cool', words: ['cool', 'blue'], background: '#e3ecf3', accent: '#2f5d7c' },
});
export function title(p: Person, tone: string) {
if (tone === 'formal') return `Many happy returns, ${p.to}.`;
if (tone === 'warm') return `Happy ${p.age}th birthday, ${p.to}!`;
return `${p.age} laps around the sun, ${p.to}!`;
}
/** The card: its tone and its colours. What Sam types lives in the app (App.tsx). */
export default function App() {
const tone = Tone.read('tone', { of: 'card', aka: ['tone'], default: 'formal', judge: false });
const colours = Colours.read('colours', { of: 'card', aka: ['colours'], default: 'cool', judge: false });
return host('div', {
style: {
maxWidth: 380,
padding: 24,
borderRadius: 12,
background: colours.background,
color: '#3a2a1c',
},
children: [
host('h1', { style: { color: colours.accent }, children: title(GRANDMA, tone.kind) }),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: `— ${GRANDMA.from}` }),
],
});
}
Starting…
Starting…
Nothing logged.
recognize(text, reads) looks for the words of every choice the evaluation read. It returns a Recognized with one of four outcomes:
| outcome | the sentence | what the app does |
|---|---|---|
resolve | names a possibility; not when it rules one out | intent.decide, or intent.constrain |
clarify | could mean more than one choice | asks Sam which one |
reprogram | asks for something the program cannot say yet | needs System Two |
context | names nothing on the card | intent.tell, said of the whole |
Press “make it funny”. The words name funny, and the title turns funny with no model involved. A resolve carries a Reading: the choice, the possibility and not. The app decides the possibility's tag, and the read gets its data back. “don't make it funny” rules funny out with intent.constrain, and the tone goes back to formal.
“make it warm” fits both choices, since warm is a word of the tone and of the colours. The outcome is clarify, with a reading for each, and the app asks Which do you mean? Press the colours, and that reading becomes the decision. “warm colours” names the choice too, and words that name a choice keep the reading to it.
“more festive overall” names nothing on the card, so the app says it of the whole card, like the sentences in Quick start.
Clarify asks about the sentence
A choice read with ask: true waits for a person to pick a possibility. clarify asks which choice a sentence was about. Once Sam answers, the possibility the sentence named becomes the decision.
A step along a scale
The title has three sizes, in order. “Bigger” names none of them, and still means something:
/** @jsxImportSource @reintent/core */
import { host } from '@reintent/core';
import { vocab } from '@reintent/lib/vocab';
export type Person = { to: string; age: number; from: string };
export const GRANDMA: Person = { to: 'Grandma', age: 90, from: 'Sam' };
/** The title's size: an ordered vocabulary, so a sentence can step along it. */
export const Size = vocab(
{
modest: { label: 'modest', words: ['modest'], fontSize: 22 },
usual: { label: 'usual', words: ['usual'], fontSize: 30 },
grand: { label: 'grand', words: ['grand'], fontSize: 40 },
},
{ ordered: true },
);
/** What a sentence button does: the intent gives it to every evaluation (index.intent.tsx). */
export const SENTENCES = ['the title, bigger', 'the title, smaller'];
export default function App() {
const size = Size.read('size', {
of: 'title',
label: 'the title',
aka: ['title'],
default: 'usual',
judge: false,
});
return host('div', {
children: [
host('p', {
children: SENTENCES.map((text) =>
host('button', { onClick: { event: 'say', args: [text] }, children: `“${text}”` }),
),
}),
host('div', {
style: { maxWidth: 380, padding: 24, borderRadius: 12, background: '#fdebd3', color: '#3a2a1c' },
children: [
host('h1', {
style: { color: '#b5562b', fontSize: size.fontSize },
children: `Happy ${GRANDMA.age}th birthday, ${GRANDMA.to}!`,
}),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: `— ${GRANDMA.from}` }),
],
}),
],
});
}
Starting…
Starting…
Nothing logged.
vocab(spec, { ordered: true }) puts the possibilities on a scale, from the first to the last. A sentence with a step's words moves one step from where the choice is now, and its reading says match: 'step'. The step words are MORE and LESS, in English and Chinese. A vocabulary can give its own with more and less, and they count for more than the shared ones.
Press “the title, bigger” twice. The first goes from usual to grand. The second would go past the end of the scale, so the outcome is reprogram, with a Need for one more size above (kind: 'extend', dir: 1). A new possibility is a new program, which is System Two's to write (Quick start).
A possibility's own words win over a step
A possibility's name is one of its words. Call the smallest size small, and “smaller” contains it, so the sentence names small and jumps there from anywhere. Give a scale names that the step words do not contain.
Labels in two languages
A label can hold both languages, '温暖 · warm'. half(label, locale) gives the reader's half: half('温暖 · warm', 'en') is 'warm'. recognize matches the first half.
In an entity's declaration
The same sizes, with the title declared as an entity:
/** @jsxImportSource @reintent/core */
import { entity, host, useChoose } from '@reintent/core';
import { vocab } from '@reintent/lib/vocab';
export type Person = { to: string; age: number; from: string };
export const GRANDMA: Person = { to: 'Grandma', age: 90, from: 'Sam' };
/** The title's size: the same ordered vocabulary as before. */
export const Size = vocab(
{
modest: { label: 'modest', words: ['modest'], fontSize: 22 },
usual: { label: 'usual', words: ['usual'], fontSize: 30 },
grand: { label: 'grand', words: ['grand'], fontSize: 40 },
},
{ ordered: true },
);
/** The title, declared: its size is a field built from the vocabulary. */
export const title = entity('title', {
size: Size.decl({ label: 'the title', aka: ['title'], default: 'usual', judge: false }),
});
/** What a sentence button does: the intent gives it to every evaluation (index.intent.tsx). */
export const SENTENCES = ['the title, bigger', 'the title, smaller'];
export default function App() {
// Read through the handle: the value is { kind, fontSize }, as with Size.read.
const size = useChoose(title.size);
return host('div', {
children: [
host('p', {
children: SENTENCES.map((text) =>
host('button', { onClick: { event: 'say', args: [text] }, children: `“${text}”` }),
),
}),
host('div', {
style: { maxWidth: 380, padding: 24, borderRadius: 12, background: '#fdebd3', color: '#3a2a1c' },
children: [
host('h1', {
style: { color: '#b5562b', fontSize: size.fontSize },
children: `Happy ${GRANDMA.age}th birthday, ${GRANDMA.to}!`,
}),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: `— ${GRANDMA.from}` }),
],
}),
],
});
}
Starting…
Starting…
Nothing logged.
Size.decl(options) gives a field for entity, a VocabDecl. Its options are the ones read takes, less what belongs to one read (of, ask, otherwise, uses, open); they are DeclOptions. The possibilities and their data go into kinds, and the labels and words into about. useChoose(title.size) reads the same value Size.read gives, { kind: 'usual', fontSize: 30 }, and the sentences step along it as before.
As with read, a label is also System One's question unless judge says otherwise. Here judge: false keeps the title out of System One's hands.
Said of a thing, and edits
Sam's app does more than read whole sentences. Sam taps the title and types “bigger”. Sam asks for something the card does not have. Sam edits the sentence the card came from (What was said). The card and the title are both entities here:
import { createIntent, entity, host, useChoose } from '@reintent/core';
import { recognize } from '@reintent/language/words';
const card = entity('card', {
tone: Tone.decl({ label: 'the tone', aka: ['tone'], default: 'warm', judge: false }),
});
const title = entity('title', {
size: Size.decl({ label: 'the title', aka: ['title'], default: 'usual', judge: false }),
});
const Card = card(function Card() {
return host('card', { tone: useChoose(card.tone), size: useChoose(title.size) });
});
const intent = createIntent({ program: <Card /> });
const reads = intent.realize().reads;
recognize('bigger', reads, { of: 'title' }); // resolve: title#size, grand
recognize('add a balloon in the corner', reads, { newThings: true });
// reprogram: { kind: 'new-thing', noun: 'balloon', text: 'add a balloon in the corner' }The third argument is RecognizeOptions. of says the sentence of one thing, and only its choices are read. focus names the thing on screen: when the words name no thing, its choices come first. newThings: true reads an indefinite noun that names nothing on the card as a new thing, a reprogramming with kind: 'new-thing'. indefinite(text) finds the noun (“a balloon”, “一盏灯”), and newNoun(text, reads) keeps it only when no thing, choice or possibility has words for it.
An edit to the words already said is one event too. recognizeEdit(said, next, reads) reads it with readEdit, then reads the new words: a reworded span with readWords for its choice, words outside every span with recognize. The result is an EditRecognized, one of the four outcomes with the words after the edit (said), the edit, where the words land (bind), and a choice to forget:
import { bind } from '@reintent/language/said';
import { bindEdit, recognizeEdit } from '@reintent/language/words';
const said = bind('A warm card for Grandma', [
['warm', 'card', 'tone', 'warm'],
['card', 'card'],
]);
// Reworded: resolve, card#tone, funny.
const a = recognizeEdit(said, 'A funny card for Grandma', reads);
if (a.outcome === 'resolve') intent.decide(a.reading.id, a.reading.kind);
// Inserted: resolve, title#size, grand; the new words get a span of their own.
const b = recognizeEdit(said, 'A warm card for Grandma, with a grand title', reads);
if (b.outcome === 'resolve') {
intent.decide(b.reading.id, b.reading.kind);
const next = bindEdit(b, { ...b.reading.id, kind: b.reading.kind });
}
// Unsaid: the decision the words made goes, and the tone is judged again.
const c = recognizeEdit(said, 'A card for Grandma', reads);
if (c.forget) intent.forget(c.forget);bindEdit(r, to) binds the edited words where the event landed, to the reading's choice and possibility, or to a thing.
A reprogramming asks more or less of System Two. tierOf(need) gives a Tier: weak for a possibility more on a choice there is (a step past the end, a value a drag let go at, new words for a choice), strong for new structure (a new thing, words that bring in something new, the last words naming a thing gone). The balloon is strong; “the title, bigger” past grand is weak.
Recap
vocab(spec)gives each possibility a label, words and host data;Tone.read(name, { of, default })reads a choice with it, as{ kind, ...data }.kindAbout(read, kind)gives a possibility's label and words back from a read.recognize(text, reads)resolves, clarifies, asks for a reprogramming, or leaves the sentence to the whole card.- An ordered vocabulary turns
MOREandLESSwords into steps; a step past the end needs a reprogramming. Size.decl()makes the vocabulary a field of an entity's declaration, read and recognized the same way.recognizetakesof,focusandnewThings;recognizeEditreads an edit to the words as one event,bindEditbinds the new words, andtierOfsays whether a reprogramming is weak or strong.
Last updated on
Edit on GitHub