ÿþ<HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-16" /> <META NAME="keywords" CONTENT="Android expert system,free expert system,expert system shell,expert system building tool,free expert system software, rule-based expert system,inference engine,knowledge bases,free Java applet, expert system tutorials,expert system training,e2gRuleEngine expert system shell"> <META NAME="description" CONTENT="A mini-course introducing the free e2gRuleEngine expert system building tool (expert system shell) implemented as a Java applet. e2gRuleEngine permits rule-based expert systems to be embedded in a Web page."> <TITLE>e2gRuleEngine/e2gDroid Free Expert System Shell - Knowledge Engineering Case Study</TITLE> </HEAD> <BODY BGCOLOR="#ffffff"> <TABLE CELLSPACING=0 BORDER=0 BGCOLOR="#ffee33" WIDTH="100%"> <TR><TD><IMG SRC="/e2g3g/images/e2gwide2.gif"></TD> <TD>&nbsp;&nbsp;</TD> <TD VALIGN=Center ALIGN=Left><script type="text/javascript"><!-- google_ad_client = "pub-0414996037110743"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel = ""; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script></TD></TR></TABLE> <FONT FACE="Arial,Helvetica" SIZE=2>[<A HREF="/e2g3g/">Home: Demos and Tutorials</A>][<A HREF="default.htm">e2gRuleEngine Mini-Course Index</A>] </FONT> <P><!--Designing and implementing...--> <CENTER><FONT FACE="Arial,Helvetica" SIZE=3><B>Building and Using Expert Systems: a Mini-Course Introducing the e2gRuleEngine/e2gDroid Expert System Shell and e2gRuleWriter Decision Table Software</B></FONT></CENTER> <P><FONT FACE="Arial,Helvetica" SIZE=3><B>Module 7: Designing and implementing e2gRuleEngine/e2gDroid knowledge bases that deliver <I>your</I>&nbsp; knowledge</B> </FONT> <FONT FACE="Arial,Helvetica" SIZE=3> <P><B>Module 7 Index</B> <UL> <LI><A HREF="#GRADADMIT">Graduate school admission decision case study</A> <LI><A HREF="#DEBUG">Recommendations for implementing and debugging a knowledge base</A> <LI><A HREF="#EVAL">Performing numerical calculations in rule consequents</A> <LI><A HREF="#HYPERLINK">Adding hyperlinks to final results and PROMPTS</A> <LI><A HREF="#VERSION8">v8.0 enhancements</A> <LI><A HREF="#ANDROID">Android capability and examples</A> <!--<LI><A HREF="#INFERENCE">Inferencing strategy options: the PROMPTFIRST and REFLAG parameters</A>--> </UL> <P> </FONT> <FONT FACE="Arial,Helvetica" SIZE=2> <A NAME="GRADADMIT"></A> <P>In this module, we'll use a hypothetical graduate school admission process as a case study to illustrate some ideas about knowledge base design, construction and debugging. A listing of the complete <A HREF="#ADMITKB">e2gRuleEngine graduate admissions knowledge base</A> is included in the module for reference. <P>If you haven't already done so, taking a look at <A HREF="/e2g3g/tutorials/knoweng/">Module 6: Introduction to Knowledge Engineering</A> is recommended because it provides supporting material for this discussion. We'll also assume that you have worked the examples in <A HREF="e2gmod4.htm">Module 4: Creating your first knowledge base</A> so that you know how to enter a knowledge base and create a Web page that loads the e2gRuleEngine applet to access your rules. <P><B>Admissions recommendation logic:</B> The logic for the example expert system is represented by the following flow chart: <P><TABLE BORDER=1 ALIGN=Center> <TR><TH bgcolor="#ffee33"><FONT FACE="Arial,Helvetica" SIZE=3>Graduate Admissions Recommendation Logic</TH></TR> <TR><TD> <IMG SRC="/e2g3g/images/admitf.gif"> </TD></TR></TABLE> <P><B>Framework:</B> An expert system is developed in a conceptual framework that represents the problem domain. This structure supports the knowledge decomposition that leads to the definition of attributes and creation of rules as described in <A HREF="/e2g3g/tutorials/knoweng/">Module 6</A>. Procedural examples like this admissions process are often documented in a flowchart or decision tree format when knowledge engineering begins. It is tempting to develop a rule to represent each path through the flow chart, but additional analysis that identifies and names subconcepts could produce a knowledge base that more clearly supports two of the justifications for using an expert system: the ability to explain why a recommendation was made and the ability to make a recommendation using a minimum amount of factual input. <P><B>Expert system outputs:</B> A list of the possible admissions recommendations can be extracted from the flow chart: <OL> <LI>Admit with full status <LI>Admit with full status (special decision) <LI>Admit provisionally <LI>Admit provisionally with recommended remedial English coursework <LI>Refer to academic department for decision <LI>Admit conditionally (special decision) <LI>Wait for transcript before making decision <LI>Deny normal admission (could be reviewed) </OL> <P>Recommendations 1-5 are possible for students who have provided a final undergraduate transcript. Recommendations 6-7 are possible for students who have not provided a final undergraduate transcript. Recommendation 8 is possible whether or not the undergraduate degree has been completed. <P><B>Expert system inputs:</B> Here is a grouped list of the attributes, identified from the flow chart, for which input PROMPTs will be written: <UL> <LI>Completion of undergraduate program <UL> <LI>Final undergraduate transcript availability </UL> <LI>English language requirement <UL> <LI>Bachelor's degree from US institution <LI>Test of English as a Foreign Language (TOEFL) </UL> <LI>Performance as an undergraduate <UL> <LI>Grade Point Ratio (GPR) last 60 Undergraduate (UG) hours <LI>Honor student <LI>Honor graduate <LI>Valedictorian <LI>Salutatorian </UL> <LI>Performance in prior graduate work (if any taken) <UL> <LI>Grade Point Ratio (GPR) for completed graduate work </UL> <LI>Performance on graduate admissions tests <UL> <LI>Graduate Record Exam (GRE) overall score <LI>Graduate Record Exam (GRE) verbal score </UL> </UL> <P><B>Certainty factors:</B> Because these inputs are factual rather than opinions, certainty factor input will not be requested for any of the PROMPTs in this knowledge base: the optional <B>CF</B> parameter is not used in the PROMPTs. <P><B>Multi-valued attributes:</B> There are four parameters representing special honors, and an applicant could possess any combination of these. The parameters are used in several rules, and the fact that an applicant possesses <I>none</I> of the attributes is also used in several rules. This set of circumstances is efficiently represented in an e2gRuleEngine knowledge base through the combined use of the AllChoice PROMPT along with the MAXVALS and DEFAULT statements: <FONT SIZE=+0><PRE> PROMPT [the applicant] AllChoice "This applicant is (check all that apply):" "an honor student" "an honor graduate" "a class valedictorian" "a class salutatorian" MAXVALS [the applicant] 4 DEFAULT [the applicant] = "not the recipient of special honors" </PRE></FONT> <P>The AllChoice PROMPT allows the knowledge base user to check any or all of the parameters describing the applicant's special honors. A MAXVALS statement allowing four values of <B>the applicant</B> must be included or values beyond the first one entered will be discarded. <P>It is often useful for a rule to detect the fact that no value can be found for an attribute. This is accomplished in e2gRuleEngine by employing the DEFAULT statement. The PROMPT for <B>the applicant</B> is the only source of values for this attribute. If none of the values are checked when the PROMPT is issued, the inference engine determines that the value cannot be resolved and the DEFAULT value "not the recipient of special honors" is assigned. Here is an example rule that will only fire for an applicant who has received <I>no</I> special honors: <FONT SIZE=+0><PRE> RULE [Conditional eval, low GRE] If [the evaluation] = "for a conditional decision" and [the applicant] = "not the recipient of special honors" and [the applicant's GRE score] < 1100 Then [the recommendation] = "wait for transcript" and [the action] = "based on established policy" </PRE></FONT> <P><B>Interim constructs:</B> Knowledge bases are sometimes simplified and recommendation justifications clarified by using interim constructs to capture a common theme. The next pair of rules captures the logic in the flow chart that determines the need to examine the applicant's undergraduate GPR: <FONT SIZE=+0><PRE> RULE [Consider undergraduate GPR (no grad credits)] If [the applicant's graduate status] = "no prior graduate work completed" Then [the undergraduate GPR should be considered] = true RULE [Consider undergraduate GPR (grad credits)] If [the applicant's graduate status] = "prior graduate work completed" and [the applicant's GPR on prior graduate work] > 2.99 Then [the undergraduate GPR should be considered] = true </PRE></FONT> The contrived attribute <B>the undergraduate GPR should be considered</B> may then be used in rules like the following: <FONT SIZE=+0><PRE> RULE [Deny because of undergraduate GPR] If [the undergraduate GPR should be considered] = true and [the applicant's GPR on last 60 undergraduate hours] < 2.5 Then [the recommendation] = "deny normal admission" and [the action] = "based on established policy" </PRE></FONT> Without this device, the following rules would be required to capture the same logic (and there are several similar rules that must determine whether to evaluate the undergraduate GPR): <FONT SIZE=+0><PRE> RULE [Deny because of undergraduate GPR (no grad credits)] If [the applicant's graduate status] = "no prior graduate work completed" and [the applicant's GPR on last 60 undergraduate hours] < 2.5 Then [the recommendation] = "deny normal admission" and [the action] = "based on established policy" RULE [Deny because of undergraduate GPR (grad credits)] If [the applicant's graduate status] = "prior graduate work completed" and [the applicant's GPR on prior graduate work] > 2.99 and [the applicant's GPR on last 60 undergraduate hours] < 2.5 Then [the recommendation] = "deny normal admission" and [the action] = "based on established policy" </PRE></FONT> <P><B>The knowledge base:</B> the complete knowledge base is provided in the following table as a reference. <A NAME="ADMITKB"></A> <P><TABLE BORDER=1 ALIGN=Center> <TR><TH bgcolor="#ffee33"><FONT FACE="Arial,Helvetica" SIZE=3>Graduate Admissions Knowledge Base</FONT></TH></TR> <TR><TD> <PRE> REM Graduate admissions demonstration expert system REM Decide how to proceed RULE [Language requirement] If [the applicant's UG status] = "receiving a bachelor's degree from a US institution" or [the applicant's TOEFL score] > 499 Then [the language requirement] = "met" RULE [Conditional consideration] If [the language requirement] = "met" and [the applicant's final undergraduate transcript] = "not available" Then [the evaluation] = "for a conditional decision" RULE [Full consideration] If [the language requirement] = "met" and [the applicant's final undergraduate transcript] = "available" Then [the evaluation] = "for a full decision" REM Conditional evaluation RULE [Wait for transcript] If [the evaluation] = "for a conditional decision" and [the applicant's GPR on last 60 undergraduate hours] < 3.3 Then [the recommendation] = "wait for transcript" and [the action] = "based on established policy" RULE [Honor student] If [the evaluation] = "for a conditional decision" and [the applicant's GPR on last 60 undergraduate hours] > 3.29 and [the applicant] = "an honor student" Then [the recommendation] = "admit conditionally" and [the action] = "based on special decision" RULE [Conditional eval, high GRE] If [the evaluation] = "for a conditional decision" and [the applicant] = "not the recipient of special honors" and [the applicant's GRE score] > 1099 Then [the recommendation] = "admit conditionally" and [the action] = "based on special decision" RULE [Conditional eval, low GRE] If [the evaluation] = "for a conditional decision" and [the applicant] = "not the recipient of special honors" and [the applicant's GRE score] < 1100 Then [the recommendation] = "wait for transcript" and [the action] = "based on established policy" REM Full evaluation REM Deny RULE [Deny because language requirement not met] If [the applicant's UG status] = "not receiving a bachelor's degree from a US institution" and [the applicant's TOEFL score] < 500 Then [the recommendation] = "deny normal admission" and [the action] = "based on established policy" RULE [Deny because of graduate GPR] If [the applicant's graduate status] = "prior graduate work completed" and [the applicant's GPR on prior graduate work] < 3.0 Then [the recommendation] = "deny normal admission" and [the action] = "based on established policy" RULE [Consider undergraduate GPR (no grad credits)] If [the applicant's graduate status] = "no prior graduate work completed" Then [the undergraduate GPR should be considered] = true RULE [Consider undergraduate GPR (grad credits)] If [the applicant's graduate status] = "prior graduate work completed" and [the applicant's GPR on prior graduate work] > 2.99 Then [the undergraduate GPR should be considered] = true RULE [Deny because of undergraduate GPR] If [the undergraduate GPR should be considered] = true and [the applicant's GPR on last 60 undergraduate hours] < 2.5 Then [the recommendation] = "deny normal admission" and [the action] = "based on established policy" RULE [Deny because of undergraduate GPR and GRE] If [the undergraduate GPR should be considered] = true and [the applicant's GPR on last 60 undergraduate hours] > 2.49 and [the applicant's GRE score] < 900 Then [the recommendation] = "deny normal admission" and [the action] = "based on established policy" RULE [Deny because of GRE] If [the undergraduate GPR should be considered] = true and [the applicant's GPR on last 60 undergraduate hours] > 2.49 and [the applicant] = "not the recipient of special honors" and [the applicant's GRE score] < 900 Then [the recommendation] = "deny normal admission" and [the action] = "based on established policy" REM Provisional acceptance RULE [Provisional acceptance: low GRE, verbal GRE] If [the undergraduate GPR should be considered] = true and [the applicant's GPR on last 60 undergraduate hours] > 2.49 and [the applicant] = "not the recipient of special honors" and [the applicant's GRE score] > 899 and [the applicant's GRE score] < 1100 and [the applicant's GRE verbal score] < 400 Then [the recommendation] = "admit provisionally - recommend English remediation" and [the action] = "based on established policy" RULE [Provisional acceptance: low GPR, verbal GRE] If [the undergraduate GPR should be considered] = true and [the applicant's GPR on last 60 undergraduate hours] > 2.49 and [the applicant's GPR on last 60 undergraduate hours] < 3.0 and [the applicant's GRE score] > 899 and [the applicant's GRE verbal score] < 400 Then [the recommendation] = "admit provisionally - recommend English remediation" and [the action] = "based on established policy" RULE [Provisional acceptance: low GRE] If [the undergraduate GPR should be considered] = true and [the applicant's GPR on last 60 undergraduate hours] > 2.99 and [the applicant] = "not the recipient of special honors" and [the applicant's GRE score] > 899 and [the applicant's GRE score] < 1100 and [the applicant's GRE verbal score] > 399 Then [the recommendation] = "admit provisionally" and [the action] = "based on established policy" RULE [Provisional acceptance: low GPR] If [the undergraduate GPR should be considered] = true and [the applicant's GPR on last 60 undergraduate hours] > 2.49 and [the applicant's GPR on last 60 undergraduate hours] < 3.0 and [the applicant's GRE score] > 899 Then [the recommendation] = "admit provisionally" and [the action] = "based on established policy" REM Accept RULE [Acceptance: honors] If [the undergraduate GPR should be considered] = true and [the applicant's GPR on last 60 undergraduate hours] > 2.99 and [the applicant] : "an honor graduate" "a class valedictorian" "a class salutatorian" Then [the recommendation] = "admit with full status" and [the action] = "based on special decision" RULE [Acceptance at departmental discretion] If [the undergraduate GPR should be considered] = true and [the applicant's GPR on last 60 undergraduate hours] > 2.99 and [the applicant] = "not the recipient of special honors" and [the applicant's GRE score] > 1099 and [the applicant's GRE verbal score] < 400 Then [the recommendation] = "admission decision is at department's discretion" and [the action] = "based on established policy" RULE [Acceptance] If [the undergraduate GPR should be considered] = true and [the applicant's GPR on last 60 undergraduate hours] > 2.99 and [the applicant] = "not the recipient of special honors" and [the applicant's GRE score] > 1099 and [the applicant's GRE verbal score] > 399 Then [the recommendation] = "admit with full status" and [the action] = "based on established policy" REM Prompts PROMPT [the applicant's UG status] MultChoice "This applicant is:" "receiving a bachelor's degree from a US institution" "not receiving a bachelor's degree from a US institution" PROMPT [the applicant's TOEFL score] Numeric "What is the applicant's TOEFL (Test of English as a Foreign Language) score?" "0" "800" PROMPT [the applicant's GPR on prior graduate work] Numeric "What is the applicant's GPR (Grade point ratio) for prior graduate work?" "0" "4.0" PROMPT [the applicant's final undergraduate transcript] MultChoice "The applicant's final undergraduate transcript is:" "available" "not available" PROMPT [the applicant's GPR on last 60 undergraduate hours] Numeric "What is the applicant's GPR (Grade point ratio) for the last 60 UG hours?" "0" "4.0" PROMPT [the applicant's graduate status] MultChoice "This applicant's graduate status is:" "prior graduate work completed" "no prior graduate work completed" PROMPT [the applicant's GPR on prior graduate work] Numeric "What is the applicant's GPR (Grade point ratio) on prior graduate work?" "0" "4.0" PROMPT [the applicant] AllChoice "This applicant is (check all that apply):" "an honor student" "an honor graduate" "a class valedictorian" "a class salutatorian" PROMPT [the applicant's GRE score] Numeric "What is the applicant's total GRE (Graduate Record Exam) score?" "0" "1600" PROMPT [the applicant's GRE verbal score] Numeric "What is the applicant's GRE verbal score?" GOAL [the recommendation] GOAL [the action] MAXVALS [the applicant] 4 DEFAULT [the applicant] = "not the recipient of special honors"</PRE> </TD></TR></TABLE> <P><BR><A NAME="DEBUG"></A> <FONT FACE="Arial,Helvetica" SIZE=3><B>Recommendations for implementing and debugging a knowledge base</B></FONT> <P>When the "Start the consultation" button is clicked on the e2gRuleEngine applet's opening screen, the knowledge base is loaded and syntax checked. If an error is encountered, loading immediately stops and an error number is displayed. If the test is run in the "debug" mode (the <B>DEBUG</B> applet parameter has the value "true") the line containing the error is displayed in the "Knowledge Base Developer's Output" window. As a result, it is most efficient to adhere to the following advice when building a knowledge base: <UL> <LI>Enter a few RULEs and PROMPTs at a time so that the knowledge base is unlikely to contain multiple syntax errors. <LI>Run with the <B>DEBUG</B> parameter in the &lt;APPLET> tags set to "true" to simplify finding the knowledge base line containing an error. </UL> <P>Some additional debugging suggestions that you might find helpful: <UL> <LI>Most e2gRuleEngine syntax errors are caused by spelling or punctuation problems or by omitting or mismatching the delimiters [ ] " '. Attribute names and text strings that are intended to be identical may differ only in case: spacing and punctuation characters must match exactly. <LI>Attribute names must be defined in a RULE before they are used in other statements including PROMPT, GOAL, MAXVALS and DEFAULT. Always put these statements after all of the RULEs. You cannot enter a PROMPT for an attribute in your knowledge base in advance of entering at least one RULE that uses the attribute. <LI>You may want to print out the <A HREF="e2gref.htm">Reference</A> documentation or at least the <A HREF="e2gref.htm#ERRCODES">Error Codes</A> for convenient use while constructing your knowledge base. <LI>Experimenting with your knowledge base with a variety of inputs after adding a each few RULEs and PROMPTs is advisable to help identify errors in your logical analysis. If you don't get the results you expect, figure out why this is happening before adding more complexity. <LI>Make sure you use some test cases that exercise the boundaries of the rules. For example, in the graduate admissions knowledge base, running tests with GPRs of exactly 3.0, 2.99, 3.29, 3.3 helps identify minor errors made when writing inequality comparisons. <LI>Consider developing your knowledge base using the e2gRuleWriter decision table software described in <a href="/e2g3g/e2g3gdoc/e2gRuleWriterRef.htm">Module 10</a>. This program provides a number of mechanisms for avoiding or identifying errors in knowledge base construction. </UL> <P>Finally, here is a summary of some commonly encountered knowledge base problems. <P> <TABLE BORDER=1> <TR><TH COLSPAN=3 BGCOLOR="#ffee33"><FONT FACE="Arial,Helvetica" SIZE='3'>Knowledge Base Debugging Suggestions</TH> <TR><TH><FONT FACE="Arial,Helvetica" SIZE=2>Symptom</TH> <TH><FONT FACE="Arial,Helvetica" SIZE=2>Probable Cause</TH> <TH><FONT FACE="Arial,Helvetica" SIZE=2>Finding the problem</TH></TR> <TR><TD><FONT FACE="Arial,Helvetica" SIZE=2>When the Web page containing &lt;APPLET...> tags loads, a grey panel persists where the e2gRuleEngine opening screen should appear after the applet is downloaded.</TD> <TD><FONT FACE="Arial,Helvetica" SIZE=2>The applet cannot be found, or crashes after loading.</TD> <TD><FONT FACE="Arial,Helvetica" SIZE=2>Look for an error message on browser's status line. Check the Java console for error messages. Make sure the e2gRuleEngine.jar file is installed in the proper location on the Web server and that the CODE and ARCHIVE attributes in the &lt;APPLET> tag are specified correctly.</TD></TR> <TR><TD><FONT FACE="Arial,Helvetica" SIZE=2>Attribute values for which PROMPTs exist are never requested</TD> <TD><FONT FACE="Arial,Helvetica" SIZE=2>Different spellings, spacing or punctuation of an attribute name.</TD> <TD><FONT FACE="Arial,Helvetica" SIZE=2>Run in Debug mode (set the DEBUG &lt;APPLET> parameter to "TRUE"), click "Start the consultation" then click "Analyze KB" in the KNOWLEDGE BASE DEVELOPER'S window. Review the ATTRIBUTE USAGE section of the resulting KNOWLEDGE BASE ANALYSIS for attribute naming problems.</TD> <TR><TD><FONT FACE="Arial,Helvetica" SIZE=2>Rules don't fire that should fire as a result of user input.</TD> <TD><FONT FACE="Arial,Helvetica" SIZE=2>Different spellings, spacing or punctuation of an attribute value.</TD> <TD><FONT FACE="Arial,Helvetica" SIZE=2>Run in Debug mode (set the DEBUG &lt;APPLET> parameter to "TRUE"), click "Start the consultation" then click "Analyze KB" in the KNOWLEDGE BASE DEVELOPER'S window. Review the VALUE USAGE section of the resulting KNOWLEDGE BASE ANALYSIS for value definition problems.</TD> <TR><TD><FONT FACE="Arial,Helvetica" SIZE=2>In the final explanation of conclusions, some rules don't seem to have used all of the known facts in their explanation even though these attributes are in the premise.</TD> <TD><FONT FACE="Arial,Helvetica" SIZE=2>Could be normal when premise clauses connected by OR</TD> <TD><FONT FACE="Arial,Helvetica" SIZE=2>Once a rule has fired, it will not be examined again by the inference engine. When premise clauses are OR'd the true premise clause with the highest CF fires the rule.</TD> <TR><TD><FONT FACE="Arial,Helvetica" SIZE=2>The knowledge base will not load (Error 800) from a Web server, but you know it has been uploaded to the server.</TD> <TD><FONT FACE="Arial,Helvetica" SIZE=2>Incorrect URL or knowledge base file extension problem.</TD> <TD><FONT FACE="Arial,Helvetica" SIZE=2>If the e2gRuleEngine.jar file and the knowledge base are not in the same subdirectory, the KBURL parameter in the applet tags must correctly define the path to the knowledge base. <br>Some Web servers will not download files with an unrecognized file extension like <b>.kb</b>. If you cannot get the server administrator to allow the .kb extension with a MIME type of text/plain in the subdirectory that holds your knowledge bases, you may have to use <b>.txt</b> as the extension on your knowledge base files and in the KBURL parameter.</TD> </TABLE> </FONT> <P><BR><A NAME="EVAL"></A> <FONT FACE="Arial,Helvetica" SIZE=3><B>Performing numerical calculations in rule consequents</B></FONT> <P><FONT FACE="Arial,Helvetica" SIZE=2> Beginning with e2gRuleEngine version 6.0, it is possible to perform mathematical calculations in a rule consequent. Here is a knowledge base that demonstrates the capability by calculating an employee's pay. The objective is to calculate the pay based on a selected hourly rate for the first 40 hours and time-and-a-half for hours worked over 40: <center> <table border='1'> <tr><th bgcolor="#ffee33"><FONT FACE="Arial,Helvetica" SIZE='3'>Numerical Calculation Demonstration Knowledge Base</font></th></tr> <tr><td><pre> REM demonstrate e2gRuleEngine calculation capability RULE [calculate overtime hours] If [the number of hours worked] > 40 Then [the overtime hours] = {[the number of hours worked] - 40} RULE [calculate pay] If [the hourly rate] ? and [the number of hours worked] ? and [the overtime hours] ? Then [the gross pay] = {[the hourly rate]*([the number of hours worked]-[the overtime hours])+1.5*[the hourly rate]*[the overtime hours]} @95 REM MultChoice prompt to demonstrate coercing string values into numeric PROMPT [the hourly rate] MultChoice CF "The hourly rate is:" "5.00" "10.00" "15.00" PROMPT [the number of hours worked] Numeric CF "The number of hours worked is:" "0.0" "80.0" DEFAULT [the gross pay] = 0 DEFAULT [the overtime hours] = 0 GOAL [the gross pay] MINCF 70 </pre></td> </table> </center> <p> To run this knowledge base, <a href="paycalc.htm" target="_new">CLICK HERE</a>. <p> The conditions for incorporating numeric calculations in an e2gRuleEngine rule include: <ul> <li>Numeric expressions are permitted only in rule consequents (the "then" part of the rule). <li>A numeric expression must be enclosed in curly braces: <b>{ }</b> and may incorporate delimited attribute names, numeric literals, mathematical operators and parentheses. <li>Each attribute used in the expression must be used in the rule premise (the "if" part of the rule). This is to keep the rule from firing before a value is determined for each attribute to be used in a calculation in the rule's consequent. The premise clauses must be joined by the "and" logical operator to insure that all attributes have a value before the rule fires. <li>If e2gRuleEngine attempts to use an attribute in a calculation that does not have a value known with a CF >= MINCF, operation of the program will terminate with an error message. <li>A new operator "has been determined" denoted by the question mark "<b>?</b>" is provided to facilitate checking for value assignment before numeric calculations are performed. The <b>calculate pay</b> rule in the example knowledge base illustrates the use of this operator. The <b>calculate overtime hours</b> rule does not require use of the "<b>?</b>" operator since the attribute used in the consequent's numeric calculation is already used in the premise. <li>Attributes used in numeric calculations must have numeric values. To permit the use of PROMPTs that return string values, e2gRuleEngine will attempt to coerce string values into numbers if they are used in a calculation. The prompt for <b>the hourly rate</b> illustrates this concept. A string that can be converted includes numbers and an optional single decimal point. It may begin with a + or - sign. It <b>may not</b> include dollar signs, commas or other special characters. If e2gRuleEngine tries to convert a string value that does not represent a legitimate number into a number, the program will terminate with an error message. <li>The Certainty Factor (CF) associated with attributes when they are used in computations is 100%. The result of the evaluation of a numeric expression may be assigned a CF by including the @xxx assignment <b>after</b> the closing expression delimiter: <b>}</b>. The <b>calculate pay</b> rule in the example knowledge base illustrates this format. <li>Mathematical operators are evaluated according to the precedence shown in the following table. Highest precedence operations are performed first. If two operators have the same precedence, they are evaluated left to right. Parentheses and nested parentheses may be used to alter the order of the evaluation: <p> <center> <table border='1' cellpadding='2'> <tr><th colspan='3' bgcolor='#ffee33'><FONT SIZE='3'>Mathematical Operator Precedence</font></th></tr> <tr bgcolor="lightgray"><th><font size='2'>Operator</font></th><th><font size='2'>Precedence</font></th><th><font size='2'>Operation</font></th></tr> <tr><th>^</th><td align='center'><font size='2'>3</font></td><td><font size='2'>Exponentiation</font></td></tr> <tr><th>*</th><td align='center'><font size='2'>2</font></td><td><font size='2'>Multiplication</font></td></tr> <tr><th>/</th><td align='center'><font size='2'>2</font></td><td><font size='2'>Division</font></td></tr> <tr><th>+</th><td align='center'><font size='2'>1</font></td><td><font size='2'>Addition</font></td></tr> <tr><th>-</th><td align='center'><font size='2'>1</font></td><td><font size='2'>Subtraction</font></td></tr> </table> </center> <p> Some examples to illustrate calculation precedence and the impact of parentheses:<p> <b>5 + 2 * 10 = 25</b><br> <b>(5 + 2) * 10 = 70</b><br> <b>(5+2) * 10 ^ 2 = 700</b><br> <b>((5+2) * 10) ^ 2 = 4900</b> <p> <li> Although it is not possible to perform numerical calculations in a rule's premise, it is often possible to use two rules to obtain the desired effect. Suppose, for example, the following rule is needed in a knowledge base: <font size='3'><pre> RULE [Decide whether to buy] If (A + B) < 5 Then [result] = "buy the item" </pre></font> e2gRuleEngine cannot support this rule premise calculation. However, the following two rules will provide equivalent logic: <font size='3'><pre> RULE [Calculate sum of A and B] If [A] ? and [B] ? Then [AplusB] = {[A] + [B]} RULE [Decide whether to buy] If [AplusB] < 5 Then [result] = "buy the item" </pre></font> The first rule will only fire when values are available for both A and B and will calculate their sum in the new variable AplusB. Then, the second rule will be able to fire. <p> <li>Using e2gRuleEngine with the DEBUG parameter set to "true" is strongly recommended while developing a knowledge base that incorporates numeric calculations. When the program fails during a calculation, an output to the debug window will indicate the location in the expression at which the error was detected. <p> <li>Beginning with v8.0, e2gRuleEngine/e2gAndroid adds the capability to count the number of values of a multivalued attribute determined by user input and rule consequents. As an example, suppose a knowledge base incorporates the following prompt: <font size='3'><pre> PROMPT [important features] AllChoice "Select all of the features you consider important" "feature 1" "feature 2" "feature 3" "feature 4" </pre></font> <p> To count the number of responses given to this prompt, the following rule and DEFAULT statement could be incorporated into the knowledge base: <p> <font size='3'><pre> RULE [number of important features] If [important features] ? Then [number of features] = {#[important features]} DEFAULT [important features] = "no features selected" </pre></font> <p> The <b>#</b> sign immediately preceding the left delimiter of an attribute name represents the "number of values of" function. This function causes a count of the number of values of the named attribute to replace the attribute name in the numeric expression. To be counted, a value of the attribute has to have a certainty factor greater than or equal to the minCF value, and the value must not have been set by default. If the user does not select any of the features in the example above, the rule would not ordinarily fire. The DEFAULT statement lets the rule fire when no values are entered. In this case the number of features will be calculated as 0, since all of the values have been set by default. The [number of features] numeric attribute could be named as a GOAL and/or used in other rules. When a rule is formatted for output, the <b>#</b> function will be displayed as <b>COUNT</b>. The rule consequent: <b>Then [the result] = {#[important features]}</b> would therefore be displayed as: <b>Then the result is COUNT[important features]</b>. <p> <li>Beginning with v8.0, e2gRuleEngine/e2gAndroid provides a formatting capability for numeric attribute output. <p>Format statements in the knowledge base provide this capability: <p><font size='3'><pre> FORMAT [numeric attribute name] = "format specification" </pre></font> <p>For example, the following format statements are included in the BankLoan.kb knowledge base: <p><font size=3><pre> FORMAT [the applicant's current actual account balance] = "$%8.2f" FORMAT [the amount of the requested loan] = "$%8.2f" FORMAT [the amount over loan limit] = "$%8.2f" </pre></font> <p>The format specification has the following structure: %[width].[decimal places][type] <p>Numeric values are maintained in double precision floating point format, so the relevant specification types for e2gRuleEngine/e2gAndroid use are: <ul> <li><b>f</b> displays a floating point number in fixed format (1234.56, for example) <li><b>e</b> or <b>E</b> displays a floating point number in exponential format (1.5e+3, for example) <li><b>g</b> or <b>G</b> displays a small floating point number in fixed format and a large number in exponential format </ul> <p>Text included before or after the specification is included in the output. <b>$%10.2f</b> displays a dollar sign followed by a numeric value in a field ten characters wide rounded to two decimal places. <p>If an error is detected while formatting a numeric value, the value is output unformatted. If this occurs when running e2gRuleEngine in DEBUG mode, an error message displaying the erroneous format specification is output to the debug window as part of the trace output. </ul> <P><BR><A NAME="HYPERLINK"></A> <FONT FACE="Arial,Helvetica" SIZE=3><B>Adding hyperlinks to final results and PROMPTS</B></FONT> <P><FONT FACE="Arial,Helvetica" SIZE=2> Beginning with e2gRuleEngine v7.0 and e2gDroidLite v1.8.1, it is possible to add hyperlinks to the <i>final results</i> of an expert system consultation. This permits the user to link to Web pages that could include more detailed recommendations, references or advertising. The hyperlinks may be used in two ways. The first and simplest loads the Web content into the e2gRuleEngine/e2gDroidLite, displacing the final results screen while incorporating a button to return to the final results display. The second technique (available only with e2gRuleEngine) uses the JavaScript interface (described in detail in Module 9) to load Web pages into a new window or frame provided by the browser that is running the e2gRuleEngine applet. In both cases the hyperlink is defined in the knowledge base and specifies the attribute and attribute value for which a link is desired and the Web address (URL) representing the link. <p> Beginning with e2gRuleEngine v8.0 and e2gDroidLite v1.8.1, hyperlinks defined by INFOLINK statements may be used to access information about a PROMPT. An INFOLINK defined for the attribute referenced by a PROMPT causes an InfoLink button (denoted by a <b>?</b>) to be added to the PROMPT screen. Clicking this button replaces the PROMPT with the hyperlinked Web page and includes a button to return to the PROMPT. <p> The new knowledge base commands and parameter that support hyperlinking include: <p> <font size='3'><pre> HYPERLINK [attribute name] = "attribute value" "URL to link to when this attribute value of this attribute name is clicked on final results display" JSHYPERLINK [attribute name] = "attribute value" "URL and optional additional parameters to pass to JavaScript window.open() function" TRANSLATE TR_HYPERLINK = "optional: modifies text to display at end of any hyperlinked results - default is: <i>Click underlined text to link to more information</i>" INFOLINK [attribute name] "URL to link to when the INFOLINK (?) button is clicked on the PROMPT screen for this attribute"</pre></font> <p> The INFOLINK, HYPERLINK and JSHYPERLINK commands may all be used in the same knowledge base, and each may be used multiple times to hyperlink different values of different goal attributes. <p> A new HYPERENCODING parameter (applet tag) will <b>generally not be required</b>, but is provided to allow linking to HTML files with the HYPERLINK command that are stored with unusual character encoding. <font size='3'><pre>&lt;param name="HYPERENCODING" value="character encoding"></pre></font> <center> <table border='1' cellpadding='5' width='90%'> <tr><th bgcolor='#ffee33'><FONT FACE="Arial,Helvetica" SIZE='3'>Special considerations when using the HYPERLINK, JSHYPERLINK and INFOLINK commands</font></th></tr> <tr><td><font size='2' face="Arial, Helvetica"> <b>Character encoding with JSHYPERLINK:</b> HTML files that define Web pages may be stored using a variety of different character encodings. Browsers generally do a good job of detecting the encoding used to store the files that they are loading, and are therefore able to render the output as intended. Browsers also provide menu options to change the display encoding (on the "View" menu in FireFox, the "Page" menu in MS Explorer and the "Control Page" menu in Chrome, for example). The output produced by a JSHYPERLINK is rendered by the browser running the applet, so the full detection ability of the browser is called into play for this output. Some problems have nevertheless been encountered when the JSHYPERLINK capability is used and the HTML file hosting the applet and the linked HTML files are stored using different character encodings. The problem symptom is HTML output garbled because it has been loaded with the wrong character encoding. Changing the display encoding from the browser menu before running the application may correct the problem. Testing your expert system with multiple browsers is recommended, particularly if you are using the JSHYPERLINK capability. You will find it helpful to include an explicit content-type meta tag in the &lt;head>...&lt;/head> section at the beginning of the HTML file hosting the e2gRuleEngine applet and the linked files -- most Web pages include this meta tag. For example: <font size='3'><center><pre>&lt;META http-equiv="Content-Type" content="text/html; charset=UTF-16" /></pre></center></font>or: <font size='3'><center><pre>&lt;META http-equiv="Content-Type" content="text/html; charset=UTF-8" /></pre></center></font> <p> <b>Character encoding with HYPERLINK and INFOLINK:</b> The HTML output that the HYPERLINK and INFOLINK commands link to is read by e2gRuleEngine, not the browser running the applet. It is therefore up to e2gRuleEngine to determine the character encoding. In version 7.00 of the software, this is accomplished by looking for a BOM (byte order marker) at the beginning of the linked HTML file. If bytes matching the BOM for UTF-8 encoding are found the file is loaded with this encoding. If bytes matching the BOM for Unicode big endian or Unicode little endian character encoding are found, the file is loaded using UTF-16 encoding. Otherwise, the file is loaded with default encoding. This technique should work for most files that could reasonably be used to generate Web pages since the UTF-8 and Unicode BOM character combinations would be unlikely to appear in these files by accident. If the file must be read using some other character encoding, add the HYPERENCODING parameter specifying the desired encoding to the applet tags. The three HTML files used as links in the examples that follow (hyperdemo1.html, hyperdemo2.html and hyperdemo3.html) were generated with Microsoft's Notepad editor and stored with three of the output character encodings supported by Notepad: UTF-8, UTF-16 little endian and UTF-16 big endian respectively. These files work properly with the examples and should be representative of the character encodings likely to be encountered with Web pages. These files also include the "content-type" meta tag described in the previous paragraph. Character encoding problems will be of most concern to users working with non-Roman character sets such as Chinese or Cyrillic that are represented with two bytes per character in HTML files. <p> <b>HYPERLINK and INFOLINK HTML limitations:</b> The rendering of HTML outlet in the applet (using HYPERLINK/INFOLINK) supports only a subset of mainstream browser capabilities, and this should be kept in mind when deciding whether to use HYPERLINK or JSHYPERLINK to support hyperlinks. If Web pages you link to are displayed properly in a browser, but not in the applet, it is likely that they incorporate HTML that is not supported (or supported in a different way) by the software at this time. HTML support in the applet does not always ignore HTML errors the way browsers do, and may generate a message that the file cannot be loaded when an error is encountered or may simply produce a blank page. As an example, e2gRuleEngine/e2gDroid cannot process &lt;SCRIPT> tags. <p> Because of Java applet security requirements (the so called Java "sandbox") URLs provided in HYPERLINK/INFOLINK tags must refer to pages located on the server from which the e2gRuleEngine applet was loaded. Java applets (unlike Java applications) cannot read files from Web servers other than the one from which the applet was loaded. This limitation does not apply to JSHYPERLINKs or to HYPERLINKS or INFOLINKs accessed by e2gDroid. <p> <b>Popup blockers and JSHYPERLINK:</b> The mechanism used by the JSHYPERLINK command to link to Web pages is similar to the technique used by commercial Web sites to produce "popup" windows displaying advertising. Popup blockers provided as a browser capability or add-on software will prevent JSHYPERLINKs from functioning unless the blocker is turned off. </font></td></tr> </table> </center> <p> Three examples follow that illustrate various ways of using and combining the HYPERLINK and JSHYPERLINK commands. Running each example, then examining the supporting HTML files and knowledge bases is strongly recommended. A provision for downloading the files defining the examples is provided at the end of the examples. <ul> <li>Example 1: Hyperlinking to Web pages displayed in the applet: <ul> <p> <li><A HREF=JavaScript:popup('autohyper.html',500,350)>Run hyperlink example with all links displayed in the applet</A> <p> <li>This example employs the following additions to the auto diagnosis knowledge base: <font size='3'><pre> HYPERLINK [the recommended action] = "recharge or replace the battery" "hyperdemo1.html" HYPERLINK [the recommended action] = "refuel the car" "hyperdemo2.html" HYPERLINK [the recommended action] = "wait 10 minutes, then restart flooded car" "hyperdemo3.html"</pre></font> In the example, the linked files (hyperdemo1.html, hyperdemo2.html and hyperdemo3.html) are located in the same subdirectory as the applet. If they were not, a more complete URL would be required in the HYPERLINK command. In fact, a complete URL (http://...) could be included, allowing Web content to be loaded from a different Web server. </ul> <p> <li>Example 2: Hyperlinking to Web pages displayed in a frame in the browser running the applet: <ul> <p> <li><A HREF=JavaScript:popup('autohyperJS.html',500,350)>Run hyperlink example with some links displayed in a new window</A> <p> <li>The first two hyperlinks will be displayed in a new browser window, and the third will be displayed in the applet. Note that the width and height of the new browser window defined by JSHYPERLINKs may be specified. Pay particular attention to the format of the JSHYPERLINK parameter that defines the hyperlink. This value is delimited (enclosed in double quotes) but the (up to) three <b>semicolon-separated</b> parameters <i>must not</i> be delimited. The third parameter may include multiple <b>comma-separated</b> parameters that will be used in opening a new browser window. Possible parameters relevant to expert system applications include: <p> <ul> <li>height=nnn the height of the new window in pixels <li>width=nnn the width of the new window in pixels <li>scrollbars=yes include scrollbars in the window if the Web page doesn't fit <li>menubar=yes include a menubar in the window </ul> <p> <li>This example employs the following additions to the auto diagnosis knowledge base: <font size='3'><pre> JSHYPERLINK [the recommended action] = "recharge or replace the battery" "hyperdemo1.html;_new;width=500,height=350,scrollbars=yes" JSHYPERLINK [the recommended action] = "refuel the car" "hyperdemo2.html;_new;width=500,height=350,scrollbars=yes" HYPERLINK [the recommended action] = "wait 10 minutes, then restart flooded car" "hyperdemo3.html"</pre></font> <li>The following parameter must be added to the applet tags in the HTML page (autohyperJS.htm) that loads the application: <p> <font size='3'><pre>&lt;param name="JSFUNCTION" value="hyperlink"></pre></font> <p>Finally, the JavaScript function that processes the JSHYPERLINK must be added to the web page that includes the applet tags: <font size='3'><pre> &lt;script> function hyperlink() { if (arguments[0] == "9") { nparams = arguments.length; if (nparams > 3) window.open(arguments[1], arguments[2], arguments[3]); else if (nparams > 2) window.open(arguments[1], arguments[2]); else if (nparams > 1) window.open(arguments[1]); } } &lt;/script></pre></font> It is possible to combine this code with the button-sensing JavaScript examples described in Module 9. The button code is returned as argument[0]. If only hyperlinking is to be supported, you may include the JSFUNCTION parameter and hyperlink JavaScript code in your application just as they are shown in the example: no custom programming is required. <p> </ul> <li>Example 3: Hyperlinking to Web pages displayed in a frame in the browser running the applet: <p> <ul> <p><li><A HREF=JavaScript:popup('autoframeJS2.html',800,350)>Run hyperlink example with some links displayed in frame</A> <p> <li>This example employs the following additions to the auto diagnosis knowledge base: <font size='3'><pre> JSHYPERLINK [the recommended action] = "recharge or replace the battery" "hyperdemo1.html;_infowin" JSHYPERLINK [the recommended action] = "refuel the car" "hyperdemo2.html;_infowin" HYPERLINK [the recommended action] = "wait 10 minutes, then restart flooded car" "hyperdemo3.html"</pre></font> <li>The first two hyperlinks will be displayed in the frame named _infowin, and the third will be displayed in the applet. The frame is defined by the HTML page used to start the application -- in this case <font face="mono"><b>autoframeJS2.html</b></font> listed below: <font size='3'><pre> &lt;html> &lt;head>&lt;title>Framed hyperlink demonstration&lt;/title>&lt;/head> &lt;frameset cols="450,*" frameborder=1 framespacing=1 border=1> &lt;frame name="_applet" src="autohyperJS2.html" marginheight=0 marginwidth=0> &lt;frame name="_infowin" marginheight=5 marginwidth=5> &lt;/frameset> &lt;/html></pre></font> This HTML defines two side-by-side frames, with the first frame 450 pixels wide and the second frame using the remaining screen width. The right frame is named <font face="mono"><b>_infowin</b></font> and is the frame referred to by the JSHYPERLINK commands. <p> <li>The JSFUNCTION applet parameter and hyperlink JavaScript function described with example 2 must be included in the HTML page hosting the applet. <p> </ul> <li>INFOLINK example: <p>The following INFOLINKs are incorporated in the BankLoan.kb knowledge base described and accessed from the <a href="#ANDROID">Android capability -- Sample Knowledge Bases</a> section of this document: <p> <font size='3'><pre> INFOLINK [the amount of the requested loan] "http://expertise2go.com/Android/loanref.htm#LoanAmount" INFOLINK [the applicant's current actual account balance] "http://expertise2go.com/Android/loanref.htm#AccountBalance" INFOLINK [the applicant's credit rating] "http://expertise2go.com/Android/loanref.htm#CreditRating" INFOLINK [the applicant's banking history] "http://expertise2go.com/Android/loanref.htm#BankingHistory" INFOLINK [the applicant's current balance category] "http://expertise2go.com/Android/loanref.htm#AccountBalance"</pre></font> In this example a single Web page provides a reference or "help" document for the expert system application with specific paragraphs accessed via the anchors. <li>Additional error, debug and formatting output supporting the hyperlink capability: <p> <ul> <li>Error code 310 has been added to indicate too many hyperlinks have been included in the knowledge base. The limit is 100 -- unlikely to be exceeded. <p> <li>An output is added to the trace when running in debug mode whenever a hyperlink is added to the expert system's final results page. The format is: <font size='3'><pre>Added hyperlink for: <i>attribute name</i> = <i>attribute-value</i> <i>hyperlink</i></p></pre></font> <li>The <font face='mono'>TRANSLATE TR_HYPERLINK</font> command may be used to change the message that appears after final results output that includes hyperlinks. The default value is: <p><center><b>Click underlined text to link to more information</b></center><p> If no message is desired, translate TR_HYPERLINK to a blank value: <font face='monospaced'>TRANSLATE TR_HYPERLINK = " "</font>. </ul> <p> <li>Example download: <b>right click</b> file names to download the example files. If you <b>left click</b> autohyper.html, autohyperJS.html or autoframeJS2.html you will start Example 1, Example 2 or Example 3 in the full browser window. <p> <center> <table border cellspacing="1" cellpadding="2"> <tr bgcolor="yellow"><th><font face="Arial,Helvetica" size=2>File</font></th><th><font face="Arial,Helvetica" size=2>Description</font></th></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="e2gRuleEngine.jar">e2gRuleEngine.jar</a></font></td><td><font face="Arial,Helvetica" size=2>e2gRuleEngine v8.0 software: keep the .jar, <b>do not extract!</b></font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="hyperdemo1.html">hyperdemo1.html</a></font></td><td><font face="Arial,Helvetica" size=2>linked demo file 1: saved as US-ASCII</font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="hyperdemo2.html">hyperdemo2.html</a></font></td><td><font face="Arial,Helvetica" size=2>linked demo file 2: saved as UTF-16 little endian</font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="hyperdemo3.html">hyperdemo3.html</a></font></td><td><font face="Arial,Helvetica" size=2>linked demo file 3: saved as UTF-16 big endian</font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="sickcar.gif">sickcar.gif</a></font></td><td><font face="Arial,Helvetica" size=2>image used in hyperdemo1.html - hyperdemo3.html</font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="autohyper.html">autohyper.html</a></font></td><td><font face="Arial,Helvetica" size=2>Web page initiating Example 1: applet tags</font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="autohyper.kb">autohyper.kb</a></font></td><td><font face="Arial,Helvetica" size=2>Knowledge base for Example 1</font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="autohyperJS.html">autohyperJS.html</a></font></td><td><font face="Arial,Helvetica" size=2>Web page initiating Example 2: applet tags and JavaScript function</font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="autohyperJS.kb">autohyperJS.kb</a></font></td><td><font face="Arial,Helvetica" size=2>Knowledge base for Example 2</font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="autoframeJS2.html">autoframeJS2.html</a></font></td><td><font face="Arial,Helvetica" size=2>Web page initiating Example 3: creates frame</font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="autohyperJS2.html">autohyperJS2.html</a></font></td><td><font face="Arial,Helvetica" size=2>Web page defining Example 3: applet tags and JavaScript</font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="autohyperJS2.kb">autohyperJS2.kb</a></font></td><td><font face="Arial,Helvetica" size=2>Knowledge base for Example 3</font></td></tr> </table> </center> <p> All of these files (including e2gRuleEngine.jar) need to be in the same subdirectory to run unaltered. You will need to change the URL in the &lt;img> tag in hyperdemo1.html, hyperdemo2.html and hyperdemo3.html to match your Web server if you download the examples to your own server. </ul> <SCRIPT> function popup(theURL,wpix,hpix){ window.open(theURL,'new','width='+wpix+',height='+hpix+',resizable=0,status=0,toolbar=0,scrollbars=0'); } </SCRIPT> <P><BR><A NAME="VERSION8"></A> <FONT FACE="Arial,Helvetica" SIZE=3><B>v8.0 enhancements</B></FONT> <P><FONT FACE="Arial,Helvetica" SIZE=2> <b>Enhancements and fixes in v8.0:</b> Hyperlinks connect to appropriate sections of the e2g Reference document. <OL> <LI><b><a href="e2gref.htm#PARAMETERS">Subset of applet parameters may be included in knowledge base:</a></b> The Android version of the shell does not have access to parameter information typically specified within the applet tags used to incorporate the e2gRuleEngine applet in its hosting Web page. A relevant subset of these parameters may now be included in the knowledge base to allow e2gRuleEngine and e2gDroid to run the same knowledge bases. <LI><b><a href="e2gref.htm#PARAMETERS">DISCLAIMER applet parameter:</a></b> When included as a parameter, either within the applet tags or as a knowledge base parameter, the DISCLAIMER text is presented to the user in a dialog box before any inputs are allowed. Accept and Exit options are provided, and the user must accept the disclaimer to continue interacting with the expert system. The DISCLAIMER text may be formatted with HTML tags. <LI><b><a href="e2gref.htm#KBASEFMT">NOSHOW knowledge base command:</a></b> When included in the knowledge base, NOSHOW prevents the output, in the final results, of the "could not be determined" message for GOAL attributes with values that could not be resolved. <LI><b><a href="e2gref.htm#KBASEFMT">NOSHOW [attribute name] knowledge base command:</a></b> When included in the knowledge base, NOSHOW [attribute name] prevents the output, in the final results, of the named GOAL attribute whether or not its value has been resolved. Multiple NOSHOW [attribute name] commands may be included in the knowledge base. This command is used to prevent output for GOALs that are included as intermediate values to help control the flow of the expert system consultation. <LI><b><a href="e2gref.htm#KBASEFMT">ELIM [attribute name] modifier to knowledge base Choice, AllChoice, MultChoice and ForcedChoice PROMPT commands:</a></b> This extension of the various multiple choice prompts allows elimination of choices from a prompt that have been selected in an earlier prompt. It is useful when prompts might ask for first and second choices from a list so that the first choice(s) won't be shown with the prompt for the second choice(s). <LI><b>GoBack capability:</b> Allows the consultation to be restarted at an earlier prompt. When the GoBack button that appears on all prompt screens after the first is clicked, the user is presented with a list of prompt questions in the order they have been issued. Selecting a prompt from this list, then clicking the GoBack button restarts the consultation at the selected prompt. Values already input after this prompt are deleted because they could lead to inconsistent final results. <LI><b><a href="e2gref.htm#RELOP">Added relational operators</a> (<=, >=, !=, <>, !:):</b> These new relational operators and alternate forms for the existing "not equal to" (!) relational operator are for use in rule premise (If) clauses. They represent "less than or equal to", "greater than or equal to", "not equal to", "not equal to" and "none of the values of". <LI><b><a href="e2gref.htm#MATHOP">Added "number of values of" function</a> (#):</b> If the <b>#</b> sign immediately precedes the opening delimiter of an attribute name used in a rule consequent numeric expression, a count of the number of values of the named attribute replaces the attribute name in the expression. For example, the expression <b>{#[important features]+5}</b> is interpreted as: "count the number of values determined for the [important features] attribute, and add 5 to this count." See <a href="#EVAL">Performing numerical calculations in rule consequents</a> for an example. <LI><b><a href="e2gref.htm#KBASEFMT">Added TEXT prompt type:</a></b> A TEXT prompt type has been added primarily to allow inclusion of identifying text information in the results output. The input to a TEXT prompt is an unrestricted string of alphanumeric characters. <LI><b><a href="e2gref.htm#KBASEFMT">INFOLINK help capability:</a></b> The INFOLINK command in a knowledge base associates a hyperlink with an attribute name for which a prompt is provided. When a prompt that has an INFOLINK is presented during a consultation, a "?" button is added to the prompt that, when clicked by the user, temporarily replaces the prompt with the hyperlinked Web page. A typical application would use anchors in a Web page to provide context-sensitive help. Like HYPERLINKs, INFOLINK URLs accessed by e2gRuleEngine must reside on the server from which the applet was loaded for security reasons. This limitation does not apply to e2gDroid. <LI><b><a href="e2gref.htm#KBASEFMT">FORMAT [numeric attribute name] = "format specifier" knowledge base command:</a></b> Allows a numeric attribute's value to be formatted whenever it is displayed. Standard Java format specifiers are allowed. For example, the specifier <b>$%8.2f</b> outputs a dollar sign followed by display of the numeric attribute's value in a field eight characters wide rounded to two decimal places. See <a href="#EVAL">Performing numerical calculations in rule consequents</a> for an example. <LI><b><a href="e2gref.htm#KBASEFMT">Optional use of equal sign in MAXVALS statement:</a></b> Allows an alternate format for specifying multiple values of an attribute. <LI><b><a href="e2gref.htm#TRANSLATE">Translation table additions:</a></b> Several additional labels resulting from v8.0 software additions and e2gDroid requirements are available for translation. <LI><b>Reverse sequence of reported final results:</b> When multiple GOAL statements appear in an e2gRuleEngine/e2gDroid knowledge base, the last listed goal is the one the expert system will first try to resolve. In versions of e2gRuleEngine before v8.0, final results were output in the order of the GOAL commands in the knowledge base. Beginning with v8.0 results are output from last GOAL to first GOAL for consistency. <LI><b>Suppress "Value 1 of" label for single valued goal attributes in results output:</b> Multivalued goal attribute values (MAXVALS > 1) will still be output with the full statement even if only one value has been resolved. <LI><b>Error caused by blank lines fixed:</b> A line in the knowledge base intended to be blank that contains spaces before the end-of-line characters could cause an error in loading the knowledge base. This has been corrected in v8.0. <LI><b>Error in explanation of goal attribute that changed value fixed:</b> When a goal attribute is resolved with a CF less than 100%, it is possible for a new value to be concluded with a higher CF later in the consultation. When this occurs, confusing explanations of both values have been output. Only the correct final value is explained beginning with v8.0. </OL> </FONT> <P><BR><A NAME="ANDROID"></A> <FONT FACE="Arial,Helvetica" SIZE=3><B>Android&#153; capability and examples</B></FONT> <p><font size='2'> <b>e2gDroid for Android devices:</b> Smartphones and Wi-Fi enabled tablet computers support the creation of expert systems that can be taken directly into a problem solving or decision making environment. Problem domains that could benefit from such truly mobile yet Internet-connected applications include hardware maintenance or other problem diagnosis, product advisors, job aids, technical tutors, regulation interpreters and adaptive checklists. <p> Beginning with version 8.00 of the e2gRuleEngine expert system shell, <b>e2gDroid</b>, a knowledge base compatible expert system shell that runs on Android devices, will be available in a "Lite" version for free download through the <a href="http://android.com/market">Android Market</a> installed on Android smartphones and the <a href="http://appslib.com">AppsLib</a> application marketplace for Android installed on (or available for) selected Android tablets. Additional options for downloading from the Android Market are available from app indexers such as: <a href="http://androidzoom.com">AndroidZoom</a>, <a href="http://droidmill.com">DroidMill</a> and <a href="http://appbrain.com">AppBrain</a>. Search for <b>e2gDroid</b> or <b>e2gDroid Lite</b> (two words) to find the app. <p /> At least version 1.6 ("Donut") of the Android operating system is required to run the application. e2gDroid works with the same knowledge bases used by e2gRuleEngine, providing identical capabilities with the exception of the applet's debugging/development tools and JavaScript interface. It is assumed that knowledge base developers will do their knowledge base construction and testing using the e2gRuleEngine applet with its integrated debugging and diagnostic support. <p> The e2gDroid software operates stand-alone on Android devices rather than running in a browser as does e2gRuleEngine. The shell allows knowledge bases to be downloaded through the internet and optionally stored in the Android device's internal or SD card memory (if an SD card capability is available). Knowledge bases are text files and could also be directly loaded onto SD cards with Android utility software. <p> If your primary interest is in developing expert system applications for Android, you must still become familiar with the e2gRuleEngine applet version of the software because you will need to do your development work in this environment. </font> <p />After installing the app from the Android Market or AppsLib on your Android device, click the Application Tab to navigate to the Application Screen. Click the e2gDroid icon <img src="/Android/images/applogo.png" align="middle"/> and you should see the following startup screen: <center><img src="/Android/images/startup.png" border="1" /></center> <p />Assuming an Internet connection is available, clicking <b>KB Load</b> while the "Help.html" file has been selected from the spinner starts the Android device's Web browser and displays the e2gDroid Online Documentation. To view this documentation on a PC, click the following link: <a href="/Android/Help.html" target="new">e2gDroid Online Documentation</a>. A look at this documentation on the larger screen of a PC before using e2gDroid for the first time is recommended. <p />After (optionally) loading the Online Documentation, press the <b>Home</b> key (the little house) on the Android device to return to the home screen, click the Application tab to navigate to the Application Screen, click the e2gDroid icon to load the app and select a knowledge base to load from the spinner displayed on the e2gDroid startup screen. <center><img src="/Android/images/kbselect.png" border="1" /></center> <p />Installing e2gDroid provides Web links to several demonstration knowledge bases in addition to the Online Documentation, any of which may be run with e2gRuleEngine in a Web browser and downloaded so they can be examined or enhanced for educational purposes. <center><img src="/Android/images/kbload.png" border="1" /></center> <p /> Clicking the <b>KB Load</b> button loads and error checks the knowledge base, and clicking the <b>Start</b> button begins the expert system consultation. <p />On many Android devices, a long press on the home key will display the icons associated with the most recent activities. This allows quick switching between the documentation displayed in the browser and the current e2gDroid expert system consultation. <p /><b>Sample Knowledge Bases.</b> The sample knowledge bases listed below have their Web addresses preloaded when e2gDroid is installed. Right click <b>KB File</b> names in the table to download the example knowledge bases for examination. To run the knowledge base with the e2gRuleEngine applet, click the <b>Demo:</b> link. <center> <table border cellspacing="1" cellpadding="2"> <tr bgcolor="yellow"><th><font face="Arial,Helvetica" size=2>KB File</font></th><th><font face="Arial,Helvetica" size=2>Description and link to run in e2gRuleEngine</font></th></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="/Android/AutoFix.kb">AutoFix.kb</a></font></td><td><font face="Arial,Helvetica" size=2><a href="JavaScript:popup('AutoFix.htm',470,370)">Demo: diagnosing why an automobile won't start. Includes TEXT prompt</a></font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="/Android/BankLoan.kb">BankLoan.kb</a></font></td><td><font face="Arial,Helvetica" size=2><a href="JavaScript:popup('BankLoan.htm',470,370)">Demo: determine loan category. Includes INFOLINKs & HYPERLINKs, numeric formatting</a></font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="/Android/WineAdvisor.kb">WineAdvisor.kb</a></font></td><td><font face="Arial,Helvetica" size=2><a href="JavaScript:popup('WineAdvisor.htm',520,420)">Demo: simple wine advisor. Includes INFOLINKs & HYPERLINKs </a></font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="/Android/GradAdmit.kb">GradAdmit.kb</a></font></td><td><font face="Arial,Helvetica" size=2><a href="JavaScript:popup('GradAdmit.htm',470,370)">Demo: graduate admissions recommendation</a></font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="/Android/AutoFixFr.kb">AutoFixFr.kb</a></font></td><td><font face="Arial,Helvetica" size=2><a href="JavaScript:popup('AutoFixFr.htm',470,370)">Demo: French translation of AutoFix.kb</a></font></td></tr> </table> </center> <p> Listed below are some additional knowledge bases that illustrate specific e2gRuleEngine/e2gDroid features. They may be examined and run with e2gRuleEngine using the methods described for the sample knowledge bases above. To run the demos with e2gDroid, load them with the Web address <b>http://expertise2go.com/Android/<i>KBname.kb</i></b> substituting one of the KB file names from the table for <i>KBname.kb</i>: <center> <table border cellspacing="1" cellpadding="2"> <tr bgcolor="yellow"><th><font face="Arial,Helvetica" size=2>KB File</font></th><th><font face="Arial,Helvetica" size=2>Description and link to run in e2gRuleEngine</font></th></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="/Android/CalcTest.kb">CalcTest.kb</a></font></td><td><font face="Arial,Helvetica" size=2><a href="JavaScript:popup('CalcTest.htm',470,370)">Demo: Overtime pay calculation. Includes numeric formatting</a></font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="/Android/TabletAdvisor.kb">TabletAdvisor.kb</a></font></td><td><font face="Arial,Helvetica" size=2><a href="JavaScript:popup('TabletAdvisor.htm',470,370)">Demo: Simplified Android tablet selector. Includes ELIM parameter in PROMPT and COUNT function</a></font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="/Android/GoalLoop.kb">GoalLoop.kb</a></font></td><td><font face="Arial,Helvetica" size=2><a href="JavaScript:popup('GoalLoop.htm',470,370)">Demo: Illustrates goal loop in knowledge base</a></font></td></tr> <tr><td><font face="Arial,Helvetica" size=2><a href="/Android/StatTech.kb">StatTech.kb</a></font></td><td><font face="Arial,Helvetica" size=2><a href="JavaScript:popup('StatTech.htm',470,370)">Demo: Data analysis technique selector. Includes INFOLINKS & HYPERLINKS</a></font></td></tr> </table </center> <SCRIPT> function popup(theURL,wpix,hpix){ window.open(theURL,'new','width='+wpix+',height='+hpix+',resizable=0,status=0,toolbar=0,scrollbars=0'); } </SCRIPT> <P><CENTER><FONT FACE="Arial,Helvetica" SIZE=2>[<A HREF="default.htm">Index</A>][<A HREF="e2gmod1.htm">Module 1</A>][<A HREF="e2gmod2.htm">Module 2</A>][<A HREF="/e2g3g/tutorials/esintro">Module 3</A>][<A HREF="e2gmod4.htm">Module 4</A>][<A HREF="/e2g3g/tutorials/inference">Module 5</A>][<A HREF="/e2g3g/tutorials/knoweng/">Module 6</A>][<A HREF="e2gmod8.htm">Module 8</A>][<A HREF="e2gmod9.htm">Module 9</A>][<A HREF="e2gRuleWriterRef.htm">Module 10</A>][<A HREF="e2gref.htm">Reference</A>]</CENTER> <P><HR><FONT FACE="Arial,Helvetica" SIZE=1>Copyright © 2001-2011 by <FONT COLOR=Blue>e</FONT><FONT COLOR=Red>Xpertise</FONT><FONT Color=Blue><I>2Go</I></FONT>.com. All rights reserved. <BR><A HREF="mailto:webmaster@expertise2go.com">webmaster@expertise2go.com</A> </FONT> </BODY> </HTML>