@reintent/language/words
Events in words, read against what an evaluation read.
Each choice's words, its possibilities' words and its thing's words are the vocabulary's About, passed through as ChoiceRead.about (a declaration field's about, which Size.decl(…) fills, or Size.read's). A sentence (said of the whole, or of one thing), or an edit to words already said (@reintent/language/said), has one of four outcomes:
resolve it names a possibility (or a step along an ordered choice): a person's decision,
or a possibility ruled out. No model (Reduce).
clarify it could be more than one choice: which one is meant is asked, and the answer
resolves. Not a choice's `ask` (a person deciding): the reading is what is unsure.
An ambiguous reading is never settled by a guess, a model's or code's.
reprogram the program cannot say it yet (past the end of a scale, a new thing, words a
choice has no possibility for): a need for System Two (Reprogram). `tierOf` says
whether it is a possibility more on a choice there is (weak) or a change of
structure (strong).
context it is about nothing in particular ("更压抑一点"): said of the whole (Judge).Only resolve, and the person's answer to clarify, are a person's decision. What a model reads into the words (a binding by: 'model', the picks it writes with a reprogramming) is its reading, a belief or a default at most: a host never writes it as a person's decision. After a reprogramming adds what was missing, the person's own words are read again by Code.
The reading is scored per choice: naming the choice counts most, then a possibility it names, then a step's own words ("慢一点" names the pace), then generic steps ("大一点"), then the thing (or, when no thing is named, the thing in focus). Words that name a choice keep the reading to it.
Interfaces
Reading
Defined in: packages/language/src/words.ts
A possibility of a choice, as words read it.
Properties
| Property | Type | Description |
|---|---|---|
id | Id | - |
key | string | - |
kind | string | - |
match | "kind" | "step" | What the words matched: a possibility's own words ('kind'), or a step along an ordered choice ('step'). |
not? | boolean | Ruled out rather than chosen ("不要大得离谱"). |
RecognizeOptions
Defined in: packages/language/src/words.ts
Where a sentence is said, and what is on screen.
Example
import { createIntent, entity, host, useChoose } from '@reintent/core';
import { vocab } from '@reintent/lib/vocab';
import { recognize } from '@reintent/language/words';
const Size = vocab(
{ usual: { words: ['usual'] }, big: { words: ['big'] } },
{ ordered: true },
);
const man = entity('man', { hat: Size.decl({ aka: ['hat'], default: 'usual' }) });
const cat = entity('cat', { tail: Size.decl({ aka: ['tail'], default: 'usual' }) });
const Man = man(() => host('man', { hat: useChoose(man.hat).kind }));
const Cat = cat(() => host('cat', { tail: useChoose(cat.tail).kind }));
const intent = createIntent({ program: [<Man />, <Cat />] });
const reads = intent.realize().reads;
const said = (text: string, opts = {}) => {
const r = recognize(text, reads, opts);
if (r.outcome === 'resolve') return `${r.reading.key} = ${r.reading.kind}`;
return r.outcome === 'reprogram' ? `${r.outcome}: ${r.need.kind}` : r.outcome;
};
console.log(said('bigger')); // → 'clarify'
// Said of one thing: only its choices are read.
console.log(said('bigger', { of: 'cat' })); // → 'cat#tail = big'
// The thing on screen comes first when the words name none.
console.log(said('bigger', { focus: 'man' })); // → 'man#hat = big'
// An indefinite noun nothing has words for: a new thing, for a reprogramming.
console.log(said('put a lamp beside him', { newThings: true })); // → 'reprogram: new-thing'Properties
Type Aliases
EditRecognized
type EditRecognized = Recognized & object;Defined in: packages/language/src/words.ts
What an edit to the words means: an outcome, the words after it, and where the words land.
Type Declaration
| Name | Type | Description |
|---|---|---|
bind? | object | Where the edited words are bound once the event lands: a span of them, or a stretch. |
bind.from | number | - |
bind.span? | string | - |
bind.to | number | - |
edit | WordEdit | - |
forget? | Id | Words taken back from a choice: the decision they made goes (if they made it), it is judged again. |
said | Said | The words after the edit (a span read is settled: no longer unread). |
Need
type Need =
| {
dir: 1 | -1;
id: Id;
key: string;
kind: "extend";
text: string;
}
| {
kind: "unknown";
text: string;
things: string[];
}
| {
kind: "new-thing";
noun: string;
text: string;
}
| {
dir: 1 | -1 | 0;
id?: Id;
key?: string;
kind: "reword";
noun?: string;
of: string;
old: string;
text: string;
}
| {
kind: "unsay";
of: string;
text: string;
}
| {
field: string;
id: Id;
key: string;
kind: "learn";
text?: string;
value: unknown;
}
| {
kind: "told";
text: string;
};Defined in: packages/language/src/words.ts
What a reprogramming is asked for: what the program cannot say yet.
Union Members
Type Literal
{
dir: 1 | -1;
id: Id;
key: string;
kind: "extend";
text: string;
}A step past the end of an ordered choice: a possibility more on it.
Type Literal
{
kind: "unknown";
text: string;
things: string[];
}Nothing reads it, though it names these things.
Type Literal
{
kind: "new-thing";
noun: string;
text: string;
}An indefinite noun ("一盏灯", "a lamp") naming no thing there is.
Type Literal
{
dir: 1 | -1 | 0;
id?: Id;
key?: string;
kind: "reword";
noun?: string;
of: string;
old: string;
text: string;
}Words of a span rewritten, and no possibility reads them: further along (dir), or a
possibility the choice does not have; with a noun, something new in place of it ("一把伞").
No id: the span named a thing.
Type Literal
{
kind: "unsay";
of: string;
text: string;
}The last words naming a thing are gone.
Type Literal
{
field: string;
id: Id;
key: string;
kind: "learn";
text?: string;
value: unknown;
}A value no possibility has (a drag that landed nowhere, a number between two): a possibility more.
Type Literal
{
kind: "told";
text: string;
}A whole new scene, told.
Recognized
type Recognized =
| {
outcome: "resolve";
reading: Reading;
}
| {
outcome: "clarify";
readings: Reading[];
}
| {
need: Need;
outcome: "reprogram";
}
| {
outcome: "context";
text: string;
};Defined in: packages/language/src/words.ts
A sentence read: one of the four outcomes.
Tier
type Tier = "weak" | "strong";Defined in: packages/language/src/words.ts
How much a need asks of a model: a possibility more on a choice there is, or new structure.
Functions
bindEdit()
function bindEdit(
r,
to,
by?
): Said;Defined in: packages/language/src/words.ts
The words of an edit bound where its event landed: a reading's choice and possibility, or a thing.
Parameters
| Parameter | Type | Default value |
|---|---|---|
r | Pick<EditRecognized, "said" | "bind"> | undefined |
to | { kind?: string; name?: string; of: string; } | undefined |
to.kind? | string | undefined |
to.name? | string | undefined |
to.of | string | undefined |
by | "code" | "model" | "human" | 'human' |
Returns
indefinite()
function indefinite(text): string | undefined;Defined in: packages/language/src/words.ts
The noun of an indefinite ("一盏灯", "a lamp"), the words after its last modifier.
Parameters
| Parameter | Type |
|---|---|
text | string |
Returns
string | undefined
newNoun()
function newNoun(text, reads): string | undefined;Defined in: packages/language/src/words.ts
An indefinite noun in text that names no thing, choice or possibility the reads know.
Parameters
| Parameter | Type |
|---|---|
text | string |
reads | readonly ChoiceRead[] |
Returns
string | undefined
recognize()
function recognize(
text,
reads,
opts?
): Recognized;Defined in: packages/language/src/words.ts
Parameters
| Parameter | Type |
|---|---|
text | string |
reads | readonly ChoiceRead[] |
opts | RecognizeOptions |
Returns
Example
import { createIntent, host } from '@reintent/core';
import { recognize } from '@reintent/language/words';
import { vocab } from '@reintent/lib/vocab';
const Size = vocab(
{
usual: { words: ['usual'] },
large: { words: ['large'] },
huge: { words: ['huge'] },
},
{ ordered: true },
);
const Man = () =>
host('man', {
hat: Size.read('hat', { of: 'man', aka: ['hat'], default: 'usual', judge: false })
.kind,
});
const intent = createIntent({ program: <Man /> });
const said = (text: string) => {
const r = recognize(text, intent.realize().reads);
return r.outcome === 'resolve' ? `resolve: ${r.reading.kind}` : r.outcome;
};
console.log(said('make the hat huge')); // → 'resolve: huge'
// A step along the scale, from where it is now:
console.log(said('the hat, bigger')); // → 'resolve: large'
console.log(said('gloomier overall')); // → 'context'
intent.decide({ of: 'man', name: 'hat' }, 'huge');
// Past the end: the program cannot say it yet, a reprogramming can.
console.log(said('the hat, bigger')); // → 'reprogram'recognizeEdit()
function recognizeEdit(
said,
next,
reads,
opts?
): EditRecognized;Defined in: packages/language/src/words.ts
An edit to words already said (@reintent/language/said), read as one event: readEdit says which
span it touched and how, readWords reads new words for a choice, recognize reads words said
outside every span (or of a thing a span names).
Parameters
| Parameter | Type |
|---|---|
said | Said |
next | string |
reads | readonly ChoiceRead[] |
opts | RecognizeOptions |
Returns
Example
import { createIntent, entity, host, useChoose } from '@reintent/core';
import { bind } from '@reintent/language/said';
import { vocab } from '@reintent/lib/vocab';
import { recognizeEdit, tierOf } from '@reintent/language/words';
const Size = vocab(
{ usual: { words: ['正常'] }, big: { words: ['大的'] }, absurd: { words: ['离谱'] } },
{ ordered: true },
);
const man = entity('man', { hat: Size.decl({ aka: ['帽子'], default: 'big' }) });
const Man = man(function Man() {
return host('man', { hat: useChoose(man.hat).kind });
});
const intent = createIntent({ program: <Man /> });
const said = bind('他的帽子大的', [['大的', 'man', 'hat', 'big']]);
const reads = intent.realize().reads;
const r = recognizeEdit(said, '他的帽子离谱', reads);
console.log(r.outcome === 'resolve' && r.reading.kind, r.said.prompt); // → 'absurd' '他的帽子离谱'
// Words that bring in something new: the hat is something else now.
const umbrella = recognizeEdit(said, '他的一把黑伞', reads, { newThings: true });
if (umbrella.outcome === 'reprogram')
console.log(umbrella.need.kind, tierOf(umbrella.need)); // → 'reword' 'strong'tierOf()
function tierOf(need): Tier;Defined in: packages/language/src/words.ts
How much a need asks of a model. Weak: a possibility more on a choice there is (a step past the end, a value learned from a gesture, new words for a choice). Strong: new structure (a new thing, a scene told, words that bring in something new, a thing's words gone).
Parameters
| Parameter | Type |
|---|---|
need | Need |
Returns
Example
import { tierOf } from '@reintent/language/words';
const hat = { of: 'man', name: 'hat' };
console.log(tierOf({ kind: 'extend', id: hat, key: 'man#hat', dir: 1, text: '还要大' })); // → 'weak'
console.log(tierOf({ kind: 'new-thing', noun: '灯', text: '床头放一盏灯' })); // → 'strong'Last updated on
Edit on GitHub