Skip to: Site menu | Main content

Drools

Java Rules Engine

Base Semantic Module Print

The Base Semantics Module provides a base language for building a RuleSet in XML. By itself, the base semantic module is not capable of writing a complete and valid rule file. It must be used in conjunction with other semantic modules. This can be the Java semantic module, the Groovy semantic module, the Python semantic module, or a custom, domain-specific semantic module you've written specifically for your problem domain.

Syntax Guide

rule-set element

Each DRL file must have exactly one rule-set element, which must be uniquely named in the rule base and declare the appropriate namespace bindings for semantic module lookup and schema validation; see Semantics Module Framework and Schema Validation.

attribute

optional?

description

name

no

This string must uniquely identify the rule-set in the rule base

import element

Imports can be specified which are then available to any element that references a Class.

attribute

optional?

description

The body of the element can be either a fully qualified import :

Or a dynamic on demand import:

application-data element

Application Data elements allow objects to be made available to conditions and consequences without the need to assert them into the Working Memory.

attribute

optional?

description

identifier

no

This string must uniquely identify the application-data in the rule-set

Application data cannot be set that is not declared in the{{rule-set}} of the rule base. To set application data:

To declare application data inside a rule-set:

rule element

Each rule-set must contain at least one rule element. Each rule element must be uniquely named in the rule-set, and may contain optional salience and no-loop attributes. no-loop is currently ignored if the duration element is specified.

attribute

optional?

description

name

no

This string must uniquely identify the rule in the rule-set.

salience

yes

Default to 0. Must be numeric, integral, signed. Must be numeric, non-float values, can be negative. Example: salience="-42", salience="2".

no-loop

yes

Default to "false". Must be boolean. Example: no-loop="true", no-loop="false".

xor-group

yes

Allow only a single rule within a group to fire, all other rules in that group are then removed from the agenda. A rule can be in only a single xor group.

parameter element

Each rule element must contain at least one parameter element, which must use a unique name for the identifer attribute within the rule scope. By itself, the parameter element can do nothing. It requires a nested element representing an ObjectType, like class, class-field and semaphore object (or one from your own semantic module).

attribute

optional?

description

identifier

no

This string must uniquely identify the parameter in the rule

class element

The class element is an ObjectType implementation to be used inside a parameter element. It has no attributes and its contents is either a fully qualified class or a class name available from a previously imported package.

attribute

optional?

description

class-field element

The class-field element is an ObjectType implementation to be used inside a parameter element. It not only constrains the parameter to a Class, like the class element, but it also constrains to a given value for the specified field. The field is limited to String types and the value is also a static String.

attribute

optional?

description

field

no

The name of the field of the type String, written to JavaBean specifications with setters and getters

value

no

Static value constraint for the given field

This is akin to saying:

semaphore element

The semaphore element is a specialised ObjectType implementation to be used inside a parameter element. It provides global named variables, where the identifier is the global name, for use within rules; this can be useful for control execution.

attribute

optional?

description

type

no

The type of semaphore

To assert a semaphore without an initial value:

To assert a semaphore with an initial value:

To specify a semaphore within a parameter

The following supported semaphore types are:

  • CharSemaphore
  • DoubleSemaphore
  • FloatSemaphore
  • IntegerSemaphore
  • ListSemaphore
  • LongSemaphore
  • MapSemaphore
  • SetSemaphore
  • ShortSemaphore
  • StringSemaphore

duration element

The duration element enables Temporal Rules where Activations fire after a given time if they are still true. A duration can have can have one or more unit of time, but must specify atleast one. no-loop is currently ignored if the duration element is specified.

attribute

optional?

description

seconds

yes

Unit of time

minutes

yes

Unit of time

hours

yes

Unit of time

days

yes

Unit of time