Project

General

Profile

Cruximplement » History » Version 43

Kaushal Alate, 13/10/2023 01:02 PM

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 41 Kaushal Alate
In this example, the object `patternschema` is the schema for one class of entities. This schema says that for rules which work on entities of class `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 42 Kaushal Alate
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 a task, and zero or more property assignments. There is no need for any type specification, etc.
105
* An example of a task word: `invitefordiwali`
106
* An example of a property assignment: `discount=7`
107 1 Shuvam Misra
108 42 Kaushal Alate
So, the schema of the actions will just specify the valid task names and the property names for assignments.
109 1 Shuvam Misra
110
``` json
111
"actionschema": {
112
    "class": "inventoryitems",
113 43 Kaushal Alate
    "tasks": [ "invitefordiwali", "allowretailsale", "assigntotrash" ],
114
    "properties": [ "discount", "shipby" ],
115 1 Shuvam Misra
}
116
```
117 43 Kaushal Alate
The schema of actions above indicates that there are three tasks, any or all of which may be present in any rule for this class of entities. There are two properties which may be assigned values by any rule.
118 1 Shuvam Misra
119
Putting the `patternschema` and `actionschema` blocks together, a better representation for the full schema for a class of entities will be:
120
121
``` json
122
"ruleschema": {
123
    "class": "inventoryitems",
124
    "patternschema": {
125
        "attr": [{
126
            "name": "cat",
127
            "type": "enum",
128
            "vals": [ "textbook", "notebook", "stationery", "refbooks" ]
129
        },{
130
            "name": "mrp",
131
            "type": "float"
132
        },{
133
            "name": "fullname",
134
            "type": "str",
135
        },{
136
            "name": "ageinstock",
137
            "type": "int"
138
        },{
139
            "name": "inventoryqty",
140
            "type": "int"
141
        }]
142
    }
143
    "actionschema": {
144 43 Kaushal Alate
        "tasks": [ "invitefordiwali", "allowretailsale", "assigntotrash" ],
145
        "properties": [ "discount", "shipby" ],
146 1 Shuvam Misra
    }
147
}
148
```
149
150
There will need to be one such `ruleschema` block for each class.
151
152 2 Shuvam Misra
## Representing a pattern
153 1 Shuvam Misra
154 6 Shuvam Misra
Below is an example of a pattern of a rule, which conforms to the schema example given above.
155
156 1 Shuvam Misra
``` json
157
"rulepattern": {
158
    "pattern": [{
159
        "attr": "cat",
160
        "op": "eq",
161
        "val": "textbook"
162
    },{
163
        "attr": "mrp",
164
        "op": "ge",
165
        "val": 2000
166
    },{
167
        "attr": "ageinstock",
168
        "op": "ge",
169
        "val": 90
170 22 Shuvam Misra
    },{
171
        "attr": "invitefordiwali",
172
        "op": "eq",
173
        "val": true
174 1 Shuvam Misra
    }]
175
}
176
```
177
178
If a rule has this pattern, it will match any entity which falls in the class `inventoryitems` which
179
* is of type textbook
180
* has MRP (max retail price) greater than INR 2000
181 25 Shuvam Misra
* has been in stock longer than 89 days 
182
* one of the earlier rules matched against this entity has added the action `invitefordiwali` to the action set of this entity
183 22 Shuvam Misra
184
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.
185 1 Shuvam Misra
186
For attributes which are of type `int`, `float`, `str` and `ts`, the following comparison operators are available:
187
* Greater than or equal to: `ge`
188
* Greater than: `gt`
189
* Less than or equal to: `le`
190
* Less than: `lt`
191
* Equal to: `eq`
192
* Not equal to: `ne`
193
194
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.
195
196 21 Shuvam Misra
For `enum` and `bool` types, only `eq` and `ne` are available.
197 1 Shuvam Misra
198 2 Shuvam Misra
## Representing an action
199 1 Shuvam Misra
200
A rule has a set of one or more actions. The following are all examples of the action section of rules:
201
* `invitefordiwali`
202
* `discount=7`
203
* `shipwithoutpo`
204
* `CALL=intlbiz`
205
206
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.*
207
* `reprimand=This cannot go on any longer`
208
209
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.
210
211
The action portion of a rule will have the following structure, shown here as an example:
212
``` json
213
"ruleactions": {
214
    "actions": [ "christmassale", "vipsupport" ],
215
    "attribs": [ "shipby=fedex" ],
216
    "call": "internationalrules",
217
    "return": true,
218
    "exit": false
219
}
220
```
221
This example shows all five attributes of `ruleactions`, but in reality, some of the attributes will typically be missing from most of the rules.
222
223 2 Shuvam Misra
## An entire rule
224 1 Shuvam Misra
225
This is what an entire rule looks like:
226
227
``` json
228
"rule": {
229
    "class": "inventoryitems",
230
    "rulepattern": [{
231
        "attr": "cat",
232
        "op": "eq",
233
        "val": "textbook"
234
    },{
235
        "attr": "mrp",
236
        "op": "ge",
237
        "val": 5000
238
    }],
239
    "ruleactions": {
240
        "actions": [ "christmassale" ],
241
        "attribs": [ "shipby=fedex" ]
242
    }
243
}
244
```
245
246
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.
247
248
A rule has a version number, which is incremented whenever the rule is updated. This number is for internal logging and rule engine debugging.
249
250
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:
251
``` json
252
"ruleset": {
253 40 Shuvam Misra
    "ver": 5,
254 1 Shuvam Misra
    "class": "inventoryitems",
255
    "setname": "overseaspo",
256
    "rules": [{
257
        "rulepattern": {
258
            :
259
            :
260
        },
261
        "ruleactions": {
262
            :
263
            :
264
        }
265
    }, {
266
        "rulepattern": {
267
            :
268
            :
269
        },
270
        "ruleactions": {
271
            :
272
            :
273
        }
274
    }]
275
}
276
```
277
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`.
278
279 2 Shuvam Misra
## The schema manager
280 1 Shuvam Misra
281 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.
282 1 Shuvam Misra
283
A schema manager will have the following features:
284
* It will allow the user to create new instances of `ruleschema`
285
* 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
286
  * the addition of additional attributes in a `patternschema` or
