UKS
Universal Knowledge Store
Loading...
Searching...
No Matches
UKS.UKS Class Reference

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...

Public Member Functions

 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.

Static Public Member Functions

static bool IsWildcard (Thought t)
 True if the Thought is a wildcard: it, or an ancestor, has a wildcard property (CreateWildcard).
static string GetCharacterLabel (char character)
 The label of a character's Thought, e.g. c:A for 'a' (letters are upper-cased).

Static Public Attributes

const string CharacterPrefix = "c:"
 The label prefix of character Thoughts (c:A is the letter a).
const int CyclesPerSecond = 100
 The clock's rate (StartClock): one cycle every 10 ms.

Properties

bool SuppressFiring = false [get, set]
 While true, Thought.Fire does nothing, e.g. during a bulk import (ImportTextFile sets it while reading).
long Cycle = 1 [get]
 The UKS has no clock: time is counted in cycles, advanced by AdvanceCycle. While nothing advances it (the host paused, a debugger stopped), nothing ages or expires. Starts at 1, so a Thought.LastFiredCycle of 0 means never fired.
bool CanUndo [get]
 True if there is a remembered change to undo.
string FileName [get]
 The file last saved or loaded (SaveXml, LoadXml).

Events

Action< Thought >? ThoughtFired
 Raised whenever a Thought in this UKS fires. Handlers run on the firing thread and should be brief.

Detailed Description

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.

Each store is independent: a label always means a Thought of the store being called. Start a store with new UKS() and CreateInitialStructure, or load one with LoadXml.

Member Function Documentation

◆ GetOrAddThought()

Thought? UKS.UKS.GetOrAddThought ( string label,
ThoughtRef parent = default,
Thought? source = null )
inline

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, ...).

Parameters
labelThe label; an empty one returns null.
parentThe parent, a Thought or a label; empty means Unknown. An existing Thought under Unknown moves to the given parent.
sourceWith a label ending in *, reuse the first numbered Thought that source does not already have a link of (so each of its links gets its own number).
Returns
The Thought, or null for an empty label.

◆ AddThought()

virtual Thought UKS.UKS.AddThought ( string label,
ThoughtRef parent = default )
inlinevirtual

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.

Parameters
labelLabel of the Thought to create.
parentOptional parent, a Thought or a label; an empty or unknown one adds no parent.
Returns
The new Thought.

◆ Merge()

int UKS.UKS.Merge ( Thought redundantThought,
Thought canonicalThought )
inline

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.

Returns
The number of links which were redirected.

◆ AddStatement()

Link? UKS.UKS.AddStatement ( ThoughtRef source,
ThoughtRef linkType,
ThoughtRef target,
string label = "" )
inline

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.

Parameters
sourceThe source.
linkTypeThe link type.
targetThe target; may be empty (default).
labelOptional label for the link.
Returns
The link, or null if the source or link type is empty.

◆ GetAttributes()

IReadOnlyList< Link > UKS.UKS.GetAttributes ( ThoughtRef source,
Link? filter = null,
int maxResults = 0 )
inline

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.

Parameters
sourceThe Thought, or its label; an unknown label gives an empty list.
filterOptional: keep only results whose type and target descend from (or are) the filter's Link.LinkType and Link.To, where those are set.
maxResultsThe most results to return; 0 for all.
Returns
The links, each with the Thought as its source. An inherited result is a new, unstored link; GetEvidence gives the stored links behind it.

◆ GetEvidence()

IReadOnlyList< Link > UKS.UKS.GetEvidence ( Link attribute)
inline

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.

Returns
The evidence, or an empty list if no stored link produces the attribute (a count the query computed, for example).

◆ FindLinks()

IReadOnlyList< Link > UKS.UKS.FindLinks ( Link l)
inline

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.

Parameters
lThe pattern. A filterBy link on it keeps only targets that descend from its target.
Returns
New, unstored links describing the matches; empty if all three parts are open.

◆ SearchByAttributes()

IReadOnlyList<(Thought t, float conf)> UKS.UKS.SearchByAttributes ( Thought target,
ThoughtRef root )
inline

Finds the Thoughts that most resemble target by its links, e.g. an observed object compared with known ones.

Parameters
targetThe links of this (often unstored) Thought are the attributes to match.
rootOnly descendants of this Thought are candidates; an unknown label finds none.
Returns
The candidates with a confidence, best first.

◆ ApplyTestOrSetAction()

IReadOnlyList< Link > UKS.UKS.ApplyTestOrSetAction ( Link action)
inline

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).

Returns
The written link, the links that answer the question, or an empty list.

