The Python Semantic Module is available through the Drools Rule Language (DRL)
by binding the namespace of http://drools.org/semantics/python
to
either the default namespace or a specific prefix. Typically it is bound to
the python
prefix.
<rule-set xmlns:python="http://drools.org/semantics/python"
...>
The <python:class>
tag provides access to the
ClassObjectType
object-type differentiator based upon the Java class hierarchy.
The fully-qualified name of the class or interface to match is provided as the content of the tag.
<python:class>com.mycompany.Person</python:class>
The <python:condition>
tag provides access to
the ExprCondition
condition based upon Python boolean expressions.
An expression that yields a boolean result is the content
of the tag. Currently logical-or (||
) expressions
are disallowed. Since valid python expressions may use the
characters <
and >
, these
characters must be escaped using their character entities,
<
and >
, respectively.
<python:condition>employee.getSlackRatio() > 0.25</python:condition>
The <python:consequence>
tag provides access to the
BlockConsequence
consequence based upon a list of Python statements.
A Python statement block is the content of the tag. The block is
eventually interpreted by Jython.
All fact objects are available
within the consequence as is a special variable, appData
,
which is the application data object provided through the working-memory.
Three global functions are also available with the consequence:
assertObject(Object object)
modifyObject(Object object)
modifyObject(Object oldObject, newObject)
retractObject(Object object)
<python:consequence>
ChipperShredder.accept( employee )
modifyObject( employee );
</python:consequence>