UKS
Loading...
Searching...
No Matches
UKS.UKS Class Reference

Contains a collection of Things linked by Relationships to implement Common Sense and general knowledge. More...

Public Member Functions

 UKS ()
 Creates a new reference to the UKS and initializes it if it is the first reference.
virtual Thing AddThing (string label, Thing parent)
 This is a primitive method needed only to create ROOT Things which have no parents.
virtual void DeleteThing (Thing t)
 This is a primitive method to Delete a Thing...the Thing must not have any children.
Thing Labeled (string label)
 Uses a hash table to return the Thing with the given label or null if it does not exist.
bool ThingInTree (Thing t1, Thing t2)
Relationship GetRelationship (Thing source, Thing relType, Thing target)
Relationship GetRelationship (Relationship r)
List< ThingThingListFromObject (object o, string parentLabel="unknownObject")
void DeleteAllChildren (Thing t)
 Recursively removes all the descendants of a Thing. If these descendants have no other parents, they will be deleted as well.
Thing GetOrAddThing (string label, object parent=null, Thing source=null)
 Creates a new Thing in the UKS OR returns an existing Thing, based on the label.
void CreateInitialStructure ()
void SetupNumbers ()
bool SaveUKStoXMLFile (string filenameIn="")
 Saves the UKS content to an XML file.
bool LoadUKSfromXMLFile (string filenameIn="", bool merge=false)
 Loads UKS content from a prvsiously-saved XML file.
List< ThingGetAllAttributes (Thing t)
 Gets all relationships to a group of Things including inherited relationships.
List< RelationshipGetAllRelationships (List< Thing > sources, bool reverse)
IList< RelationshipFilterResults (List< Relationship > result, List< Thing > ancestors)
 Filters a list of Relationships returning only those with at least one component which has an ancestor in the list of Ancestors.
float HasSequence (Thing pattern, Thing candidate, out int bestOffset, bool circularSearch=false, Thing relType=null)
 This determines how well two Things match in terms of the order of their ordered attributes.
List< ThingFindThingsWithAttributes (List< Thing > attributes)
 Returns a list of Things which have ALL the given attributes (IS Relationships)
List< RelationshipWhyNot ()
 Returns a list of Relationships which were false in the previous query.
List< RelationshipWhy ()
 Returns a list of Relationships which were true in the previous query.
Thing GetNextClosestMatch (ref float confidence)
 Given that you have performed a search with SearchForClosestMatch, this returns the next-best result given the previous best.
Thing SearchForClosestMatch (Thing target, Thing root, ref float confidence)
 Search for the Thing which most closely resembles the target Thing based on the attributes of the target.
Relationship AddStatement (object oSource, object oRelationshipType, object oTarget, object oSourceProperties=null, object oTypeProperties=null, object oTargetProperties=null)
 Creates a Relationship.
Parameters may be Things or strings. If strings, they represent Thing labels and if the Things with those labels do not exist, they will be created.
If the RelationshipType has an inverse, the inverse will be used and the Relationship will be reversed so that Fido IsA Dog become Dog HasChild Fido.
If Attributes are given, they apply to the applicable source, type, or target parameter. Example "Fido","IsA","Dog",null,null,"Big" creates or locates an existing Thing which is a child of Dog and has the attribute IS Big (perhaps labeled Dog.Big). Then Fido is made a child of that Thing.
Relationship CreateTheRelationship (object oSource, object oRelationshipType, object oTarget, object oSourceProperties=null, object oTypeProperties=null, object oTargetProperties=null)
Relationship CreateTheRelationship (ref Thing source, ref Thing relType, ref Thing target, ref List< Thing > sourceProperties, List< Thing > typeProperties, ref List< Thing > targetProperties)
Thing SubclassExists (Thing t, List< Thing > thingAttributes, ref Thing bestMatch, ref List< Thing > missingAttributes)
Thing CreateInstanceOf (Thing t)
void ExportTextFile (string root, string path, int maxDepth=12)
 Export a neighborhood starting from root to the bracketed txt file format. Emits facts as [S,R,O] (or [S,R,O,N] when R is a numeric specialization like "has.4"). Optionally emits simple clause pairs if Relationship exposes a Clauses collection.
