自动异常处理示例

在条件中启用自动异常处理时,规则引擎将处理特定子类,以便在抛出异常后可以继续进行规则处理。 您可以通过查看示例来了解自动异常处理背后的逻辑。

使用条件中的自动异常处理,将使用以下三值逻辑来解析布尔表达式的未知值,该逻辑适用于可能导致异常的所有布尔表达式组合:

该图像包含与和,而不是运算符的三值逻辑。

简单规则条件

在以下示例中,如果借款人的状态未知,那么不会执行任何规则操作。

if
   the status of 'the borrower' starts with "duplicate"
then
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;
else 
   add "no duplicate found" to the messages of 'the loan' ;

使用 OR 运算符的规则条件

在以下示例中,如果借款人的状态未知,并且贷款的注释包含单词 duplicate,那么将拒绝贷款,并且duplicate detected发送消息。

if 
   the status of 'the borrower' starts with "Duplicate" or the comment of 'the loan' contains "duplicate"
then
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;
else 
   add "no duplicate found" to the messages of 'the loan' ;

但是,如果借款人的状态未知,并且注释未知,那么系统不会执行规则操作。 贷款未被拒绝,消息no duplicate found未添加到贷款。

使用 AND 运算符的规则条件

在以下示例中,如果借款人的状态未知,并且贷款中的注释包含单词 duplicate,那么系统既不会执行 then 部分的操作,也不会执行 else 部分的操作。 换言之,系统不会拒绝该贷款,并且不会将 no duplicate found 消息添加到该贷款的消息中。

if 
   the status of 'the borrower' starts with "duplicate" and the comment of 'the loan' contains "duplicate"
then
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;
else 
   add "no duplicate found" to the messages of 'the loan' ;

要拒绝该贷款,两个表达式都必须为 true。

If there is no ... then ...

如果 4 过去借款人的集合包含 3 个借款人 (其 where 子句为 false) 和 1 个借款人 (其借款人未知) ,那么将执行规则操作。

If there is no borrower in the past borrowers of 'the loan' where the name of this borrower is the name of 'the borrower', 
then 
add "no duplicate found" to the message of 'the loan'

If there is at least one ... then ...

如果过去的借款人集合包含 3 个借款人,对于这些借款人, where 子句在 1 案例中为 true ,在 1 案例中为 false ,而在 1 案例中为未知,那么将执行规则操作。

If there is at least one borrower in the past borrowers of 'the loan' where the name of this borrower is the name of 'the borrower', 
then 
   reject 'the loan' ;
   add "duplicate detected" to the message of 'the loan'

使用 NOT 运算符的规则条件

在以下示例中,如果状态未知并且注释不包含 duplicate,那么将执行随后的操作并no duplicate found添加到贷款的消息中。

if it is not true that
   (the status of 'the borrower' starts with "duplicate" and the comment of 'the loan' contains "duplicate")
then
   add "no duplicate found" to the messages of 'the loan' ;
else 
   reject 'the loan' ;
   add "duplicate detected" to the messages of 'the loan' ;

如果状态未知且注释包含重复项,那么不会执行任何规则操作。

决策表

在以下示例中,当列中的所有其他条件都为 false 时,将选择条件列的 otherwise 行。 或者,如果其他某个条件未知,那么不会选择 otherwise 行:

决策表示例图像。

对象集合

如果对象必须满足的测试结果未知,那么不会将此对象添加到集合中,因为只会添加测试为 true 的对象:

definitions
set 'duplicateBorrowers' to all borrowers where the status of each borrower starts with "duplicate" ; 

使用集合的表达式

在以下示例中,如果 where 子句对于三个借款人为 true ,而对于一个借款人为未知,那么规则引擎将认为条件为 true ,因为不计算 where 子句未知的借款人。 将执行 then 操作:

if  
	there are less than 3 borrowers where the name of each borrower is the name of 'the borrower',
then
   add “3 or less similar borrowers found" to the messages of 'the loan' ;
else
   reject 'the loan';
   add "more than 3 similar borrowers found" to the messages of 'the loan' ;

在以下示例中,如果 where 子句对于一个借款人为 true ,而对于两个借款人为未知,那么规则引擎会认为规则条件为 false ,因为不会对 where 子句未知的两个借款人进行计数。 将执行 else 操作:

if  
	there are more than 3 borrowers where the name of each borrower is the name of 'the borrower',
then
   reject 'the loan';
   add "3 or more similar borrowers found" to the messages of 'the loan' ;
else
   add "less than 3 similar borrowers found" to the messages of 'the loan' ;

使用包含的表达式

以下示例表达式使用 contain,这是测试集合的替代方法。 如果集合 ('duplicateBorrowers') 包含对象 'the borrower',那么条件为 true。

definitions
	set 'duplicateBorrowers' to all borrowers where the customer status of each borrower starts with "duplicate" ;
if
    'duplicateBorrowers' contain  'the borrower' 
then
add "duplicate detected" to the messages of 'the loan' ;
	reject 'the loan' ;