有谁知道有什么方法可以解决流口水循环的问题吗?
我正试图遍历一个字符串列表,以查看其中一个字符串是否与模式匹配。
def listOfStrings = ['a','a.b','a.b.c']
for(String s:listOfStrings){
if(s matches "^a.b.*$"){
return true
}
}
我根据我能找到的文档编写了以下规则,但我认为语法是不正确的
rule "Matcher"
when
TestClass : TestClass(($s matches "^a.b.*$") from listOfStrings, count($s))
then
TestClass.setResponse( "Condition is True !!" );
end
我发现很难找到关于drl语言的好文档。
我很感激任何人能给我的任何帮助
根据前面的答案,我尝试了以下几点
rule "Matcher"
when
TestClass:TestClass(String( this matches "^a.b.*$" ) from listOfStrings)
then
TestClass.setResponse( "Condition is True !!" );
end
但是,我现在收到以下错误消息:
[43,197]: unknown:43:197 Unexpected token 'this'
发布于 2010-11-01 23:50:26
我认为您误解了规则引擎的基本原理;您需要有一点不同的想法。
与其对列表进行“迭代”,还需要将列表分解为组件字符串,并将它们作为事实单独插入到工作内存中。
只有与“什么时候”条件匹配的字符串/事实才会触发规则。
您还可能希望查看全局和查询。global将允许您将服务注入工作内存以供调用,并且查询可能是从工作内存中获取匹配字符串的一种方法。
发布于 2013-01-24 09:39:09
当我使用这个drl文件作为我的项目的规则时,我使用了这个命令。
希望这对你有帮助。
package com.sample
import com.sample.HelloProcessModel;
rule "NYuser_Rule"
no-loop true
ruleflow-group "EvalLoopcondition"
when
m:HelloProcessModel(userlocation in ("NewYorkUser"), count < 4)
then
m.setLoopcondition(6);update(m);
end
rule "ChileUser_Rule"
no-loop true
ruleflow-group "EvalLoopcondition"
when
m:HelloProcessModel(userlocation in ("ChileUser"), count < 3)
then
m.setLoopcondition(5);update(m);
end
rule "BelgiumUser_Rule"
no-loop true
ruleflow-group "EvalLoopcondition"
when
m:HelloProcessModel(userlocation in ("BelgiumUser"), count < 6)
then
m.setLoopcondition(8);update(m);
end
发布于 2010-07-31 14:05:41
Rete算法不是这样工作的。
我想你想试试流淌的正则表达式。
https://stackoverflow.com/questions/3378375
复制相似问题