void ImportTextFile (string filePath)
 Text file format format: A line is one or more bracketed statements [S,R,O] or [S,R,O,N] (N weight), optionally chained by RELTYPE connector tokens between them. Examples: [Dog,has.4,leg] [Fido,plays,outside] IF [weather,is,sunny] [A,rel,B] WITH [C,rel,D] BECAUSE [E,rel,F] Comments (# or //) allowed outside quotes/brackets.
bool ParseOneLine (int lineNo, string raw)

Static Public Member Functions

static bool CanWriteTo (string fileName, out string message)
static string GetFullPathFromKnowledgeFileName (string fileName)
static void WriteTheRelationship (Relationship r)

Static Public Attributes

static List< RelationshiptransientRelationships = new List<Relationship>()

Properties

IList< ThingUKSList [get]
 Occasionally a list of all the Things in the UKS is needed. This is READ ONLY. There is only one (shared) list for the App.
string FileName [get]

Detailed Description

Contains a collection of Things linked by Relationships to implement Common Sense and general knowledge.

Member Function Documentation

◆ AddStatement()

Relationship UKS.UKS.AddStatement ( object oSource,
object oRelationshipType,
object oTarget,
object oSourceProperties = null,
object oTypeProperties = null,
object oTargetProperties = null )
inline

Creates a Relationship.
Parameters may be Things or strings. If strings, they represent Thing labels and if the Things with those labels do not exist, they will be created.
If the RelationshipType has an inverse, the inverse will be used and the Relationship will be reversed so that Fido IsA Dog become Dog HasChild Fido.
If Attributes are given, they apply to the applicable source, type, or target parameter. Example "Fido","IsA","Dog",null,null,"Big" creates or locates an existing Thing which is a child of Dog and has the attribute IS Big (perhaps labeled Dog.Big). Then Fido is made a child of that Thing.

Parameters
oSourcestring or Thing
oRelationshipTypestring or Thing
oTargetstring or Thing (or null)
oSourceAttributessString containing one or more Thing labels separated by spaces, list of strings with individusl Thing Labels, Thing, OR List of Things
oTypeAttributesSame
oTargetAttributessSame
Returns
The primary relationship which was created (others may be created for given attributes

◆ AddThing()

virtual Thing UKS.UKS.AddThing ( string label,
Thing parent )
inlinevirtual

This is a primitive method needed only to create ROOT Things which have no parents.

Parameters
label
parentMay be null
Returns

◆ DeleteAllChildren()

void UKS.UKS.DeleteAllChildren ( Thing t)
inline

Recursively removes all the descendants of a Thing. If these descendants have no other parents, they will be deleted as well.

Parameters
tThe Thing to remove the children from

◆ DeleteThing()

virtual void UKS.UKS.DeleteThing ( Thing t)
inlinevirtual

This is a primitive method to Delete a Thing...the Thing must not have any children.

Parameters
tThe Thing to delete

◆ FilterResults()

IList< Relationship > UKS.UKS.FilterResults ( List< Relationship > result,
List< Thing > ancestors )
inline

Filters a list of Relationships returning only those with at least one component which has an ancestor in the list of Ancestors.

Parameters
resultList of Relationships from a previous Query
ancestorsFilter
Returns

◆ FindThingsWithAttributes()

List< Thing > UKS.UKS.FindThingsWithAttributes ( List< Thing > attributes)
inline

Returns a list of Things which have ALL the given attributes (IS Relationships)

Parameters
attributesList of Things
Returns

◆ GetAllAttributes()

List< Thing > UKS.UKS.GetAllAttributes ( Thing t)
inline

Gets all relationships to a group of Things including inherited relationships.

Parameters
sources
reverseif true, the first parameter is a list of targets rather than sources
Returns
List of matching relationships

◆ GetNextClosestMatch()

Thing UKS.UKS.GetNextClosestMatch ( ref float confidence)
inline

Given that you have performed a search with SearchForClosestMatch, this returns the next-best result given the previous best.

Parameters
confidencevalue representin the quality of the match
Returns

◆ GetOrAddThing()

Thing UKS.UKS.GetOrAddThing ( string label,
object parent = null,
Thing source = null )
inline

Creates a new Thing in the UKS OR returns an existing Thing, based on the label.

Parameters
labelThe new label OR if it ends in an asterisk, the astrisk will be replaced by digits to create a new Thing with a unique label.
parent
source
Returns
Exceptions
ArgumentException

◆ HasSequence()

float UKS.UKS.HasSequence ( Thing pattern,
Thing candidate,
out int bestOffset,
bool circularSearch = false,
Thing relType = null )
inline

This determines how well two Things match in terms of the order of their ordered attributes.

Parameters
patternThis is the pattern we are searching for
candidateThis is the item suggested as a possible sequence match< (the stored pattern)
bestOffsetReturn value of offset into the candidate where the pattern match begins.
relTypeIf specified, specifees the relationship type to follow, otherwise all sequential relTypes are matched
circularSearchIf true, circularizes the search of the candidate (for visuals)
Returns
Confidence that the pattern exists in the candidate

◆ Labeled()

Thing UKS.UKS.Labeled ( string label)
inline

Uses a hash table to return the Thing with the given label or null if it does not exist.

Parameters
label
Returns
The Thing or null

◆ LoadUKSfromXMLFile()

bool UKS.UKS.LoadUKSfromXMLFile ( string filenameIn = "",
bool merge = false )
inline

Loads UKS content from a prvsiously-saved XML file.

Parameters
fileNameInLeave null or empty to use file name from previous operation
mergeIf true, existing UKS content is not deleted and new content is merged by Thing label

◆ SaveUKStoXMLFile()

bool UKS.UKS.SaveUKStoXMLFile ( string filenameIn = "")
inline

Saves the UKS content to an XML file.

Parameters
fileNameInLeave null or empty to use file name from previous operation

◆ SearchForClosestMatch()

Thing UKS.UKS.SearchForClosestMatch ( Thing target,
Thing root,
ref float confidence )
inline

Search for the Thing which most closely resembles the target Thing based on the attributes of the target.

Parameters
targetThe Relationships of this Thing are the attributes to search on
rootAll searching is done within the descendents of this Thing
confidencevalue representing the quality of the match.
Returns

◆ Why()

List< Relationship > UKS.UKS.Why ( )
inline

Returns a list of Relationships which were true in the previous query.

Returns

◆ WhyNot()

List< Relationship > UKS.UKS.WhyNot ( )
inline

Returns a list of Relationships which were false in the previous query.

Returns

The documentation for this class was generated from the following files:
  • UKS.cs
  • UKS.File.cs
  • UKS.Query.cs
  • UKS.TextFile.cs
  • UKS.Statement.cs