Table of Knowledge Base Functions

The functions used to operate on objects in the Knowledge Base have been listed here in table form for easy reference.  For examples of these functions, please refer to the individual function pages within the subsections of the current Help section, Knowledge Base Functions.

The names of KB objects are abbreviated as follows: concept (CON), attribute (ATTR), value (VAL), and phrase (PHR).

The return types include: CON, ATTR, VAL, PHR, INT (integer),  FLT (float), STR (string), BOOL (Boolean).  Boolean type is currently implemented by integer 1 (or non-zero) for true and 0 for false.)  NONE indicates nothing is returned.

In the table below, a name must be a STR, parent is a CON, attr_str is a STR, hier is a CON.

FUNCTION(ARG1,ARG2...)

RETURN TYPE

DESCRIPTION

Command File Functions

 

 

kbdumptree(root_con, file_str)

BOOL

Create a dump file of knowledge base concept.

take(file_str)

BOOL

Execute commands in a knowledge base command file (.KB file)

Functions that Find and Fetch

 

 

findroot()

CON

Find the root concept of the knowledge base (named concept).

findconcept(con, str)

CON

Find and return the concept with name str under the parent concept con.

findconcept(con, num)

CON

Find concept number num under the parent concept con.

findattr(con, str)

ATTR

Fetch attribute named str belonging to concept con.

findattrs(con)

ATTR

Fetch concept's list of attributes.

attrname(attr)

STR

Fetch attribute's name.

attrvals(attr)

VAL

Fetch attribute's list of values.

findvals(con, name)

VAL

Fetch list of values for a concept's attribute.

numval(con, name)

NUM

Fetch numeric-value of attribute (must be first).

fltval(con, name)

FLT

Fetch float value of attribute (must be first).

strval(con, name)

STR

Fetch string-value of attribute (must be first).

conval(con, name)

CON

Fetch concept-value of attribute (must be first).

attrwithval(con, attr_str, val_str)

BOOL

Check if concept's attribute has given value (multiple-value aware). Note that second two arguments must be STR.

inheritval(con, name, topCon)

STR

Find string attribute's value up the hierarchy. con is the current concept, topCon is the root to be searched up to, and name is the name of the attribute. If hier==0, goes to root of KB.

conceptname(con)

STR

Fetch name of given concept.

conceptpath(con)

STR

Fetch entire path of given concept as a string.

pathconcept(str)

CON

Fetch concept, given the path str.

wordpath(str)

STR

Get entire path of dictionary concept for the given string.

findwordpath(str)

STR