287
  * additional attributes, action names or tags in an `actionschema`.
288
* It will ensure that there is no scope for typos when defining the schema.
289
290 3 Shuvam Misra
## The rule manager
291 1 Shuvam Misra
292
The rule manager will allow a user to manage rules. Core functionality:
293
* It will provide a user interface to let the user edit rules.
294
* 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.
295
* It will allow the user to move a rule up or down in the sequence, since ordering is important.
296
* If a rule is being defined with a `CALL` action, then the rule manager will ensure that a ruleset with that target name exists.
297
* 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.
298
* 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.
299
300 2 Shuvam Misra
## The matching engine
301 1 Shuvam Misra
302
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.
303
304 11 Shuvam Misra
The operation of the engine, in a highly simplified notation, is:
305
```
306
for each rule in the ruleset do
307
    match the pattern of the rule with the entity
308
    if the pattern matches, then
309
        collect the actions from the rule into the actionset
310
    endif
311
endfor
312
```
313 1 Shuvam Misra
314 2 Shuvam Misra
### Matching one rule's pattern
315 1 Shuvam Misra
316 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`.
317 1 Shuvam Misra
```
318
func matchOnePattern()
319 18 Shuvam Misra
    input parameters: entity, rulepattern, actionset
320 1 Shuvam Misra
    returns patternmatch: boolean
321
322 16 Shuvam Misra
#
323
# In this loop we iterate through terms from our pattern array
324
# one by one
325 1 Shuvam Misra
#
326
for patternterm in rulepattern do
327 18 Shuvam Misra
    #
328
    # We get into a loop, stepping through the attributes of this
329
    # entity to pull out the value of the attribute
330
    # we will now be matching against the term we have selected
331
    # for this iteration of the outer loop, i.e. patternterm
332
    #
333 19 Shuvam Misra
    entitytermval = null
334 18 Shuvam Misra
    for entityoneterm in entity.attrs do
335
        if entityoneterm.attr == patternterm.attr then
336
            entitytermval = entityoneterm.val
337
        endif
338 1 Shuvam Misra
    endfor
339 19 Shuvam Misra
340
    if entitytermval == null then
341
        #
342
        # We reach here if none of the attributes in the entity
343
        # has a name matching the term in the pattern array. This
344
        # can only mean one thing: this is a pattern clause which
345 26 Shuvam Misra
        # will match a tag with which this entity has been tagged.
346
        # A tag is an action clause which has already been collected
347
        # against this entity from matching a previous rule.
348 19 Shuvam Misra
        #
349
        # So we will now cycle through the action clauses in the
350
        # actionset to see if any of those matches this patternterm.
