Python Semantic Module DRL Reference
Namespace URI

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"
          ...>
Tag Reference
<python:class>

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>
<python:condition>

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, &lt; and &gt;, respectively.

<python:condition>employee.getSlackRatio() &gt; 0.25</python:condition>
<python:extractor>
<python:consequence>

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)
    To assert a new object into the working-memory.
  • modifyObject(Object object)
    To assert a change in an existing fact in the working-memory.
  • modifyObject(Object oldObject, newObject)
    To assert a new value for an existing fact in the working-memory.
  • retractObject(Object object)
    To retract a fact from the working-memory.
<python:consequence>
  ChipperShredder.accept( employee )

  modifyObject( employee );
</python:consequence>