Reintent

@reintent/language/said

What was said, bound to the choices it is about.

A person's words (a prompt, a dream told) stay with the program they became: stretches of them (spans) name a thing, a choice of it, and the possibility they say. The binding is data beside the intent, kept with the program's version and shared with it; it points at a choice's identity ({ of, name }) and a possibility's tag, never at a place in a program, so it survives a reprogramming. A span whose choice is gone after a reprogramming is an orphan, listed like a decision nothing reads.

status      where a span and the choice stand: it names, agrees, differs, is unread, or is
            an orphan
readEdit    an edit to the words, read as one event: a span reworded, a span unsaid, or
            words inserted outside every span
readWords   new words for a choice: the possibility they name, or a step along it
follow      the words rewritten to say what the choices are now

Only ChoiceRead and its about are read: the words come from a declaration field's about (which Size.decl(…) fills, 0015), or from Size.read's, so the same binding serves both.

Interfaces

Said

Defined in: packages/language/src/said.ts

What was said, and where each stretch of it is bound.

Properties

PropertyType
promptstring
spansSpan[]

Span

Defined in: packages/language/src/said.ts

A stretch of what was said, bound to a thing, a choice of it, and the possibility it says.

Properties

PropertyTypeDescription
by?"code" | "model" | "human"The Actor who bound them: 'model', 'human', 'code'. A model's binding is its reading of the words, shown and checked against what is read (status); it never decides a choice: a decision comes from a person's words read by Code (recognize), or a person's answer.
fromnumberOffsets into the prompt: prompt.slice(from, to) are its words.
idstring-
kind?stringThe possibility the words say (a tag); none: they name the choice, not a possibility.
name?stringThe choice (its name); none: the words name only the thing.
ofstringThe thing (a choice's of).
tonumber-
unread?trueReworded, and not read yet.

Type Aliases

Binding

type Binding = readonly [string, string, string, string];

Defined in: packages/language/src/said.ts

A binding as an author (or a model) writes it, in reading order: [words, of, name?, kind?].


SpanStatus

type SpanStatus = "names" | "agrees" | "differs" | "unread" | "orphan";

Defined in: packages/language/src/said.ts

Where a span and the choice it is bound to stand.


WordEdit

type WordEdit = 
  | {
  kind: "none";
}
  | {
  kind: "reword";
  old: string;
  span: Span;
  text: string;
}
  | {
  kind: "unsay";
  old: string;
  span: Span;
}
  | {
  from: number;
  kind: "insert";
  text: string;
  to: number;
};

Defined in: packages/language/src/said.ts

An edit to the words, read.

Union Members

Type Literal
{
  kind: "none";
}

Type Literal
{
  kind: "reword";
  old: string;
  span: Span;
  text: string;
}

A bound span's words changed: span is the span as it is now (its new words at from–to).


Type Literal
{
  kind: "unsay";
  old: string;
  span: Span;
}

A bound span's words are gone.


Type Literal
{
  from: number;
  kind: "insert";
  text: string;
  to: number;
}

Words added outside every span.

Variables

BACK

const BACK: readonly string[];

Defined in: packages/language/src/said.ts

Words that go back along any ordered choice, after its own.


FURTHER

const FURTHER: readonly string[];

Defined in: packages/language/src/said.ts

Words that go further along any ordered choice, after its own.

Functions

bind()

function bind(
   prompt, 
   list, 
   by?
): Said;

Defined in: packages/language/src/said.ts

Spans from bindings, each found after the one before it (so repeated words bind in order). A binding whose words are not there is skipped.

Parameters

ParameterTypeDefault value
promptstringundefined
listreadonly Binding[]undefined
by"code" | "model" | "human"'model'

Returns

Said

Example

import { bind, textOf } from '@reintent/language/said';

const said = bind('我梦到一个戴着大得离谱的帽子的男人站在床头', [
  ['大得离谱', 'man', 'hat', 'absurd'],
  ['男人', 'man'],
  ['床头', 'man', 'stand', 'bedside'],
]);
console.log(said.spans.map((s) => `${textOf(said, s)} → ${s.name ?? s.of}`));
// → [ '大得离谱 → hat', '男人 → man', '床头 → stand' ]

follow()

function follow(
   said, 
   reads, 
   ids?
): Said;

Defined in: packages/language/src/said.ts

The words rewritten to say what the choices are now: each span (of ids, default every one) that says a possibility its choice is no longer on says the current one. Spans that only name a thing or a choice stay.

Parameters

ParameterType
saidSaid
readsreadonly ChoiceRead[]
ids?readonly string[]

Returns

Said

Example

import { createIntent, entity, host, useChoose } from '@reintent/core';
import { bind, follow } from '@reintent/language/said';
import { vocab } from '@reintent/lib/vocab';

const Place = vocab({ bedside: { words: ['床头'] }, window: { words: ['窗边'] } });
const man = entity('man', { stand: Place.decl({ default: 'bedside' }) });
const Man = man(function Man() {
  return host('man', { stand: useChoose(man.stand).kind });
});
const intent = createIntent({ program: <Man /> });
intent.decide(man.stand('man'), 'window'); // dragged to the window

const said = bind('他站在床头看着我', [['床头', 'man', 'stand', 'bedside']]);
console.log(follow(said, intent.realize().reads).prompt); // → '他站在窗边看着我'

idOf()

function idOf(s): Id | undefined;

Defined in: packages/language/src/said.ts

The choice a span is bound to; undefined for a span that names only a thing (no choice has an empty name).

Parameters

ParameterType
sSpan

Returns

Id | undefined


nextId()

function nextId(said, prefix?): string;

Defined in: packages/language/src/said.ts

An id no span of said has (w1, w2…, in the order they are made).

Parameters

ParameterTypeDefault value
saidPick<Said, "spans">undefined
prefixstring'w'

Returns

string


orphans()

function orphans(said, reads): Span[];

Defined in: packages/language/src/said.ts

The spans no read has the identity of: what a reprogramming left behind.

Parameters

ParameterType
saidSaid
readsreadonly ChoiceRead[]

Returns

Span[]


readEdit()

function readEdit(said, next): object;

Defined in: packages/language/src/said.ts

The words edited to next: the changed stretch (between what the two share at the start and at the end), the spans moved past it, and what it means for the one span it touches (or for none). A reworded span is marked unread, bound by the person.

Parameters

ParameterType
saidSaid
nextstring

Returns

object

NameType
editWordEdit
saidSaid

Example

import { bind, readEdit } from '@reintent/language/said';

const said = bind('他站在床头,帽子大得离谱', [
  ['床头', 'man', 'stand', 'bedside'],
  ['大得离谱', 'man', 'hat', 'absurd'],
]);
console.log(readEdit(said, '他站在窗边,帽子大得离谱').edit.kind); // → 'reword'
console.log(readEdit(said, '他站在,帽子大得离谱').edit.kind); // → 'unsay'
const { said: next, edit } = readEdit(said, '他站在床头,帽子大得离谱。床头有一盏灯');
console.log(edit, next.spans.length);
// → { kind: 'insert', text: '。床头有一盏灯', from: 12, to: 19 } 2

readWords()

function readWords(read, text): 
  | {
  kind: string;
}
  | {
  dir: -1 | 1;
}
  | null;

Defined in: packages/language/src/said.ts

New words for a choice: the possibility they name (its words or label, the longest that appears), or which way along an ordered choice they go when they name none.

Parameters

ParameterType
readChoiceRead
textstring

Returns

| { kind: string; } | { dir: -1 | 1; } | null

Example

import { createIntent, entity, host, useChoose } from '@reintent/core';
import { readWords } from '@reintent/language/said';
import { vocab } from '@reintent/lib/vocab';

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 [hat] = intent.realize().reads;

console.log(readWords(hat, '大得离谱')); // → { kind: 'absurd' }
console.log(readWords(hat, '再小一点')); // → { dir: -1 }
console.log(readWords(hat, '一把黑伞')); // → null

rebind()

function rebind(
   said, 
   list, 
   by?
): Said;

Defined in: packages/language/src/said.ts

Bindings applied to words already said (a model's answer says where its new things are said): a span with exactly these words is bound again; otherwise the first stretch of them no span holds becomes a span.

Parameters

ParameterTypeDefault value
saidSaidundefined
listreadonly Binding[]undefined
by"code" | "model" | "human"'model'

Returns

Said


rewrite()

function rewrite(
   said, 
   spanId, 
   text, 
   patch?
): Said;

Defined in: packages/language/src/said.ts

What was said with one span's words replaced, every span after it shifted.

Parameters

ParameterType
saidSaid
spanIdstring
textstring
patchPartial<Span>

Returns

Said


status()

function status(s, reads): SpanStatus;

Defined in: packages/language/src/said.ts

Where a span and its choice stand, against what an evaluation read.

Parameters

ParameterType
sSpan
readsreadonly ChoiceRead[]

Returns

SpanStatus

Example

import { createIntent, entity, host, useChoose } from '@reintent/core';
import { bind, status } from '@reintent/language/said';
import { vocab } from '@reintent/lib/vocab';

const Size = vocab({ usual: { words: ['正常'] }, absurd: { words: ['大得离谱'] } });
const man = entity('man', { hat: Size.decl({ default: 'absurd' }) });
const Man = man(function Man() {
  return host('man', { hat: useChoose(man.hat).kind });
});

const intent = createIntent({ program: <Man /> });
const said = bind('一顶大得离谱的帽子', [['大得离谱', 'man', 'hat', 'absurd']]);
const [span] = said.spans;

console.log(status(span, intent.realize().reads)); // → 'agrees'
intent.decide(man.hat('man'), 'usual'); // a person clicked another size
console.log(status(span, intent.realize().reads)); // → 'differs'
console.log(status({ ...span, name: 'umbrella' }, intent.realize().reads)); // → 'orphan'

textOf()

function textOf(said, s): string;

Defined in: packages/language/src/said.ts

The words of a span.

Parameters

ParameterType
saidSaid
sSpan

Returns

string


withSpan()

function withSpan(spans, s): Span[];

Defined in: packages/language/src/said.ts

The spans with s added in order (any it overlaps replaced).

Parameters

ParameterType
spansreadonly Span[]
sSpan

Returns

Span[]


wordsFor()

function wordsFor(
   read, 
   kind, 
   prompt?
): string;

Defined in: packages/language/src/said.ts

How a possibility is said in words like prompt: its first word in the prompt's script, else its label.

Parameters

ParameterTypeDefault value
readChoiceReadundefined
kindstringundefined
promptstring''

Returns

string

Last updated on

Edit on GitHub