| 
#!/usr/bin/php -q
<?php
 /*
 Author: Bob Wedwick
 USE: php XbertClassDemo.php
 
 5/15/2017  - demonstrating XbertClass.php
 
 */
 
 # require the expert class
 require_once "XbertClass.php";
 
 # create a new Xbert object
 $exp = new Xbert;
 
 /*
 # if planning to access mySql tables
 # connect to the database now
 
 # notify Xbert of the connection - $exp->DbConnection()
 $exp->DbConnection($dbconnection);
 
 # Run a rule set from a table. Be sure to set $csv to false. $exp->RunXbert()
 $exp->RunXbert('YourRuleSet', $csv=false);
 */
 # try -- exceptions may be used in any rule set
 try {
 
 # run expert with the csv rule set - $exp->RunXbert()
 $exp->RunXbert('MasterMenu.xbt');
 
 # when any exception is caught
 } catch (Exception $e) {
 
 # echo the exception error message
 echo "Caught exception: {$e->getMessage()} \r\n";
 
 # do whatever else like sending an email.
 
 # end exception
 }
 
 /*
 Open any of these files with a text editor to see the variations
 in how they were created.
 
 These are most interesting and are in the Master Menu
 $exp->RunXbert('ButtermilkPancakes.xbt');
 $exp->RunXbert('Lupus.xbt', $csv=true);
 $exp->RunXbert('MacularDegeneration.xbt', $csv=true);
 $exp->RunXbert('Matematiko.lerta');
 
 These rule sets are also in the Master Menu and run specific examples.
 $exp->RunXbert('Comments.xbt');
 $exp->RunXbert('FlowControlTest.xbt');
 $exp->RunXbert('Nodes.xbt');
 $exp->RunXbert('Math.xbt');
 $exp->RunXbert('OpenTest.xbt');
 $exp->RunXbert('SetVars.kno');
 $exp->RunXbert('SymbolicLevel.xbt');
 $exp->RunXbert('TraceFile.xbt');
 $exp->RunXbert('Variables.xbt');
 $exp->RunXbert('Vars.kno');
 $exp->RunXbert('VarsA.kno');
 $exp->RunXbert('Weather.know');
 $exp->RunXbert('YesNoTest.xbt');
 
 These rule sets are called from other rule sets, but can be run individually.
 $exp->RunXbert('BP_CookPancakes.xbt');
 $exp->RunXbert('LupusCause.xbt');
 $exp->RunXbert('MathASMD.xbt');
 $exp->RunXbert('MathMaxMin.xbt');
 $exp->RunXbert('MD_Disclaimer.xbt');
 $exp->RunXbert('MD_NoSeeDr.xbt');
 $exp->RunXbert('MD_SeeDr.xbt');
 $exp->RunXbert('OpenTest2.xbt');
 $exp->RunXbert('OpenTest3.xbt');
 $exp->RunXbert('SetVars2.kno');
 */
 
 # end main
 
 ### UserCall - optional function called from a rule set
 function UserCall($msg) {
 # globals
 global $exp;
 
 # designer can use the message to decide what to do.
 
 # examples include putting a message in the conclusion, changing databases,
 # changing directories, retrieving CSV rule sets from the internet...
 
 # end function
 }
 
 ### UserDebug() - user debug interface called from a rule set
 function UserDebug($msg) {
 # globals
 global $exp;
 
 # an example of what can be done.
 # get the value of control values or arrays
 $a = $exp->RuleSetControlValue('abortWord');
 $m = $exp->userMessage;
 $d = $exp->RuleSetNumber();
 
 print_r($exp->ruleSetControl[$d]);
 
 # send the message to the user interface - UserInterface()
 UserInterface( "\r\n---Debug Messages---\r\n$msg\r\n u.m. $m\r\n* / * / *\r\n\r\n");
 
 # return
 return;
 
 # end function
 }
 
 ### UserDebugA() - alternate user debug interface with the function name of your choice
 function UserDebugA($msg) {
 # globals
 global $exp;
 
 # an example of what can be done.
 # get the value of control values or arrays
 $a =$exp->RuleSetControlValue('nodeId');
 $c = $exp->RuleSetControlValue('command');
 $n = $exp->RuleSetControlValue('currentNode');
 
 # send the message to the user interface - UserInterface()
 UserInterface( "\r\n---Debug Message---\r\n$msg\current level is $n, nNode ID is $a, \r\n"
 ." command is $c\r\n-----\r\n\r\n");
 
 # return
 return;
 
 # end function
 }
 
 ### UserInterface() - communication with the expert engine via console
 function UserInterface($msg) {
 
 /* if a different user interface is to be used, it is coded
 either here or in an alternate interface function.
 For example the interface can be with a browser,
 web page, or another program.
 */
 
 # display the message from Xbert
 echo "$msg";
 
 # get user response
 $reply = fgets(STDIN);
 $reply = trim($reply);
 
 # return the response
 return $reply;
 
 # end function
 }
 
 ### Finalize() - called, if exists, whenall rule sets are finished.
 function Finalize() {
 
 # globals
 global $exp;
 
 # var for any messages
 $say = '';
 
 # if there is a conclusion - $exp->Conclusion()
 if ($msg = $exp->Conclusion()) {
 
 # add it to what to say
 $say .= "CONCLUSION: \r\n$msg\r\n";
 # ....
 }
 
 # if there is a summary message - $exp->SummaryMessage()
 if ($msg = $exp->SummaryMessage()) {
 
 #add to what to say
 $say .=  "SUMMARY: \r\n$msg";
 
 # ....
 }
 
 # if anything to say
 if ($say) {
 
 # send it to the user interface - UserInterface()
 UserInterface($say);
 
 # ....
 }
 
 # end function
 }
 
 # end script
 ?>
 |