Reintent

@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

PropertyTypeDescription
idId-
keystring-
kindstring-
match"kind" | "step"What the words matched: a possibility's own words ('kind'), or a step along an ordered choice ('step').
not?booleanRuled 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

PropertyTypeDescription
focus?stringThe thing on screen: when no thing is named, its choices are read first.
newThings?booleanRead an indefinite noun that names no thing as a new thing (default false).
of?stringSaid of this thing (a choice's of): only its choices are read.

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

NameTypeDescription
bind?objectWhere the edited words are bound once the event lands: a span of them, or a stretch.
bind.fromnumber-
bind.span?string-
bind.tonumber-
editWordEdit-
forget?IdWords taken back from a choice: the decision they made goes (if they made it), it is judged again.
saidSaidThe 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

ParameterTypeDefault value
rPick<EditRecognized, "said" | "bind">undefined
to{ kind?: string; name?: string; of: string; }undefined
to.kind?stringundefined
to.name?stringundefined
to.ofstringundefined
by"code" | "model" | "human"'human'

Returns

Said


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

ParameterType
textstring

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

ParameterType
textstring
readsreadonly ChoiceRead[]

Returns

string | undefined


recognize()

function recognize(
   text, 
   reads, 
   opts?
): Recognized;

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

Parameters

ParameterType
textstring
readsreadonly ChoiceRead[]
optsRecognizeOptions

Returns

Recognized

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

ParameterType
saidSaid
nextstring
readsreadonly ChoiceRead[]
optsRecognizeOptions

Returns

EditRecognized

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

ParameterType
needNeed

Returns

Tier

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