351
        #
352
        for oneactionclause in actionset.actions do
353
            if oneactionclause == patternterm.attr then
354
                #
355
                # Bingo! We have found an action clause which matches
356
                # the name of an entry in the pattern array.
357
                #
358
                entitytermval = "true"
359 18 Shuvam Misra
            endif
360 19 Shuvam Misra
        endfor
361 18 Shuvam Misra
    endif
362
363 19 Shuvam Misra
    if entitytermval == null then
364
        #
365
        # If we reach here, it means that we have a term of the entity which
366
        # is not listed in the pattern at all. Every entity has all the
367
        # attributes listed against its class in the schema, but rule patterns
368
        # may have just one or two terms, so it's likely that many of the
369
        # attributes of an entity may not match any term in the pattern array.
370
        #
371
        # In that case we just loop to the next term in the pattern array.
372
        #
373
        continue
374
    endif
375
376 1 Shuvam Misra
    case patternterm.op in
377
    "eq":
378
        if entitytermval != patternterm.val then
379
            return false
380
        endif
381
    "ne":
382
        if entitytermval == patternterm.val then
383
            return false
384
        endif
385
    endcase
386
    if patternterm.type in [ "int", "float", "ts", "str" ] then
387
        case patternterm.op in
388
        "le":
389
            if entitytermval > patternterm.val then
390
                return false
391
            endif
392
        "lt":
393
            if entitytermval >= patternterm.val then
394
                return false
395
            endif
396
        "ge":
397
            if entitytermval < patternterm.val then
398
                return false
399
            endif
400
        "gt":
401
            if entitytermval <= patternterm.val then
402
                return false
403
            endif
404
        default:
405
            log error with priority = CRITICAL: "system inconsistency with BRE rule terms"
406
        endcase
407
    endif