◆ AddStatementRecordingHistory()

Link? UKS.UKS.AddStatementRecordingHistory ( ThoughtRef from,
ThoughtRef type,
ThoughtRef to )
inline

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.

Returns
The added (or reinforced) statement, or null if the source or type is empty.

◆ AddSequence()

SeqElement? UKS.UKS.AddSequence ( string label,
IReadOnlyList< Thought >? targets,
bool allowCompression = true )
inline

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").

Parameters
labelThe label of the first element of a new sequence.
targetsThe values in order; a value may be the first element of another sequence.
allowCompressionFalse to store the values flat.
Returns
The first element, or null for no values.

◆ AddSequenceAndLink()

SeqElement? UKS.UKS.AddSequenceAndLink ( Thought source,
ThoughtRef linkType,
IReadOnlyList< Thought > targets,
bool allowCompression = true )
inline

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.

Parameters
sourceThe owner of the sequence.
linkTypeThe type of the owner's link; an unknown label creates it under LinkType.
targetsThe values in order; a value may be the first element of another sequence.
allowCompressionFalse to store the values flat.
Returns
The first element, or null for no values.

◆ FlattenSequence()

IReadOnlyList< Thought > UKS.UKS.FlattenSequence ( Thought? sequenceStart)
inline

The values of a sequence in order, with nested sequences expanded.

Parameters
sequenceStartThe first element; anything else gives an empty list.

◆ EnumerateSequenceElements()

IEnumerable< SeqElement > UKS.UKS.EnumerateSequenceElements ( SeqElement? sequenceStart)
inline

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.

Parameters
sequenceStartThe first element (or any element, to start there).

◆ GetElementValue()

Thought? UKS.UKS.GetElementValue ( SeqElement? s,
ThoughtRef valueClass = default )
inline

An element's value. An element can carry several values of different classes (a note and its duration, say); valueClass selects one.

Parameters
sThe element.
valueClassOptional: the value that is, or descends from, this class. Without it, the primary value (not one marked isSequenceMetadata).
Returns
The value, or null if there is none (or the class label is unknown).

◆ InsertAfter()

SeqElement UKS.UKS.InsertAfter ( SeqElement element,
ThoughtRef value,
bool atBeginning = false )
inline

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.

Returns
The element holding the new value.

◆ CreateFirstElement()

SeqElement UKS.UKS.CreateFirstElement ( string labelBase,
ThoughtRef value )
inline

Starts a new, unshared sequence of one element, to be extended with InsertAfter. Unlike AddSequence, it never reuses an existing sequence.

Parameters
labelBaseThe element's label is this followed by -seq0.
valueThe value; an unknown label creates it under Unknown.

◆ FindSequencesByActivation() [1/2]

IReadOnlyList<(SeqElement seqNode, float confidence)> UKS.UKS.FindSequencesByActivation ( SeqElement? sequence,
ThoughtRef searchOptions = default,
bool getFirstElements = true,
SeqElement? last = null,
ThoughtRef valueClass = default,
ThoughtRef alternativeClass = default,
ThoughtRef matchClass = default )
inline

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.

Parameters
sequenceThe first input element.
searchOptionsA search options Thought (CreateSearchOptions, or one of those CreateInitialStructure makes: ExactSequenceSearch, the default, TemplateSequenceSearch, ApproximateSequenceSearch, ...).
getFirstElementsTrue for each matching sequence's first element; false for the element where each match starts, which finds occurrences inside longer sequences (flat, literal searches only).
lastThe last input element to use; null for the whole input.
valueClassOptional: compare the values of this class (GetElementValue) in input and stored sequences.
alternativeClassOptional: where an input element has a value of this class, use it instead, as one value for the run of following elements that share it.
matchClassOptional: keep only sequences owned by a Thought of this class.
Returns
The matches with a confidence (the share of the stored sequence matched), best first.

◆ FindSequencesByActivation() [2/2]

IReadOnlyList<(SeqElement seqNode, float confidence)> UKS.UKS.FindSequencesByActivation ( IReadOnlyList< Thought > pattern,
ThoughtRef searchOptions = default,
bool getFirstElements = true,
ThoughtRef valueClass = default,
ThoughtRef matchClass = default )
inline

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.

Parameters
patternThe values to look for, in order.
searchOptionsA search options Thought; ExactSequenceSearch if empty.
getFirstElementsTrue for each matching sequence's first element; false for where each match starts.
valueClassOptional: compare the stored values of this class.
matchClassOptional: keep only sequences owned by a Thought of this class.
Returns
The matches with a confidence, best first.

