gizai/written/english
a small English for a Reader (./reader.giz): people, cities, countries, foods and jobs, five relations between them, and the sentences that state and ask them. It gives the Reader's form, the worlds a Reader is trained on (drawn at random; no text of anyone), and the reading of a typed line: its words as the Reader's tokens, with each new name bound to a free entity of its kind.
A name is a label of an entity. The binding of names to entities is a table (Names), not weights: what the Reader learns from a sentence is the fact between the entities.
import * as English from "gizai/written/english";Types
World
type World = { to: Vec<Vec<i64>>; known: Vec<bool>; }A world: for each relation, the object (an index of its kind) of each subject, and whether each fact is written
(the facts in facts' order).
to:Vec<Vec<i64>>known:Vec<bool>
Names
type Names = { bound: Vec<Vec<string>>; }The names bound to the entities of each kind, in the order they were first read.
bound:Vec<Vec<string>>
Line
type Line = { kind: "told" | "asked" | "unread"; ask: Ask; told: Told; why: string; }What a line is: a sentence to write (told), a question (ask), or neither, with the reason in why.
kind:stringask:M52.Asktold:M52.Toldwhy:string
Functions
form
function form(): FormThe form of a Reader of this English.
Effects: fail, alloc.
world
function world(seed: u64): WorldThe world that seed draws: each relation's objects, and which facts the reader is told.
Effects: fail, alloc.
partly
function partly(w: World, seed: u64, percent: u64): Worldw with percent of its facts not written, drawn by seed.
Effects: fail, alloc.
facts
function facts(): Vec<Vec<i64>>Each fact's (entity, relation), for Reader.keys.
Effects: fail, alloc.
objects
function objects(w: World): Vec<i64>Each fact's object entity in w, for Reader.written.
Effects: fail, alloc.
asks
function asks(w: World): Vec<Vec<Ask>>Every question of w, and every sentence start (what the Reader asks before a sentence's last word): one set a
form, over its subjects.
Effects: fail, read, write, console, io, alloc.
basics
function basics(w: World): Vec<Vec<Ask>>The one-fact questions of w (one set a relation), in facts' order: what a Reader asks itself to study.
Effects: fail, read, write, console, io, alloc.
told
function told(w: World): Vec<Vec<Told>>Every sentence of w, written or not: one set a relation, in facts' order.
Effects: fail, read, write, console, io, alloc.
names
function names(): NamesNo names bound yet.
Effects: fail, alloc.
namesOf
function namesOf(text: string): NamesThe names that Names.encode wrote.
Effects: fail, alloc.
line
function line(n: mut Names, text: string): LineReads a typed line. A sentence binds its new names; a question binds none.
Effects: fail, read, write, console, io, alloc.
Methods
Names.encode
function Names.encode(self: Names): stringThe names as text: a line of names for each kind.
Effects: fail, alloc.
Names.say
function Names.say(self: Names, token: i64, unknown: i64): stringThe Reader's word token as text: the name of its entity, or that it does not know.
Effects: fail, alloc.