408
endfor
409
410
return true
411 2 Shuvam Misra
```
412 1 Shuvam Misra
413 39 Shuvam Misra
Note how the algorithm cycles through the `actionset` of the entity, trying to see of any of the actions in `actionset` matches the `patternterm. This aspect of the matching algorithm has been discussed in [[Cruxdesign#Tags|the explanation of the idea of actions as tags]].
414
415 1 Shuvam Misra
### Collecting the actions from one rule
416
417
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:
418
``` json
419
"actionset": {
420
    "actions": [ "dodiscount", "yearendsale" ],
421
    "attribs": [ "shipby=fedex" ],
422
    "call": "overseaspo",
423
    "return": true,
424
    "exit": false
425 8 Shuvam Misra
}
426 1 Shuvam Misra
```
427
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.
428
429
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.
430
431
```
432
function collectActions()
433
input parameters: actionset, ruleactions
434
    returns actionset
435
436
actionset.actions = actionset.actions UNION ruleactions.actions
437
actionset.attribs = actionset.attribs UNION ruleactions.attribs
438
439
actionset.call = ""
440
actionset.return = false
441
actionset.exit = false
442
if ruleactions.call is defined, then
443
    actionset.call = ruleactions.call
444
endif
445
if ruleactions.return is defined, then
446
    actionset.return = true
447
endif
448
if ruleactions.exit is defined,  then
449 14 Shuvam Misra
    actionset.exit = true
450
endif
451 1 Shuvam Misra
452
return actionset
453
```
454
455 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.
456
457 1 Shuvam Misra
### Representing one entity
458 14 Shuvam Misra
459 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:
460
``` json
461
"inputentity": {
462 14 Shuvam Misra
    "class": "inventoryitems",
463
    "attribs": [{
464
        "name": "cat",
465
        "val": "refbook"
466
    },{
467
        "name": "mrp",
468
        "val": "1350"
469
    },{
470
        "name": "fullname",
471
        "val": "Advanced Level Physics, 2/ed"
472
    },{
473
        "name": "ageinstock",
474
        "val": "20"
475
    },{
476
        "name": "inventoryqty",
477 1 Shuvam Misra
        "val": "540"
478
    }]
479 14 Shuvam Misra
}
480 1 Shuvam Misra
```
481 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.
482
483 1 Shuvam Misra
This is the way the entity will be submitted to the matching engine for processing.
484 13 Shuvam Misra
485 27 Shuvam Misra
### `doMatch()`: the matching function
486 13 Shuvam Misra
487 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.
488
489
This engine will be implemented by the `getRules()` function, which will occasionally call itself recursively. It will be called with three parameters:
490
* an `inputentity`, which will be matched against the ruleset
491 1 Shuvam Misra
* a `ruleset` which will be traversed by the engine
492 14 Shuvam Misra
* an `actionset`, which collects the result of the action matching
493 1 Shuvam Misra
494
The pseudocode has been written with the assumption that parameters are all pass-by-value.
495
496
So, the `doMatch()` engine will work in the following way:
497 14 Shuvam Misra
```
498 1 Shuvam Misra
function doMatch()
499
input parameters: inputentity, ruleset, actionset
500 14 Shuvam Misra
    returns actionset
501
502
for each onerule in ruleset do
503 23 Shuvam Misra
    if matchOnePattern(inputentity, onerule.pattern, actionset) == true then
504 14 Shuvam Misra
        actionset = collectActions(actionset, onerule.actions)
505
        #
506
        # now check if the actions just collected includes an EXIT clause
507
        #
508
        if actionset.exit == true then
509
            return actionset
510
        endif
511
        #
512
        # If there was no EXIT clause, check if there was a RETURN clause
513
        #
514
        if actionset.return == true then
515
            actionset.return = false
516
            return actionset
517
        endif
518
        #
519
        # If there was no EXIT or RETURN, check if there was a CALL clause
520
        #
521 15 Shuvam Misra
        if actionset.call is not null then
522
            settocall = actionset.call
523
            if settocall.class != inputentity.class then
524
                log error with priority = CRITICAL:
525 14 Shuvam Misra
                       "system inconsistency with BRE rule terms, attempting to call ", settocall, " from ", ruleset, "!"
526
            endif
527
            actionset.call = null
528
            doMatch(inputentity, settocall, actionset)
529
            #
530
            # If the called ruleset has set EXIT to true, then we too need to
531
            # exit, and our caller too needs to exit, ad infinitum
532
            #
533
            if actionset.exit == true then
534
                return actionset
535
            endif
536
        endif
537
    endif
538
    #
539
    # We come here because we've done one rule and we've neither been thrown
540
    # out by an EXIT nor a RETURN clause. So we now loop to the next rule in
541
    # our ruleset.
542 13 Shuvam Misra
    #
543 14 Shuvam Misra
endfor
544 10 Shuvam Misra
545 14 Shuvam Misra
return actionset
546
```
547 1 Shuvam Misra
548 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`.
549
550
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.
551 1 Shuvam Misra
552 36 Shuvam Misra
## Operations supported by the BRE
553 1 Shuvam Misra
554 29 Shuvam Misra
The BRE must support the following set of operations:
555 32 Shuvam Misra
* Schema management:
556
  * `schemaAdd()`: add a new rule schema, for a new class
557
  * `schemaUpdate()`: update an existing schema
558
  * `schemaDelete()`: delete an existing schema
559
  * `schemaList()`: list all the schema for all classes
560
  * `schemaGet()`: get the full schema for one class, given the class name
561
* Ruleset management:
562
  * `rulesetAdd()`: add a new ruleset for a class, with one or more rules
563
  * `rulesetUpdate()`: update an existing ruleset
564
  * `rulesetDelete()`: delete a ruleset
565
  * `rulesetList()`: list all rulesets for a class
566
  * `rulesetGet()`: get the full ruleset, given the class name and the ruleset name
567
* Query the BRE and get the list of actions and attributes for an entity:
568 38 Shuvam Misra
  * `getBR()`: submit an entity and pull out the final set of actions and attributes. This call will fail unless the `inputentity` carries all the attributes listed in the schema of its class.
569 32 Shuvam Misra
  * `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()`.
570 33 Shuvam Misra
* Rule engine management:
571
  * `setConfig()`: set one or more global configuration parameters of the engine
572
  * `getConfig()`: get values of one or more global config parameters of the engine
573
  * `setAuth()`: set authorization rules to allow access to the engine
574
  * `getAuth()`: get authorization rules which control access to the engine
575
  * `shutdown()`: shut down the engine
576 36 Shuvam Misra
  * `sysReset()`: the equivalent of a factory reset. All configuration reverts to that which is present in a fresh install, all currently active processing threads are aborted and all schema, rulesets and other information is lost.
577 37 Shuvam Misra
578
The actual API specs will be on [[cruxapi|a separate page]], but the list of operations have been listed here in the typical syntax of API calls just to indicate the operations which the BRE will support. Only when we look at a complete list of operations do we see the entire scope of this system.