A Universal Knowledge Store: Thoughts connected by links, with inheritance through is-a, queries that resolve inherited and conflicting knowledge, sequences, time counted in cycles, undo, and text and XML files.
More...
|
|
| UKS () |
| | Creates an empty, independent store. Call CreateInitialStructure for the core types.
|
| Thought? | GetOrAddThought (string label, ThoughtRef parent=default, Thought? source=null) |
| | The Thought with this label, created if there is none. A dotted label composes its parts: big.dog gets the parents big and dog (each created if needed), and is.not.! gets is.not and !. A trailing * makes a new numbered Thought (dog0, dog1, ...).
|
| virtual Thought | AddThought (string label, ThoughtRef parent=default) |
| | Always creates a new Thought; if the label is in use, a number is appended to it (a trailing * becomes the next free number). Without a parent the Thought is a root. Use GetOrAddThought to find a labeled Thought or create it.
|
|
Thought? | Labeled (string label) |
| | The Thought with this label (ignoring case), or null if there is none.
|
|
IReadOnlyList< Thought > | LabeledStartingWith (string prefix) |
| | The Thoughts whose labels start with prefix (ignoring case), in label order, e.g. to complete a label as it is typed. Links and sequence elements are included.
|
|
IReadOnlyList< Thought > | Roots () |
| | The Thoughts with no parents, the tops of the hierarchy (e.g. Thought, BrainSim).
|
|
int | ThoughtCount () |
| | The number of Thoughts in the store, not counting links or sequence elements.
|
|
int | LinkCount () |
| | The number of links in the store, including those within sequences.
|
|
int | SequenceElementCount () |
| | The number of sequence elements in the store.
|
| int | Merge (Thought redundantThought, Thought canonicalThought) |
| | Merges redundantThought into canonicalThought : every link from, to, or typed by the redundant Thought is redirected to the canonical one, reinforcement is combined, and the redundant Thought is deleted.
|
|
void | DeleteDescendants (Thought t) |
| | Deletes every descendant of t (even one with another parent) and removes all of t 's own links, including its is-a links and any sequences its links point to. t itself stays in the store, unlinked.
|
|
void | Reset () |
| | Empties the store: every Thought and label, the sequence cache, the undo history and everything counting down, and the cycle starts again at 1. Call CreateInitialStructure afterward for the core types.
|
| Link? | AddStatement (ThoughtRef source, ThoughtRef linkType, ThoughtRef target, string label="") |
| | Adds the statement [source → linkType → target], e.g. AddStatement("Fido", "is-a", "dog"). An identical stored link is reused, strengthened and fired. A conflicting link of the source (LinksAreExclusive) is weakened, and removed when its weight reaches 0 or when it is the negation of the new one. Each operand is a Thought or a label: an unknown label creates the Thought, under LinkType for the link type and under Unknown otherwise.
|
|
Link? | GetLink (ThoughtRef from, ThoughtRef linkType, ThoughtRef to) |
| | The stored link [from → linkType → to], or null if there is none or a label is unknown. An empty to means a link with no target. Only the link itself counts, not inheritance.
|
| IReadOnlyList< Link > | GetAttributes (ThoughtRef source, Link? filter=null, int maxResults=0) |
| | Everything known about a Thought: its own links and those it inherits through is-a, strongest first. A more specific link overrides an inherited one it conflicts with (LinksAreExclusive), and a rule (a link with IF conditions) counts only while its conditions hold; Why and WhyNot then tell which conditions held and failed.
|
|
IReadOnlyList< Link > | Why () |
| | The rule conditions that held in the most recent GetAttributes.
|
|
IReadOnlyList< Link > | WhyNot () |
| | The rule conditions that failed in the most recent GetAttributes.
|
| IReadOnlyList< Link > | GetEvidence (Link attribute) |
| | The stored links that produce an attribute returned by GetAttributes: the inheritable links (is-a, ...) from the attribute's source up to the Thought that stores it, nearest first, then the stored link itself. For Fido's inherited fur: [Fido→is-a→dog], [dog→is-a→animal], [animal→has→fur]. A stored link alone means the attribute is stated on the source itself. A rule's conditions are the IF links on the stored link.
|
| IReadOnlyList< Link > | FindLinks (Link l) |
| | Finds the links matching a pattern link, where a null or wildcard part matches anything. With a source, inherited links are included (GetAttributes) and the type matches its descendants; otherwise the stored links to the target, or of the type, are searched.
|
|
bool | LinksAreExclusive (Link r1, Link r2) |
| | True if two links cannot both hold, e.g. [Fido→is→inside] and [Fido→is→outside] (targets under a class that isExclusive), a type and its negation (is, is.not), or different counts (has.3 legs, has.4 legs). The sources must be the same Thought or related by inheritance. Links stating history, possibilities (TYPE.?) and rules (IF) never conflict.
|
| IReadOnlyList<(Thought t, float conf)> | SearchByAttributes (Thought target, ThoughtRef root) |
| | Finds the Thoughts that most resemble target by its links, e.g. an observed object compared with known ones.
|
| IReadOnlyList< Link > | ApplyTestOrSetAction (Link action) |
| | Carries out an action link. With a TYPE.! type (one that has setRelationship) it writes [From → TYPE → To]; for an exclusive type the source's other links of that type are removed first. With a TYPE.? type (one that has isPossible) it asks: without wildcards, whether GetAttributes of From includes the link; with a wildcard operand, every matching link (FindLinks).
|
|
Thought? | GetPlainLinkType (Thought? linkType) |
| | The ordinary link type a SET (TYPE.!) or query (TYPE.?) type stands for: its most specific parent that is neither a marker nor a root; null if it has none.
|
| Link? | AddStatementRecordingHistory (ThoughtRef from, ThoughtRef type, ThoughtRef to) |
| | Adds the statement [from → type → to] like AddStatement, first keeping the history of the values it displaces. When the type or the target has the recordsHistory property, each statement of the source that is exclusive with the new one (LinksAreExclusive) is archived as a was.TYPE link at the head of the source's events sequence (newest first, with a validUntil time) and then removed, so only the new value remains in effect.
|
| SeqElement? | AddSequence (string label, IReadOnlyList< Thought >? targets, bool allowCompression=true) |
| | Stores a sequence of values, or returns the identical one already stored (a sequence is stored once and shared). With compression, a run of values that is already a stored sequence is replaced by that sequence (so "cats" can reuse "cat").
|
| SeqElement? | AddSequenceAndLink (Thought source, ThoughtRef linkType, IReadOnlyList< Thought > targets, bool allowCompression=true) |
| | Stores a sequence (AddSequence) and links an owner to it, e.g. [w:cat→spelled→^c a t], replacing the owner's previous link of that type.
|
| IReadOnlyList< Thought > | FlattenSequence (Thought? sequenceStart) |
| | The values of a sequence in order, with nested sequences expanded.
|
| IEnumerable< SeqElement > | EnumerateSequenceElements (SeqElement? sequenceStart) |
| | The elements of a sequence in order, descending into nested sequences, so each element returned holds a value that is not a sequence. A sequence that contains itself is not repeated.
|
| Thought? | GetElementValue (SeqElement? s, ThoughtRef valueClass=default) |
| | An element's value. An element can carry several values of different classes (a note and its duration, say); valueClass selects one.
|
|
bool | IsSequenceElement (Thought? t) |
| | True if the Thought is a sequence element.
|
|
bool | IsSequenceFirstElement (Thought? t) |
| | True if the Thought is the first element of its sequence (its FRST is itself).
|
| SeqElement | InsertAfter (SeqElement element, ThoughtRef value, bool atBeginning=false) |
| | Adds value to a sequence after element , or, with atBeginning , at the front of the sequence whose first element is element . The first element keeps its identity (its value moves to a new second element), so links to the sequence stay valid. An unknown label creates the value under Unknown.
|
| SeqElement | CreateFirstElement (string labelBase, ThoughtRef value) |
| | Starts a new, unshared sequence of one element, to be extended with InsertAfter. Unlike AddSequence, it never reuses an existing sequence.
|
|
void | DeleteSequence (SeqElement? s) |
| | Deletes a sequence's elements, given its first element. Nothing is deleted if another Thought also refers to the sequence (it is shared) or if s is not a first element.
|
|
IReadOnlyList< Thought > | GetReferringThoughts (SeqElement s, ThoughtRef linkType) |
| | The owners of a sequence: the sources of links of the given type to its element s .
|
| IReadOnlyList<(SeqElement seqNode, float confidence)> | FindSequencesByActivation (SeqElement? sequence, ThoughtRef searchOptions=default, bool getFirstElements=true, SeqElement? last=null, ThoughtRef valueClass=default, ThoughtRef alternativeClass=default, ThoughtRef matchClass=default) |
| | Finds the stored sequences that match an input sequence, by activation: each input value activates the stored elements holding it, and activation passes along NXT links.
|
| IReadOnlyList<(SeqElement seqNode, float confidence)> | FindSequencesByActivation (IReadOnlyList< Thought > pattern, ThoughtRef searchOptions=default, bool getFirstElements=true, ThoughtRef valueClass=default, ThoughtRef matchClass=default) |
| | Finds the stored sequences that match a pattern of values, by activation (see the overload taking an input sequence). With wildcards allowed, a wildcard in the pattern matches values of its class.
|
| Thought | CreateSearchOptions (bool mustMatchFirst=false, bool mustMatchLast=false, bool allowWildcard=false, bool allowNestedSequences=false, bool allowTrailingInput=false) |
| | Creates a search options Thought (under SearchOption) for FindSequencesByActivation.
|
| Thought | CreateWildcard (string wildcardName, IEnumerable< Thought > parentThoughts, string wildcardProperty="isWildcard") |
| | Gets or creates a wildcard: a Thought that, in a sequence pattern, matches any value of its classes (??.noun matches any noun).
|
|
Thought | GetOrAddCharacter (char character) |
| | The Thought for a written character (under character), created if needed.
|
| SeqElement? | CreateSpellingSequence (string spelling, Thought? owner) |
| | Stores a word's spelling as a sequence of characters and links the owner to it with spelled.
|
| IReadOnlyList< Thought > | AdvanceCycle () |
| | Agent: advances Cycle by one and counts down every finite TimeToLive. A Thought whose time runs out is deleted (a Link is removed from its source).
|
|
void | StartClock () |
| | Starts a background thread that calls AdvanceCycle CyclesPerSecond times a second. It keeps to the rate however coarse the system timer is, but after a stall (a debugger break) it skips the lost time instead of aging everything at once.
|
|
void | StopClock () |
| | Stops the clock: nothing ages or expires until it is started again.
|
|
void | RunPeriodically (Func< IReadOnlyList< Thought > > agent, TimeSpan? interval) |
| | Runs an agent every interval, e.g. RunPeriodically(uks.BubbleAttributes, TimeSpan.FromSeconds(10)). A null interval stops it. If called from a thread with a synchronization context (a UI thread), the agent runs on that thread; otherwise on a pool thread, never overlapping another agent run.
|
|
void | ChangeUndoably (string description, Action change) |
| | Makes a change as one transaction and remembers it for UndoLast, if it changed anything. If a transaction is already open, the change becomes part of it instead.
|
| bool | TryChange (string description, Func< bool > change) |
| | Makes a change as one transaction and keeps it only if it succeeds: if change returns true, the change is remembered for UndoLast; if it returns false or throws, it is undone. Changes made this way do not nest.
|
| string? | UndoLast () |
| | Undoes the most recent remembered change, from whichever source made it (the interpreter, a dialog). Earlier changes can be undone in turn.
|
|
bool | CreatedInCurrentChange (Thought thought) |
| | True if the change in progress (ChangeUndoably or TryChange) created the Thought, rather than finding it already there.
|
|
void | CreateInitialStructure () |
| | Empties the store and creates the core structure: the root Thought with Unknown, Abstract, Object, Action and LinkType under it; the core link types (is-a, hasProperty, the sequence links FRST, NXT and VLU, and IF and AND for rules); the markers ? and ! for asking and setting; the wildcard ??; and the sequence search options. Thoughts under BrainSim (a host's module layout) are kept.
|
| void | ImportTextFile (string filePath) |
| | Reads a text knowledge file into the store: one statement per line, [from->type->to], optionally preceded by a label and followed by a weight; nested statements ([a->means->[b->is->c]]), sequences (^a b c) and # comments. Firing is suppressed while reading.
|
| Thought? | ProcessSingleLine (string line) |
| | Reads one line of the text format (ImportTextFile) and adds what it states.
|
| Thought? | ProcessSingleLineWithNesting (string line, bool asPattern=false, bool asActionPrototype=false) |
| | Reads one line of the text format and adds what it states, treating the operands of IF and AND as patterns (TYPE.? possibilities) rather than statements.
|
| void | ExportTextFile (ThoughtRef root, string path) |
| | Writes root , its descendants and everything they link to in the text format (ImportTextFile): one line per link, [from->type->to], followed by its weight, MaxWeight and IsPlastic when they are not the defaults.
|
| bool | SaveXml (string path="") |
| | Saves the store to an XML file: labels, links, weights and string values (not firing or time to live).
|
| bool | LoadXml (string path="") |
| | Replaces the store's content with an XML file written by SaveXml.
|
|
UKS | Copy () |
| | An independent copy of this store's saved content (what SaveXml would write), e.g. to try a change and inspect the result without touching the original. Like a saved file, it keeps labels, links, weights and string values, but not firing or time to live.
|