Project

General

Profile

Cruximplement » History » Version 35

Shuvam Misra, 21/09/2023 01:37 AM

1 4 Shuvam Misra
*(For a conceptual overview and design of Crux, see [[cruxdesign|this page]] if you haven't already.)*
2
3 35 Shuvam Misra
# Algorithms and data structures for the Crux BRE
4 1 Shuvam Misra
5
{{>toc}}
6 35 Shuvam Misra
7
This page documents the rules engine. It does not cover the flow engine.
8 1 Shuvam Misra
9
A rules engine implementation must include the following:
10
* **RULE SCHEMA**. A notation to specify the list of valid terms in a rule. This list will be separate for each class of entities. For instance, for items in inventory, the list of attributes may be:
11
  * Price
12
  * Full name
13
  * Age in stock
14
  * Quantity in inventory
15
16
    For vendors, the list could include:
17
  * Amount outstanding
18
  * Total value of business done  in the last financial year
19
20
* **RULE NOTATION**. A notation to specify the pattern and actions of a rule.
21
* **THE MATCHING ENGINE**. Something which will take an entity with all its attributes, apply each rule to it, and follow the trail of rules to come up with a list of actions which will emerge.
22
23
So, if these three can be designed and then implemented, the core of a rules engine or a flow engine can be built.
24
25 2 Shuvam Misra
## Representing the schema of patterns
26 1 Shuvam Misra
27
If using JSON, the schema of all valid patterns may be represented in structures of this form:
28
29
``` json
30
"patternschema": {
31
    "class": "inventoryitems",
32
    "attr": [{
33
        "name": "cat",
34
        "type": "enum",
35
        "vals": [ "textbook", "notebook", "stationery", "refbooks" ]
36
    },{
37
        "name": "mrp",
38
        "type": "float"
39
    },{
40
        "name": "fullname",
41
        "type": "str",
42
    },{
43
        "name": "ageinstock",
44
        "type": "int"
45
    },{
46
        "name": "inventoryqty",
47
        "type": "int"
48
    }]
49
}
50
```
51
52 20 Shuvam Misra
In this example, the object `patternschema` is the schema for one category of entities. This schema says that for rules which work on entities of type `inventoryitems`, there are five attributes available which may be used to make patterns. Each attribute has a type. Boolean, enum types, integers, floating point numbers, timestamps (`ts`) and strings are supported. The example above does not have any attribute of type `ts` or  `bool`.
53 1 Shuvam Misra
54
So, the full schema of the rules engine will be an array of `patternschema` blocks. Initial examples have discussed inventory items and vendors. The `patternschema` block above is for inventory items. If the schema of patterns for vendors needed to be specified, there would be a second `patternschema` with `“class”: “vendors”`
55
56 5 Shuvam Misra
While the fields in the example above are adequate from a purely functional point of view, it may be necessary to have some additional metadata to allow the building of a good UI which will allow users to manage these schema objects. So, an augmented data structure may look like this:
57
58
``` json
59
"patternschema": {
60
    "class": "inventoryitems",
61
    "attr": [{
62
        "name": "cat",
63
        "shortdesc": "Category of item",
64
        "longdesc": "Each item can belong to one of the following categories: textbooks, notebooks, stationery, or reference books.",
65
        "type": "enum",
66
        "vals": [ "textbook", "notebook", "stationery", "refbooks" ],
67
        "enumdesc": [ "Text books", "Notebooks", "Stationery and miscellaneous items", "Reference books, library books" ]
68
    },{
69
        "name": "mrp",
70
        "shortdesc": "Maximum retail price",
71
        "longdesc": "The maximum retail price of the item as declared by the manufacturer."
72
        "type": "float",
73
        "valmax": 20000,
74
        "valmin": 0
75
    },{
76
        "name": "fullname",
77
        "shortdesc": "Full name of item",
78
        "longdesc": "The full human-readable name of the item. Not unique, therefore sometimes confusing.",         
79
        "type": "str",
80
        "lenmax": 40,
81
        "lenmin": 5
82
    },{
83
        "name": "ageinstock",
84
        "shortdesc": "Age in stock, in days",
85
        "longdescr": "The age in days that the oldest sample of this item has been lying in stock",
86
        "type": "int",
87
        "valmax": 1000,
88
        "valmin": 1
89
    },{
90
        "name": "inventoryqty",
91
        "shortdesc": "Number of items in inventory",
92
        "longdescr": "How many of these items are currently present in the inventory",
93
        "type": "int",
94
        "valmax": 10000,
95
        "valmin": 0
96
    }]
97
}
98
```
99
100
Here, the `shortdesc` and `longdesc` are useful attributes of each attribute, for displaying labels and help text in any UI which is displayed to the human user who manages the rules for entities of this class. The `valmax`, `valmin`, `lenmax`, `lenmin`, allow the system to enforce some sanity checks on the patterns defined in any rules for this entity.
101
102 2 Shuvam Misra
## Representing the schema of actions
103 1 Shuvam Misra
104
The schema of the action section of rules is simpler than patterns. Each rule's action section will contain a set of zero or more words, each denoting an action, and zero or more attribute assignments. There is no need for any type specification, etc.
105
* An example of an action word: `invitefordiwali`
106
* An example of an attribute assignment: `discount=7`
107
108
So, the schema of the actions will just specify the valid action names and the attribute names for assignments.
109
110
``` json
111
"actionschema": {
112
    "class": "inventoryitems",
113
    "actions": [ "invitefordiwali", "allowretailsale", "assigntotrash" ],
114
    "attribs": [ "discount", "shipby" ],
115
    "tags": [ "specialvendor", "tryoverseas" ]
116
}
117
```
118
The schema of actions above indicates that there are three actions, any or all of which may be present in any rule for this class of entities. There are two attributes which may be assigned values by any rule. And there are two tags for this class of entities – if a rule wishes to tag an entity with one or both of these tags, it may do so.
119
120
Putting the `patternschema` and `actionschema` blocks together, a better representation for the full schema for a class of entities will be:
121
122
``` json
123
"ruleschema": {
124
    "class": "inventoryitems",
125
    "patternschema": {
126
        "attr": [{
127
            "name": "cat",
128
            "type": "enum",
129
            "vals": [ "textbook", "notebook", "stationery", "refbooks" ]
130
        },{
131
            "name": "mrp",
132
            "type": "float"
133
        },{
134
            "name": "fullname",
135
            "type": "str",
136
        },{
137
            "name": "ageinstock",
138
            "type": "int"
139
        },{
140
            "name": "inventoryqty",
141
            "type": "int"
142
        }]
143
    }
144
    "actionschema": {
145
        "actions": [ "invitefordiwali", "allowretailsale", "assigntotrash" ],
146
        "attribs": [ "discount", "shipby" ],
147
    }
148
}
149
```
150
151
There will need to be one such `ruleschema` block for each class.
152
153 2 Shuvam Misra
## Representing a pattern
154 1 Shuvam Misra
155 6 Shuvam Misra
Below is an example of a pattern of a rule, which conforms to the schema example given above.
156
157 1 Shuvam Misra
``` json
158
"rulepattern": {
159
    "pattern": [{
160
        "attr": "cat",
161
        "op": "eq",
162
        "val": "textbook"
163
    },{
164
        "attr": "mrp",
165
        "op": "ge",
166
        "val": 2000
167
    },{
168
        "attr": "ageinstock",
169
        "op": "ge",
170
        "val": 90
171 22 Shuvam Misra
    },{
172
        "attr": "invitefordiwali",
173
        "op": "eq",
174
        "val": true
175 1 Shuvam Misra
    }]
176
}
177
```
178
179
If a rule has this pattern, it will match any entity which falls in the class `inventoryitems` which
180
* is of type textbook
181
* has MRP (max retail price) greater than INR 2000
182 25 Shuvam Misra
* has been in stock longer than 89 days 
183
* one of the earlier rules matched against this entity has added the action `invitefordiwali` to the action set of this entity
184 22 Shuvam Misra
185
It is important to note that a pattern does not need to have just the attributes listed in `patternschema`. It may also include actions listed in the `ruleschema`. Each such action becomes an implicit attribute of type `bool` for this class.
186 1 Shuvam Misra
187
For attributes which are of type `int`, `float`, `str` and `ts`, the following comparison operators are available:
188
* Greater than or equal to: `ge`
189
* Greater than: `gt`
190
* Less than or equal to: `le`
191
* Less than: `lt`
192
* Equal to: `eq`
193
* Not equal to: `ne`
194
195
Collation sequences for strings are system dependent, and will need to be standardised so that they work reliably across programming languages and Unicode strings in any language. That's an implementation issue.
196
197 21 Shuvam Misra
For `enum` and `bool` types, only `eq` and `ne` are available.
198 1 Shuvam Misra
199 2 Shuvam Misra
## Representing an action
200 1 Shuvam Misra
201
A rule has a set of one or more actions. The following are all examples of the action section of rules:
202
* `invitefordiwali`
203
* `discount=7`
204
* `shipwithoutpo`
205
* `CALL=intlbiz`
206
207
The terms which identify actions, *e.g.* `invitefordiwali`, will automatically be converted to lower-case and stored in the system. Reserved attribute names like `CALL`, `RETURN`, `EXIT`, will always be in uppercase. For an attribute assignment, the value of the attribute will be everything after the first `=` character till the end of the string, thus supporting multi-word values, *e.g.*
208
* `reprimand=This cannot go on any longer`
209
210
The action portion of a rule can have zero or one occurrence of a `CALL` term, a `RETURN` term, and an `EXIT` term. If it contains both a `RETURN` and an `EXIT`, then the `RETURN` will be ignored.
211
212
The action portion of a rule will have the following structure, shown here as an example:
213
``` json
214
"ruleactions": {
215
    "actions": [ "christmassale", "vipsupport" ],
216
    "attribs": [ "shipby=fedex" ],
217
    "call": "internationalrules",
218
    "return": true,
219
    "exit": false
220
}
221
```
222
This example shows all five attributes of `ruleactions`, but in reality, some of the attributes will typically be missing from most of the rules.
223
224 2 Shuvam Misra
## An entire rule
225 1 Shuvam Misra
226
This is what an entire rule looks like:
227
228
``` json
229
"rule": {
230
    "class": "inventoryitems",
231
    "ver": 4,
232
    "rulepattern": [{
233
        "attr": "cat",
234
        "op": "eq",
235
        "val": "textbook"
236
    },{
237
        "attr": "mrp",
238
        "op": "ge",
239
        "val": 5000
240
    }],
241
    "ruleactions": {
242
        "actions": [ "christmassale" ],
243
        "attribs": [ "shipby=fedex" ]
244
    }
245
}
246
```
247
248
This structure represents one rule. The rule applies to entities of class `inventoryitems`. It has a pattern section which tries to match two attributes and an action section which throws up one action and one assignment.
249
250
A rule has a version number, which is incremented whenever the rule is updated. This number is for internal logging and rule engine debugging.
251
252
An array of such structures is a set of rules, and will be traversed in the order in which the rules appear in the array. Named rulesets will be represented thus:
253
``` json
254
"ruleset": {
255
    "class": "inventoryitems",
256
    "setname": "overseaspo",
257
    "rules": [{
258
        "ver": 4,
259
        "rulepattern": {
260
            :
261
            :
262
        },
263
        "ruleactions": {
264
            :
265
            :
266
        }
267
    }, {
268
        "ver": 3,
269
        "rulepattern": {
270
            :
271
            :
272
        },
273
        "ruleactions": {
274
            :
275
            :
276
        }
277
    }]
278
}
279
```
280
The example above shows a ruleset named `overseaspo` for class `inventoryitems` which has two rules. This ruleset may be invoked from any other rule with the action `CALL=overseaspo`.
281
282 2 Shuvam Misra
## The schema manager
283 1 Shuvam Misra
284 7 Shuvam Misra
The schema for each class of entities may be written by hand using a text editor. JSON or YAML files are easy to write. If the schema of one class has less than a dozen attributes, it may be short enough to edit or audit by hand. However, a tool to manage and maintain the schema eliminates typos and enforces various types of consistency, and a second-level implementation of a schema manager may also enforce authorisation policies.
285 1 Shuvam Misra
286
A schema manager will have the following features:
287
* It will allow the user to create new instances of `ruleschema`
288
* It will sharply restrict editing of, and prevent deletion of any `patternschema` block or `actionschema` block if there are rules defined in the rules engine for this class of entities. In other words, schema are editable only as long as there are no rules for the class. The only kind of editing it will permit for “live” schema are
289
  * the addition of additional attributes in a `patternschema` or
290
  * additional attributes, action names or tags in an `actionschema`.
291
* It will ensure that there is no scope for typos when defining the schema.
292
293 3 Shuvam Misra
## The rule manager
294 1 Shuvam Misra
295
The rule manager will allow a user to manage rules. Core functionality:
296
* It will provide a user interface to let the user edit rules.
297
* It will check each rule against the schema for the class, and will not give the user the opportunity to define any rule inconsistent with the schema.
298
* It will allow the user to move a rule up or down in the sequence, since ordering is important.
299
* If a rule is being defined with a `CALL` action, then the rule manager will ensure that a ruleset with that target name exists.
300
* Most important: it will provide a testing facility by which sample entities may be submitted to the rule engine for testing, and the rule manager will display a full trace showing which rules were attempted to match, which rules actually matched, and how the result set of actions, attributes, *etc* grew with each step. This feature will be provided without having to save the rule changes.
301
* Finally, when the editing session is complete and all rulesets need to be saved, it will perform a detailed cross-validation of all rules across each other to ensure consistency. If there is any inconsistency, it will give readable explanations of the problems and not permit saving of the updates.
302
303 2 Shuvam Misra
## The matching engine
304 1 Shuvam Misra
305
The matching engine has a one-line job. It will take a full set of attributes of one entity, apply all the rules which apply to its class, and return with the list of actions, attributes, *etc* from all the matching rules.
306
307 11 Shuvam Misra
The operation of the engine, in a highly simplified notation, is:
308
```
309
for each rule in the ruleset do
310
    match the pattern of the rule with the entity
311
    if the pattern matches, then
312
        collect the actions from the rule into the actionset
313
    endif
314
endfor
315
```
316 1 Shuvam Misra
317 2 Shuvam Misra
### Matching one rule's pattern
318 1 Shuvam Misra
319 18 Shuvam Misra
The algorithm for the matching of one rule's pattern is shown below. Here, it is assumed that the object being matched is in `entity` and pattern of the rule being matched is in `rulepattern`. It is assumed that the matching engine  may have proceeded some distance in its matching process, and may have collected zero or more actions in its `actionset`.
320 1 Shuvam Misra
```
321
func matchOnePattern()
322 18 Shuvam Misra
    input parameters: entity, rulepattern, actionset
323 1 Shuvam Misra
    returns patternmatch: boolean
324
325 16 Shuvam Misra
#
326
# In this loop we iterate through terms from our pattern array
327
# one by one
328 1 Shuvam Misra
#
329
for patternterm in rulepattern do
330 18 Shuvam Misra
    #
331
    # We get into a loop, stepping through the attributes of this
332
    # entity to pull out the value of the attribute
333
    # we will now be matching against the term we have selected
334
    # for this iteration of the outer loop, i.e. patternterm
335
    #
336 19 Shuvam Misra
    entitytermval = null
337 18 Shuvam Misra
    for entityoneterm in entity.attrs do
338
        if entityoneterm.attr == patternterm.attr then
339
            entitytermval = entityoneterm.val
340
        endif
341 1 Shuvam Misra
    endfor
342 19 Shuvam Misra
343
    if entitytermval == null then
344
        #
345
        # We reach here if none of the attributes in the entity
346
        # has a name matching the term in the pattern array. This
347
        # can only mean one thing: this is a pattern clause which
348 26 Shuvam Misra
        # will match a tag with which this entity has been tagged.
349
        # A tag is an action clause which has already been collected
350
        # against this entity from matching a previous rule.
351 19 Shuvam Misra
        #
352
        # So we will now cycle through the action clauses in the
353
        # actionset to see if any of those matches this patternterm.
354
        #
355
        for oneactionclause in actionset.actions do
356
            if oneactionclause == patternterm.attr then
357
                #
358
                # Bingo! We have found an action clause which matches
359
                # the name of an entry in the pattern array.
360
                #
361
                entitytermval = "true"
362 18 Shuvam Misra
            endif
363 19 Shuvam Misra
        endfor
364 18 Shuvam Misra
    endif
365
366 19 Shuvam Misra
    if entitytermval == null then
367
        #
368
        # If we reach here, it means that we have a term of the entity which
369
        # is not listed in the pattern at all. Every entity has all the
370
        # attributes listed against its class in the schema, but rule patterns
371
        # may have just one or two terms, so it's likely that many of the
372
        # attributes of an entity may not match any term in the pattern array.
373
        #
374
        # In that case we just loop to the next term in the pattern array.
375
        #
376
        continue
377
    endif
378
379 1 Shuvam Misra
    case patternterm.op in
380
    "eq":
381
        if entitytermval != patternterm.val then
382
            return false
383
        endif
384
    "ne":
385
        if entitytermval == patternterm.val then
386
            return false
387
        endif
388
    endcase
389
    if patternterm.type in [ "int", "float", "ts", "str" ] then
390
        case patternterm.op in
391
        "le":
392
            if entitytermval > patternterm.val then
393
                return false
394
            endif
395
        "lt":
396
            if entitytermval >= patternterm.val then
397
                return false
398
            endif
399
        "ge":
400
            if entitytermval < patternterm.val then
401
                return false
402
            endif
403
        "gt":
404
            if entitytermval <= patternterm.val then
405
                return false
406
            endif
407
        default:
408
            log error with priority = CRITICAL: "system inconsistency with BRE rule terms"
409
        endcase
410
    endif
411
endfor
412
413
return true
414 2 Shuvam Misra
```
415 1 Shuvam Misra
416
### Collecting the actions from one rule
417
418
If the pattern for one rule matches the entity being processed, then the actions of that rule will need to be added to the result set for that entity. Here we assume that the result of the action-collection function will return an object of the following structure. This object will be passed as input to the action-collecting function, and a (possibly extended) object will be returned, after merging the input object with the action terms from the rule just matched. The object structure will be:
419
``` json
420
"actionset": {
421
    "actions": [ "dodiscount", "yearendsale" ],
422
    "attribs": [ "shipby=fedex" ],
423
    "call": "overseaspo",
424
    "return": true,
425
    "exit": false
426 8 Shuvam Misra
}
427 1 Shuvam Misra
```
428
These five attributes will always be present in the object. The `actions` and `attribs` attributes will carry an array of strings, which will be a union set of all the action terms and attribute assignments collected from rules matched so far. The `call` attribute will either be a zero-length string (signifying that no ruleset needs to be called after this rule returns) or will carry the name of one ruleset to call after the current rule. The `return` and `exit` attributes will carry boolean values.
429
430
Performing a set union of action names is straightforward. Performing a set union of attribute assignments requires choosing one value of an attribute, if there was already the same attribute in the `actionset` and the current rule's actions also assigns a value to that attribute. In that case, the old value of the attribute will be overwritten by the new value.
431
432
```
433
function collectActions()
434
input parameters: actionset, ruleactions
435
    returns actionset
436
437
actionset.actions = actionset.actions UNION ruleactions.actions
438
actionset.attribs = actionset.attribs UNION ruleactions.attribs
439
440
actionset.call = ""
441
actionset.return = false
442
actionset.exit = false
443
if ruleactions.call is defined, then
444
    actionset.call = ruleactions.call
445
endif
446
if ruleactions.return is defined, then
447
    actionset.return = true
448
endif
449
if ruleactions.exit is defined,  then
450 14 Shuvam Misra
    actionset.exit = true
451
endif
452 1 Shuvam Misra
453
return actionset
454
```
455
456 13 Shuvam Misra
The matching engine needs to look at what has emerged from `collectActions()` and then take action. The flow of the matching engine will change based on the values of the `call`, `return` and `exit` attributes.
457
458 1 Shuvam Misra
### Representing one entity
459 14 Shuvam Misra
460 1 Shuvam Misra
The matching engine matches all the rules of a ruleset against one instance of a class, like one instance of `vendor` or `inventoryitem`. How do we represent this object instance, when the type and the fields are all dynamically determined at runtime and varies from invocation to invocation? Here is one example:
461
``` json
462
"inputentity": {
463 14 Shuvam Misra
    "class": "inventoryitems",
464
    "attribs": [{
465
        "name": "cat",
466
        "val": "refbook"
467
    },{
468
        "name": "mrp",
469
        "val": "1350"
470
    },{
471
        "name": "fullname",
472
        "val": "Advanced Level Physics, 2/ed"
473
    },{
474
        "name": "ageinstock",
475
        "val": "20"
476
    },{
477
        "name": "inventoryqty",
478 1 Shuvam Misra
        "val": "540"
479
    }]
480 14 Shuvam Misra
}
481 1 Shuvam Misra
```
482 14 Shuvam Misra
As this example highlights, all the values are supplied of type string, so that they may be converted from strings to their respective types later. This allows the data structure for specifying an object instance to be strongly typed and still allow attributes of all types to be captured. One more point illustrated is that **all attributes in the `patternschema` of the class must be present** in each object instance of that class.
483
484 1 Shuvam Misra
This is the way the entity will be submitted to the matching engine for processing.
485 13 Shuvam Misra
486 27 Shuvam Misra
### `doMatch()`: the matching function
487 13 Shuvam Misra
488 14 Shuvam Misra
This engine will go through rules one after another, and for each rule, it will call `matchOnePattern()`. If `matchOnePattern()` returns `true`, it will call `collectActions()`. And then it will inspect the result obtained from `collectActions()` and decide what to do next.
489
490
This engine will be implemented by the `getRules()` function, which will occasionally call itself recursively. It will be called with three parameters:
491
* an `inputentity`, which will be matched against the ruleset
492 1 Shuvam Misra
* a `ruleset` which will be traversed by the engine
493 14 Shuvam Misra
* an `actionset`, which collects the result of the action matching
494 1 Shuvam Misra
495
The pseudocode has been written with the assumption that parameters are all pass-by-value.
496
497
So, the `doMatch()` engine will work in the following way:
498 14 Shuvam Misra
```
499 1 Shuvam Misra
function doMatch()
500
input parameters: inputentity, ruleset, actionset
501 14 Shuvam Misra
    returns actionset
502
503
for each onerule in ruleset do
504 23 Shuvam Misra
    if matchOnePattern(inputentity, onerule.pattern, actionset) == true then
505 14 Shuvam Misra
        actionset = collectActions(actionset, onerule.actions)
506
        #
507
        # now check if the actions just collected includes an EXIT clause
508
        #
509
        if actionset.exit == true then
510
            return actionset
511
        endif
512
        #
513
        # If there was no EXIT clause, check if there was a RETURN clause
514
        #
515
        if actionset.return == true then
516
            actionset.return = false
517
            return actionset
518
        endif
519
        #
520
        # If there was no EXIT or RETURN, check if there was a CALL clause
521
        #
522 15 Shuvam Misra
        if actionset.call is not null then
523
            settocall = actionset.call
524
            if settocall.class != inputentity.class then
525
                log error with priority = CRITICAL:
526 14 Shuvam Misra
                       "system inconsistency with BRE rule terms, attempting to call ", settocall, " from ", ruleset, "!"
527
            endif
528
            actionset.call = null
529
            doMatch(inputentity, settocall, actionset)
530
            #
531
            # If the called ruleset has set EXIT to true, then we too need to
532
            # exit, and our caller too needs to exit, ad infinitum
533
            #
534
            if actionset.exit == true then
535
                return actionset
536
            endif
537
        endif
538
    endif
539
    #
540
    # We come here because we've done one rule and we've neither been thrown
541
    # out by an EXIT nor a RETURN clause. So we now loop to the next rule in
542
    # our ruleset.
543 13 Shuvam Misra
    #
544 14 Shuvam Misra
endfor
545 10 Shuvam Misra
546 14 Shuvam Misra
return actionset
547
```
548 1 Shuvam Misra
549 24 Shuvam Misra
This matching engine will be able to traverse all rulesets, make "subroutine calls" from one ruleset to another, and finally come up with a consolidated `actionset`.
550
551
The outermost calling code which calls the outermost layer of `doMatch()` for a given entity will initialise an empty `actionset` and pass it in. After all the ruleset traversals, `doMatch()` will return with a loaded `actionset`, which will then be returned to the client of the BRE.
552 1 Shuvam Misra
553 29 Shuvam Misra
## API for the BRE
554 1 Shuvam Misra
555 29 Shuvam Misra
The BRE must support the following set of operations:
556 32 Shuvam Misra
* Schema management:
557
  * `schemaAdd()`: add a new rule schema, for a new class
558
  * `schemaUpdate()`: update an existing schema
559
  * `schemaDelete()`: delete an existing schema
560
  * `schemaList()`: list all the schema for all classes
561
  * `schemaGet()`: get the full schema for one class, given the class name
562
* Ruleset management:
563
  * `rulesetAdd()`: add a new ruleset for a class, with one or more rules
564
  * `rulesetUpdate()`: update an existing ruleset
565
  * `rulesetDelete()`: delete a ruleset
566
  * `rulesetList()`: list all rulesets for a class
567
  * `rulesetGet()`: get the full ruleset, given the class name and the ruleset name
568
* Query the BRE and get the list of actions and attributes for an entity:
569
  * `doMatch()`: take an entity, pass it through all relevant rules and rulesets, and respond with the set of final results. This call will fail unless the `inputentity` carries all the attributes listed in the schema of this class.
570
  * `getAttrSet()`: take a class name, pull out from the `patternschema` all the attributes listed against that class, with full details. This is useful to let the caller know what attributes are to be specified when calling `doMatch()`.
571 33 Shuvam Misra
* Rule engine management:
572
  * `setConfig()`: set one or more global configuration parameters of the engine
573
  * `getConfig()`: get values of one or more global config parameters of the engine
574
  * `setAuth()`: set authorization rules to allow access to the engine
575
  * `getAuth()`: get authorization rules which control access to the engine
576
  * `shutdown()`: shut down the engine
577 34 Shuvam Misra
  * `sysReset()`: the equivalent of a factory reset. All configuration reverts to that which is present in a fresh install, and all schema, rulesets and other information is lost.