|
Release 0.6.4 - April 2006
10 Tree Module
The Tree module provides an expert with the skill to store information in a simple tree structure in main memory. We define a Tree expert as follows.
define table1 expert tree; define table2 expert tree;
When assertions are made to a Tree expert, it simply stores the asserted values.
assert table1(1,3,5,”abc”),table1(1,3,6,”xyz”);
To evaluate expert conditions, the skill module does a lookup on the tree.
define r1 on(x and y); assert a=1,b=3; assert x==table1(a,b); # x is 1 (true) because node (1,3) is present
You might expect the value of a Tree expert condition to be False (0) when the specified node has not been asserted. Instead the value is Unknown.
assert b=4; # This makes x Unknown
A false value can be assigned to a node.
assert !table1(a,b); # table1(1,4) is now False
To remove an entry from a tree, you assert it to be Unknown.
assert ?table1(a,b); # table1(1,4) is now Unknown
You may actually assign any value to a tree entry.
assert table1(a,b)=25; # table1(1,4) is now 25 assert table1(a,b)=”abc”; # table1(1,4) is now “abc” assert table1(a,b)=a+b; # table1(1,4) is now 5 assert table1(a,b)=1; # table1(1,4) is still True assert table1(a,b)=0; # table1(1,4) is now False assert table1(a,b)=??; # table1(1,4) is now Unknown
A skill module is not required to fully implement the NodeBrain model. For example, the Tree module does not properly implement the association of a definition with a tree entry. That is, “assert table1(1,2,3)==a*b;” will not work the way you hope.
We have shown how values are asserted to a table implemented by the Tree skill. Now let’s look at how we might reference the table in conditions. We just mentioned a limitation. If tree entries are given definitions, our conditions will not respond as one might hope. (This would require a minor enhancement to our skill module.) Otherwise, we can expect a tree expert condition to take on the value of the currently referenced row.
define r1 on(table(a,b)); define r2 on(!table(b,a)); define r3 on(?table(a,b)); assert a=1,b=4; assert table(a,b),!table(b,a); # rules r1 and r2 fire assert ?b; # rule r3 fires assert b=4; # rules r1 and r2 fire assert ?table(1,4); # rule r3 fires
Notice that an assertion takes the values of the argument cell expressions at the time of assertion, but a condition “monitors” the value of these cells. In our example above the cell expressions are simple terms (“a” and “b”). Changes to the values of these terms change the table entry being referenced by the condition. Changes to the table entries will also change the value of the condition.
In an actual application, you might use tree expert tables for classification. For example, one might create a table of web server host names and reference it in an event monitoring IF rule.
define webserver expert tree; assert webserver(“happy.web.mycompany.com”); assert webserver(“lucky.web.mycompany.com”);
define r1 if(webserver(server) and event=”abc”):action
# The following alert will cause r1 to fire alert event=”abc”,server=”lucky.web.mycompany.com”;
You may notice that this is no different than a cache with no expiration interval. However, values can not currently be assigned to cache entries, so the following would not be possible with a cache.
define serverGroup expert tree.tree; assert serverGroup(“lucky.web.mycompany.com”)=”webServer”; assert serverGroup(“dns1.mycompany.com”)=”dnsServer”;
define r1 if(serverGroup(server)=”webServer” and event=”abc”):action
# The following alert will cause r1 to fire alert event=”abc”,server=”lucky.web.mycompany.com”;
It is also important to understand that a cache uses the “closed world” assumption, returning False when an entry is not asserted while a tree returns Unknown. A tree only returns False when an entry has been asserted to be False. For this reason, you test for existence in a tree expert table using the “?” operator, but use “!” when testing for existence in a cache expert table. define cacheTable expert cache:(s); define treeTable expert tree;
# take action if server is not in either table define r1 if(!cacheTable(server) and ?treeTable(server)):action
The expert skills, cache and tree, are not aware of the operators we are using here. We are simply choosing the appropriate operator based on our awareness of what value these skills return when an entry is not defined---cache returns False (0) and tree returns Unknown (??)
Copyright © 2003-2006 The Boeing Company |