Jess in action: rule-based systems in Java 1930110898, 9781930110892

A practical handbook for anyone interested in programming rule-based systems and written by the creator of the popular J

288 55 4MB

English Pages 482 Year 2003

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
brief contents......Page 8
contents......Page 10
preface......Page 22
Introducing rule-based systems......Page 34
Rules to the rescue......Page 36
1.1 Math class melee......Page 37
1.1.1 Beyond logic puzzles......Page 41
1.2.1 Mail filtering......Page 42
1.2.2 Product configuration......Page 43
1.2.3 Implementing business rules......Page 44
1.3 Summary......Page 45
What are rule-based systems?......Page 46
2.1 The cooking/driving robot......Page 47
2.1.1 Declarative programming: a different approach......Page 48
2.2 Rules and rule engines......Page 50
2.2.1 Expert systems......Page 51
2.3 Architecture of a rule-based system......Page 52
2.3.1 The inference engine......Page 53
2.3.3 The working memory......Page 54
2.3.5 The agenda......Page 55
2.4.1 Knowledge engineering......Page 56
2.4.3 Testing......Page 57
2.4.5 Writing the rules......Page 58
2.5 Rule engine standards......Page 59
2.6 Summary......Page 60
Jess: A rule-based programming environment......Page 62
Introducing Jess......Page 64
3.1 The Jess rule engine......Page 65
3.1.2 Installing Jess......Page 66
3.1.4 “Hello, World”......Page 67
3.2 Jess applications......Page 69
3.2.1 Command line, GUI, or embedded?......Page 70
3.2.2 Jess performance......Page 71
3.3 Summary......Page 72
Getting started with the Jess language......Page 74
4.1.2 Symbols......Page 75
4.1.4 Numbers......Page 76
4.1.6 Comments......Page 77
4.2.1 Lists......Page 78
4.2.2 Calling functions......Page 79
4.2.3 Variables......Page 80
4.2.4 More about lists......Page 82
4.3 Control flow......Page 83
4.3.1 foreach......Page 84
4.3.3 if/then/else......Page 85
4.3.4 progn......Page 86
4.3.6 eval and build......Page 87
4.4 Defining functions with deffunction......Page 88
4.4.1 Late binding......Page 90
4.5 Fine-tuning a function’s behavior......Page 91
4.6 Summary......Page 93
Scripting Java with Jess......Page 94
5.1 Creating Java objects......Page 95
5.2 Calling Java methods......Page 97
5.2.1 Nesting function calls, and a shortcut......Page 98
5.2.3 Calling set and get methods......Page 99
5.2.4 Working with arrays......Page 100
5.2.5 How Jess chooses among overloaded methods......Page 101
5.3 Accessing Java member data......Page 102
5.4 Working with exceptions......Page 103
5.5 Summary......Page 106
Representing facts in Jess......Page 107
6.1 Jess’s working memory......Page 108
6.1.1 Manipulating the working memory......Page 109
6.2 Just the facts, ma’am......Page 114
6.3.1 The deftemplate construct......Page 115
6.3.2 Default slot values......Page 116
6.3.3 Multislots......Page 117
6.3.5 Copying facts with duplicate......Page 118
6.4 Ordered facts......Page 119
6.5 Shadow facts......Page 120
6.5.2 JavaBeans have “slots”......Page 121
6.5.3 An example JavaBean......Page 122
6.5.5 Putting a DimmerSwitch into working memory......Page 123
6.5.6 Static vs. dynamic shadow facts......Page 124
6.5.7 Adding PropertyChangeListener support to DimmerSwitch......Page 125
6.6 Summary......Page 127
Writing rules in Jess......Page 128
7.1 Forward-chaining rules......Page 129
7.2 Constraining slot data......Page 133
7.2.1 Literal constraints......Page 134
7.2.2 Variables as constraints......Page 135
7.2.3 Connective constraints......Page 137
7.2.4 Constraining matches with predicate functions......Page 138
7.2.5 Return value constraints......Page 139
7.2.6 Pattern bindings......Page 140
7.3.1 The and conditional element......Page 141
7.3.2 The or conditional element......Page 142
7.3.3 The not conditional element......Page 144
7.3.4 The test conditional element......Page 146
7.3.5 The logical conditional element......Page 147
7.4 Backward-chaining rules......Page 149
7.5 Managing the agenda......Page 153
7.5.2 Changing rule priority with salience......Page 154
7.6.1 Defining constructs in modules......Page 156
7.6.2 Modules, scope, and name resolution......Page 157
7.6.3 Module focus and execution control......Page 159
7.7 Searching working memory with defquery......Page 161
7.7.2 Query trigger facts......Page 163
7.8 Summary......Page 164
Under the hood: how Jess works......Page 166
8.1 Review of the problem......Page 167
8.2 An inefficient solution......Page 168
8.3.1 How Rete works......Page 169
8.4 Easy optimizations for Rete......Page 172
8.5.1 Node index hash value......Page 174
8.6.1 Implementing the not conditional element......Page 175
8.7.1 The (watch compilations) command......Page 176
8.7.2 The view function......Page 177
8.8 Summary......Page 179
Creating your first rule-based application: the Tax Forms Advisor......Page 180
Collecting the knowledge......Page 182
9.2 Introduction to knowledge engineering......Page 183
9.2.1 Where do you start?......Page 184
9.2.2 Interviews......Page 186
9.2.3 Desk research......Page 189
9.3.1 An interview......Page 190
9.3.2 Reviewing the forms......Page 192
9.4 Summary......Page 193
Designing the application......Page 194
10.1 Organizing the data......Page 195
10.2.1 Default slot values......Page 196
10.3 More templates......Page 197
10.4 Templates you don’t need......Page 198
10.6 Building the infrastructure......Page 199
10.6.1 Simple text-based I/O......Page 200
10.6.2 Fetching the question text......Page 201
10.7 Summary......Page 203
Writing the application......Page 205
11.1.1 Testing the startup module......Page 206
11.2 Asking the user questions......Page 207
11.2.1 Income and dependents......Page 208
11.2.2 Dealing with special circumstances......Page 209
11.3 Recommending forms......Page 210
11.4 Explaining the results......Page 214
11.5 Finishing touches......Page 215
11.6 Testing the full application......Page 216
11.7 Summary......Page 217
Writing a diagnostic application: the PC Repair Assistant......Page 218
Writing the PC Repair Assistant......Page 220
12.1 Using flowcharts in knowledge engineering......Page 221
12.1.1 From flowcharts to rules......Page 222
12.2 The problem domain......Page 223
12.2.1 Writing the first rules......Page 224
12.3 Asking questions with backward chaining......Page 226
12.4 Checking the answers......Page 227
12.4.1 Modifying the ask module......Page 228
12.5.1 Rules about sound......Page 230
12.5.2 Degrading gracefully......Page 231
12.5.4 RAM problems......Page 232
12.5.5 Questioning authority......Page 233
12.6 Testing......Page 234
12.7 Summary......Page 235
Adding a graphical interface......Page 236
13.1 Getting started......Page 237
13.2 Displaying a window......Page 238
13.3 Displaying questions......Page 239
13.4 Getting answers......Page 240
13.4.1 The main thread vs. the event thread......Page 242
13.5 Better input components......Page 246
13.6 Finishing touches......Page 247
13.7 Testing the interface......Page 248
13.8 Summary......Page 249
Reasoning about reality: the HVAC Controller......Page 252
The reality connection......Page 254
14.1 The system......Page 256
14.2.1 Native methods......Page 257
14.2.2 Writing a simulator......Page 258
14.2.3 Simulating getTemperature......Page 260
14.3 Writing the JavaBeans......Page 262
14.3.1 Rules about Thermometers......Page 265
14.3.2 Writing the other Beans......Page 266
14.5 Summary......Page 268
Extending the Jess language......Page 270
15.1 The Userfunction interface......Page 271
15.1.3 Loading a Userfunction into Jess......Page 272
15.2.1 How many arguments?......Page 273
15.2.2 Using arguments......Page 274
15.2.3 Resolving variable arguments......Page 275
15.2.4 Resolving function call arguments......Page 276
15.3.1 Constructing Value objects......Page 278
15.4.2 Multiple personalities......Page 279
15.4.4 Grouping functions with Userpackage......Page 280
15.5.1 Creating a simulator......Page 281
15.5.2 Counting devices......Page 282
15.5.3 Matching heat pumps and floors......Page 283
15.5.4 Operating the hardware......Page 284
15.6 Testing......Page 286
15.7 Summary......Page 287
Writing the rules......Page 288
16.1.1 Knowledge engineering with truth tables......Page 289
16.1.3 Using guard lines......Page 290
16.2 Setting up......Page 291
16.3 Controlling the heat pumps......Page 292
16.3.1 Enough is enough......Page 293
16.3.2 The moment of truth......Page 294
16.4.1 The vent rules......Page 295
16.5 Testing the whole system......Page 296
16.6 Controlling with fuzzy rules......Page 297
16.6.1 Fuzzy logic, briefly......Page 298
16.6.2 The Fuzzy HVAC Controller......Page 302
16.7 What’s next?......Page 315
16.8 Summary......Page 316
TekMart.com: rule-based applications for the Web......Page 318
Jess on the Web......Page 320
17.1.1 Fat-client applications......Page 321
17.1.2 Thin-client applications......Page 323
17.3 Knowledge engineering......Page 325
17.4 Designing data structures......Page 326
17.5.1 About testing......Page 328
17.5.2 The recommend-requirements rule......Page 329
17.5.3 Recommending videos and DVDs......Page 330
17.5.4 Conspicuous consumption......Page 331
17.5.5 More media rules......Page 332
17.6 Refining the recommendations......Page 333
17.7 Some useful queries......Page 334
17.7.1 Maintaining the order number......Page 335
17.8 Cleaning up......Page 336
17.9 Summary......Page 337
Embedding Jess in Java applications......Page 339
18.1 Getting started with the Jess library......Page 340
18.1.2 Exchanging Java objects......Page 341
18.1.3 Beyond executeCommand......Page 343
18.2 Working with Fact objects in Java......Page 344
18.2.2 Ordered facts......Page 346
18.3 Working with JavaBeans......Page 347
18.4 Calling Jess functions from Java......Page 348
18.5 Working with JessException......Page 349
18.5.1 Nested exceptions......Page 350
18.5.2 Rolling your own......Page 351
18.6 Input and output......Page 352
18.6.1 Using custom routers......Page 353
18.7 Summary......Page 354
Deploying web-based applications......Page 356
19.1 The Java Servlet API......Page 358
19.2.1 Deploying the Hello servlet......Page 359
19.3 Your first Jess servlet......Page 362
19.3.1 Deploying the Jess servlet......Page 363
19.4 Application architecture: take one......Page 364
19.5.1 JavaServer Pages......Page 365
19.5.2 Forwarding to a JSP......Page 366
19.7 The login screen......Page 368
19.8.1 Initializing Jess......Page 370
19.8.2 Getting the login name......Page 371
19.8.3 Starting a user session......Page 372
19.8.5 Invoking the JSP......Page 373
19.8.6 The catalog JSP......Page 374
19.10 The Recommend servlet......Page 376
19.10.2 Creating the order......Page 377
19.10.3 Getting the recommendations......Page 378
19.11 The recommend JSP......Page 379
19.12 The Purchase servlet......Page 381
19.13 Persistence......Page 383
19.14 Deploying the application......Page 384
19.15 What’s next?......Page 385
19.16 Summary......Page 386
Enterprise systems......Page 388
Jess, XML, and the enterprise......Page 390
20.1 Enterprise applications......Page 391
20.1.2 What does that stand for?......Page 392
20.2 Rules and XML......Page 393
20.2.1 Interoperability......Page 394
20.2.3 Storage and retrieval......Page 395
20.3.1 RuleML......Page 396
20.3.2 DAML......Page 397
20.3.4 Strategies for representing rules in XML......Page 398
20.4 Representing Jess rules in XML......Page 400
20.4.1 An example rule......Page 401
20.4.2 Transforming the XML rules into Jess rules......Page 402
20.5 Rule editors......Page 405
20.6 Summary......Page 407
Jess in the J2EE environment......Page 408
21.1.1 Kinds of EJBs......Page 409
21.1.3 Do you need to use EJBs?......Page 410
21.1.4 Accessing external resources from EJBs......Page 411
21.2.1 The remote interfaces......Page 412
21.2.2 Implementing the interfaces......Page 413
21.2.5 A sample client......Page 415
21.3 JSR 94: the javax.rules API......Page 416
21.3.1 Working with javax.rules......Page 417
21.3.2 The reference implementation......Page 419
21.4 Summary......Page 421
Appendix A - Jess functions......Page 422
Appendix B - Abridged Java API for Jess......Page 448
B.2 jess.Fact......Page 449
B.4 jess.Jesp......Page 450
B.5 jess.JessEvent......Page 451
B.7 jess.PrettyPrinter......Page 452
B.8.1 Working with events......Page 453
B.8.4 Finding things......Page 454
B.9 jess.RU......Page 455
B.11 jess.Value......Page 456
B.12 jess.ValueVector......Page 458
Appendix C - An automated testing framework......Page 460
C.1 Architecture......Page 461
C.2 The Jess template......Page 462
C.3 The Java template......Page 463
A......Page 466
D......Page 467
E......Page 468
G......Page 469
J......Page 470
N......Page 472
R......Page 473
S......Page 474
U......Page 475
Z......Page 476

Jess in action: rule-based systems in Java
 1930110898, 9781930110892

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Recommend Papers