我是Drools和Java的新手,我试图从护士名册示例中了解此规则的工作原理,尤其是关于$ pattern的第一部分。
rule "unwantedPatternShiftType3DaysPattern"
when
$pattern : ShiftType3DaysPattern(
$dayIndex0ShiftType : dayIndex0ShiftType,
$dayIndex1ShiftType : dayIndex1ShiftType,
$dayIndex2ShiftType : dayIndex2ShiftType
)
PatternContractLine(
pattern == $pattern, $contract : contract
)
ShiftAssignment(
shiftType == $dayIndex0ShiftType,
contract == $contract,
$employee : employee, $firstDayIndex : shiftDateDayIndex
)
ShiftAssignment(
shiftType == $dayIndex1ShiftType,
employee == $employee,
shiftDateDayIndex == ($firstDayIndex + 1)
)
ShiftAssignment(
shiftType == $dayIndex2ShiftType,
employee == $employee,
shiftDateDayIndex == ($firstDayIndex + 2)
)
then
scoreHolder.addSoftConstraintMatch(kcontext, - $pattern.getWeight());
end
特别是,流口水如何知道其中的值:dayIndex0ShiftType,dayIndex1ShiftType,dayIndex2ShiftType?它使用这些值调用ShiftType3DaysPattern类,但是如何确定这些值?
此外,当它发出此呼叫时:
ShiftType3DaysPattern (dayIndex0ShiftType, dayIndex1ShiftType, dayIndex2ShiftType)
指的是以下内容:
@XStreamAlias("ShiftType3DaysPattern")
public class ShiftType3DaysPattern extends Pattern {
private ShiftType dayIndex0ShiftType;
private ShiftType dayIndex1ShiftType;
private ShiftType dayIndex2ShiftType;
public ShiftType getDayIndex0ShiftType() {
return dayIndex0ShiftType;
}
public void setDayIndex0ShiftType(ShiftType dayIndex0ShiftType) {
this.dayIndex0ShiftType = dayIndex0ShiftType;
}
public ShiftType getDayIndex1ShiftType() {
return dayIndex1ShiftType;
}
public void setDayIndex1ShiftType(ShiftType dayIndex1ShiftType) {
this.dayIndex1ShiftType = dayIndex1ShiftType;
}
public ShiftType getDayIndex2ShiftType() {
return dayIndex2ShiftType;
}
public void setDayIndex2ShiftType(ShiftType dayIndex2ShiftType) {
this.dayIndex2ShiftType = dayIndex2ShiftType;
}
@Override
public String toString() {
return "Work pattern: " + dayIndex0ShiftType + ", " + dayIndex1ShiftType + ", " + dayIndex2ShiftType;
}
}
这是ShiftType3DaysPattern.getDayIndex0ShiftType
,ShiftType3DaysPattern.getDayIndex1ShiftType
和ShiftType3DaysPattern.getDayIndex2ShiftType
的简写吗?
如果是这种情况,那么如果xml源文件中有多个“ 3天模式”,那么ShiftType3DaysPattern如何知道要返回哪种模式?我想念什么?
此外,如果存在多个“ 3天模式”,那么流口水如何自动将此规则应用于所有这些“ 3天模式”?
答案 0 :(得分:0)
特别是,流口水如何知道其中的值:dayIndex0ShiftType,dayIndex1ShiftType,dayIndex2ShiftType?它使用这些值调用ShiftType3DaysPattern类,但是如何确定这些值?
问题事实集合中的每个ShiftType3DaysPattern都将根据此规则与when子句中的其他条件一起进行评估。因此,将评估ShiftType3DaysPattern,PatternContractLine和三个ShiftAssignments在Kie会话中可用作问题事实的每种组合。如果所有条件都匹配(因此PatternContractLine与ShiftType3DayPattern匹配,并且所有三个ShiftAssignment类型均按不需要的ShiftType3DayPattern的顺序分配,则该规则将被触发并且对分数产生负面影响。因此dayIndex0ShiftType,dayIndex1ShiftType和dayIndex2ShiftType的值将可以是问题事实集合中ShiftType3DaysPattern中设置的任何值。
这是
ShiftType3DaysPattern.getDayIndex0ShiftType
的简写,ShiftType3DaysPattern.getDayIndex1ShiftType
,以及ShiftType3DaysPattern.getDayIndex2ShiftType
?
我不确定您指的是什么,但是如果您指的是此话:
$pattern : ShiftType3DaysPattern(
$dayIndex0ShiftType : dayIndex0ShiftType,
$dayIndex1ShiftType : dayIndex1ShiftType,
$dayIndex2ShiftType : dayIndex2ShiftType
)
这只是将dayIndex0ShiftType
分配给变量$dayIndex0ShiftType
的语法,因此以后可以在规则中引用它。模式本身也已分配给变量$pattern
。美元符号本身只是一个约定。
如果是这种情况,那么如果xml源文件中有多个“ 3天模式”,那么ShiftType3DaysPattern如何知道要返回哪种模式?我想念什么?
此外,如果存在多个“ 3天模式”,那么流口水如何自动将此规则应用于所有这些“ 3天模式”?
正如我之前说的,将针对每个可用的问题事实组合评估规则,因此将对照规则的when子句中所述的其他事实评估每个ShiftType3DaysPattern。
我建议您阅读Drools文档,它将帮助您提高对Drools的基本了解。这是一本长篇小说,但值得。至少阅读User guide一章。