如何在 Drools 中打印不匹配的参数
How to print unmatched parameters in Drools
在下面的 Drools 文件中,我在 when 表达式中连接了两个查询,并打印了匹配的结果。
import com.demo.drools.*;
rule "demo"
when
$book: BlockTrade()
$buys : Trade(type=="buy") from $book.trades
$sells : Trade(type=="sell", $buys.id==id,
$buys.price==price,
$buys.trader==trader) from $book.trades
then
System.out.println("buys: " + $buys);
System.out.println("sells: " + $sells);
end
它工作正常,但我想记录所有不匹配原因的不匹配交易。
例如:
Trade id=1 doesn't match because $buys.type="both" doesn't match any trades in $buys or $sells
// 或
Trade id=2 doesn't match because $buys.price=50, and $buys.trader="John" doesn't match any $sells
如何实现?
参见 this other answer。如果您想记录不匹配的交易,您将需要为此创建规则。
希望对您有所帮助,
在下面的 Drools 文件中,我在 when 表达式中连接了两个查询,并打印了匹配的结果。
import com.demo.drools.*;
rule "demo"
when
$book: BlockTrade()
$buys : Trade(type=="buy") from $book.trades
$sells : Trade(type=="sell", $buys.id==id,
$buys.price==price,
$buys.trader==trader) from $book.trades
then
System.out.println("buys: " + $buys);
System.out.println("sells: " + $sells);
end
它工作正常,但我想记录所有不匹配原因的不匹配交易。
例如:
Trade id=1 doesn't match because $buys.type="both" doesn't match any trades in $buys or $sells
// 或
Trade id=2 doesn't match because $buys.price=50, and $buys.trader="John" doesn't match any $sells
如何实现?
参见 this other answer。如果您想记录不匹配的交易,您将需要为此创建规则。
希望对您有所帮助,