问题描述
给定一个配置类Config,其中包含属性excludeShifts(这是Shift类的列表),是否存在像“ this”这样的关键字表示匹配过程中的当前对象?例如,
rule "Match but not if excluded"
when
$config : Config(...) // additional matching criteria deleted
$shift : Shift(this not memberOf $config.excludeShifts,... // additional criteria deleted
)
... // additional criteria deleted
then
...
end
我认识到在功能上,我可以使用以下命令来实现此匹配:
$shift : Shift()
$config : Config(excludeShifts not contains $shift
)
解决方法
this
是一个公认的关键字,其使用方式与您指示的方式相同,用作对要评估的当前对象的引用。
一些例子:
// An even integer in working memory
$even: Integer( this % 2 == 0 )
// A string with a specific value
$animal: String(this in ("cat","dog","fish"))
// A value from a map
Map( $value: this['key'] )
您的示例与您编写的示例一样有效。
rule "Match but not if excluded"
when
$config : Config($excluded: excludedShifts)
$shift : Shift(this not memberOf $excluded)
then
end
我拨通了documentation,但看不到是否曾经this
被用作关键字(尽管要搜索它有点困难。)在一些示例中使用了它。 ,例如,在forall
运算符示例代码中。正如Esteban在评论中所建议的那样,欢迎您打开错误报告或提交文档修订以纠正这种疏忽。