◆ CreateSearchOptions()

Thought UKS.UKS.CreateSearchOptions ( bool mustMatchFirst = false,
bool mustMatchLast = false,
bool allowWildcard = false,
bool allowNestedSequences = false,
bool allowTrailingInput = false )
inline

Creates a search options Thought (under SearchOption) for FindSequencesByActivation.

Parameters
mustMatchFirstThe match must start at a sequence's first element.
mustMatchLastThe match must end at a sequence's last element.
allowWildcardWildcards in the input match values of their class.
allowNestedSequencesValues inside nested sequences are matched.
allowTrailingInputA stored sequence matches even if the input continues past its end.

◆ CreateWildcard()

Thought UKS.UKS.CreateWildcard ( string wildcardName,
IEnumerable< Thought > parentThoughts,
string wildcardProperty = "isWildcard" )
inline

Gets or creates a wildcard: a Thought that, in a sequence pattern, matches any value of its classes (??.noun matches any noun).

Parameters
wildcardNameThe wildcard's label.
parentThoughtsThe classes it matches; none matches anything.
wildcardPropertyHow many values it matches: isWildcard (one), isOptionalWildcard (zero or one), is*Wildcard (any number), is+Wildcard (one or more).
Exceptions
ArgumentExceptionThe property is not one of these.
InvalidOperationExceptionThe wildcard already exists with another property.

◆ CreateSpellingSequence()

SeqElement? UKS.UKS.CreateSpellingSequence ( string spelling,
Thought? owner )
inline

Stores a word's spelling as a sequence of characters and links the owner to it with spelled.

Returns
The first element, or null for an empty spelling or no owner.

◆ AdvanceCycle()

IReadOnlyList< Thought > UKS.UKS.AdvanceCycle ( )
inline

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).

Returns
The Thoughts that expired.

◆ TryChange()

bool UKS.UKS.TryChange ( string description,
Func< bool > change )
inline

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.

Returns
What change returned.

◆ UndoLast()

string? UKS.UKS.UndoLast ( )
inline

Undoes the most recent remembered change, from whichever source made it (the interpreter, a dialog). Earlier changes can be undone in turn.

Returns
The description of what was undone, or null if there was nothing to undo.

◆ ImportTextFile()

void UKS.UKS.ImportTextFile ( string filePath)
inline

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.

Parameters
filePathThe file to read.

◆ ProcessSingleLine()

Thought? UKS.UKS.ProcessSingleLine ( string line)
inline

Reads one line of the text format (ImportTextFile) and adds what it states.

Returns
The Thought or link, or null for a blank, comment or unreadable line.

◆ ProcessSingleLineWithNesting()

Thought? UKS.UKS.ProcessSingleLineWithNesting ( string line,
bool asPattern = false,
bool asActionPrototype = false )
inline

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.

Parameters
lineThe line, e.g. [[fido->is->wet]->IF->[fido->located->outside]].
asPatternRead the whole statement as a pattern: an ordinary type becomes TYPE.?, so nothing is asserted.
asActionPrototypeBuild the action link (a TYPE.! or TYPE.? statement) without connecting it to its Thoughts, as a template to carry out later with ApplyTestOrSetAction.
Returns
The Thought or link, or null if the line could not be read.

◆ ExportTextFile()

void UKS.UKS.ExportTextFile ( ThoughtRef root,
string path )
inline

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.

Parameters
rootThe starting Thought, or its label.
pathThe file to write.

◆ SaveXml()

bool UKS.UKS.SaveXml ( string path = "")
inline

Saves the store to an XML file: labels, links, weights and string values (not firing or time to live).

Parameters
pathThe file; empty to reuse FileName.
Returns
True if the file was written.

◆ LoadXml()

bool UKS.UKS.LoadXml ( string path = "")
inline

Replaces the store's content with an XML file written by SaveXml.

Parameters
pathThe file; empty to reuse FileName.
Returns
True if the file was read.

The documentation for this class was generated from the following files:
  • UKS.cs
  • UKS.Labels.cs
  • UKS.Query.cs
  • UKS.Sequence.cs
  • UKS.SequenceSearch.cs
  • UKS.Characters.cs
  • UKS.Time.cs
  • UKS.Journal.cs
  • UKS.XMLFile.cs
  • UKS.Statement.cs
  • UKS.Exclusivity.cs
  • UKS.Search.cs
  • UKS.Actions.cs
  • UKS.History.cs
  • UKS.SequenceApproximate.cs
  • UKS.Initialize.cs
  • UKS.TextFile.cs