Find entire path of dictionary concept for the given string. (If not present, don't add the word.)

wordindex(str)

CON

Fetch index entry for dictionary concept.  Gets index concept that str would be added under.

findhierconcept(name, hier)

CON

Find a concept in the subhierarchy of a given concept. e.g.: G("returnedConcept") = findhierconcept("child",G("ancestor")); finds the concept named "child" anywhere under the concept pointed to by G("ancestor").

dictfindword(str)

CON

Find dictionary concept in dictionary hierarchy of KB.

dictfirst()

CON

Fetch the first word-concept in the KB dictionary hierarchy. (New in 1.6)

dictnext(con)

CON

Fetch the word following the given word in the KB dictionary hierarchy. (New in 1.6)

attrexists(hier, attr_s, val_s)

BOOL

Find attribute and value pair in the subhierarchy of a concept.

attrchange(hier, attr_s, val_s, new_s)

BOOL

Replace all matching attribute-value pairs in the given hierarchy to have the new string value, new_s.

down(con)

CON

Fetch the first child of given concept.

up(con)

CON

Fetch the parent of the given concept.

prev(con)

CON

Fetch the left or previous sibling of concept.

next(con)

CON

Fetch the right or next sibling of concept.

nextattr(attr)

ATTR

Fetch the next attribute in a list of attributes

nextval(val)

VAL

Fetch the next value in a list of values.

getsval(val)

STR

Fetch value as a string from a numeric or string-valued KB value object.

getstrval(val)

STR

Fetch the string value from a KB value object.

getnumval(val)

INT

Fetch number from numeric VAL.

getconval(val)

CON

Fetch concept from value.

Functions that Create

 

 

makeconcept(parent, name [, num] )

CON

Make concept under given parent concept. Optionally as the numth child of the parent. num==0 or absent places concept at end of list of children. name is the name of new concept.

addattr(con, attr_s)

ATTR

Add an attribute with no value to given concept.

addsval(con, name, num)

NONE

Add numeric value num as a string to concept con's attribute called name.

addstrval(con, name, str)

NONE

Add str as string value to concept con's attribute called name.

addnumval(con, name, num)

NONE

Add num as numeric value to concept con's attribute called name.

addconval(con, name, con_val)

NONE

Add concept value con_val to concept's name attribute.

getconcept(parent, name)

CON

Get or make named concept under parent.

addword(str)

CON

Add dictionary concept to the dictionary within the KB, if not present. In either case, fetch the dictionary concept for the word.

dictgetword(str)

CON

Same as addword; more principled function name.

sortconsbyattr(arr_c, attr_s, numeric_b, descending_b)

ARR

Given an array (multi-valued variable) of KB concepts, sort the concepts by the given attribute. numeric_b = 1 if num, 0 if string type attribute.  descending_b = 1 if descending order, 0 if ascending.  E.g.,

G("sorted") = sortconsbyattr(G("cons"),"count",1,0);

will sort an array of KB concepts by their "count" attribute in ascending order, assigning a new sorted array to G("sorted").  The given array in G("cons") is left unaltered. New in 1.6

Functions that Move and Remove

 

 

rmconcept(con)

BOOL

Remove concept con from Knowledge Base. Removes entire subhierarchy.

rmchild(con, str)

BOOL

Remove child named str from parent concept con.

rmchild(con, num)

BOOL

Remove number num child of parent concept con.

rmvals(con, str)

BOOL

Remove attributes and values of concept con's attribute named str.

rmval(attr, val)

BOOL

Remove value val from attribute attr.

rmattrval(con, str1, str2)

BOOL

Remove value named str2 from attribute named str1 under concept con. Also removes the attribute.

rmattrs(con)

BOOL

Remove concept's attributes (except for system internal ones).

rmattr(con,name)

BOOL

Remove concept's named attr and values.

rmchildren(con)

BOOL

Remove concept's children and phrase.

rmword(str)

BOOL

Remove dictionary concept from KB.

prunephrases(hier)

BOOL

Remove all phrases from given subhierarchy.

replaceval(con, name, str)

NONE

Replace named attribute's value(s) with str.

replaceval(con, name, num)

NONE

Replace named attribute's value(s) with num.

replaceval(con, name, con_val)

NONE

Replace named attribute's value(s) with concept con_val

renameconcept(con, name)

NONE

Rename given concept to name.

renamechild(con, num, name)

NONE

Rename con's numth child concept to name.

renameattr(con, name, new)

NONE

Rename con's named attribute to new.

movecleft(con)

NONE

Move concept before previous sibling.  (Moves concept to the left in its list.)

movecright(con)

NONE

Move concept after next sibling.  (Moves concept to the right in its list.)

sortchilds(con)

NONE

Sort concept's immediate children alphabetically.

sorthier(con)

NONE

Sort concept's subhierarchy alphabetically.

Phrase and Node Functions

 

 

findphrase(con)

PHR

Fetch concept's phrase.

sortphrase(con)

NONE

Sort concept's phrase nodes alphabetically.

phraselength(con)

INT

Get number of nodes in concept's phrase.

nodeconcept(node)

CON

Fetch the concept that node is a proxy for. (Changed in 1.6)

nodeowner(node)

CON

Fetch the concept that owns the node's phrase. (NEW in 1.6)

findnode(phrase, name)

CON

Find first named node in phrase.

findnode(phrase, num)

CON

Find the numth node in phrase.

listnode(node)

CON

Fetch the first node in given node's list.

firstnode(phrase)

CON

Fetch the first node in phrase.

lastnode(phrase)

CON

Fetch the last node in phrase.

makephrase(con, name)

PHR

Make a phrase in con by creating named node.

addcnode(con, name)

CON

Add named node at end of con's phrase.

addnode(phrase, name, num)

CON

Add named node as numth in phrase.

rmnode(con)

NONE

Remove node from concept's phrase.

rmphrase(phrase)

NONE

Remove phrase from its concept.

rmcphrase(con)

NONE

Remove a concept's phrase.

renamenode(phrase, name, new)

NONE

Rename phrase's named node to new.

renamenode(phrase, num, new)

NONE

Rename phrase's numth node to new.

See Also

Special Functions

Formatting and I/O Functions

Parse Tree Functions

String Functions

Spelling Functions