我创建了一个简单的Drools项目。 一切正常,除了我的规则执行两次而不是一次。
请检查我的规则:
library(dplyr)
# calculate x-axis position for bars of varying width
gr <- gr %>%
group_by(drug) %>%
arrange(practice) %>%
mutate(pos = 0.5 * (cumsum(prop) + cumsum(c(0, prop[-length(prop)])))) %>%
ungroup()
x.labels <- gr$practice[gr$drug == "a"]
x.pos <- gr$pos[gr$drug == "a"]
ggplot(gr,
aes(x = pos, y = prevalence,
fill = country, width = prop,
ymin = low.CI, ymax = high.CI)) +
geom_col(col = "black") +
geom_errorbar(size = 0.25, colour = "black") +
facet_wrap(~drug) +
scale_fill_manual(values = c("c1" = "gray79",
"c2" = "gray60",
"c3" = "gray39"),
guide = F) +
scale_x_continuous(name = "Drug",
labels = x.labels,
breaks = x.pos) +
labs(title = "Drug usage by country and practice", y = "Prevalence") +
theme_classic()
请检查代码:
package rules
rule "age and type match"
when
$droolsIntro : rules.DroolsInstruction( type == "Manager" ) && rules.DroolsInstruction( age >= 20 )
then
System.out.println("age and type match");
System.out.println($droolsIntro.introduceYourself());
end
这是输出,显示规则对同一个对象执行了两次:
年龄和类型匹配 经理,25岁,错误
年龄和类型匹配 经理,25岁,错误
为什么?
答案 0 :(得分:2)
此模式
DroolsInstruction( type == "Manager" )
DroolsInstruction( age >= 20 )
匹配实体&#34;经理&#34;并且年龄≥1岁之一,但对他们的关系没有任何限制。因此,25岁的经理匹配第一个模式和第二个模式:火!但同一个经理匹配第一个模式,一个老警察匹配第二个模式:再次开火!
如果你想寻找老经理,你最好写一下
DroolsInstruction( type == "Manager", age >= 20 )
虽然是间接的(而不是推荐的)
$di1: DroolsInstruction( type == "Manager" )
$di2: DroolsInstruction( this == $di1, age >= 20 )
也可以。