我正在尝试编写一条简单的规则,根据提供的症状来确定患者患感冒的可能性。每当提供的症状之一与感冒中出现的症状匹配时,它都会通过将初始0加1来检查感冒的所有可能症状。最后,将总值除以可能的感冒症状的总数。这是我第一次编写规则,因此,如果您认为我应该以不同的方式制定规则,那么我也会提出任何建议。
rule "Cold check"
when
$p: DoctorsAppointment() and //doctor's appointment which contains symptoms (symptoms are modelled as enumeration) that patient has
$b: HashMap(String, Double) //hashmap which contains all diseases in the form key="disease name", value=0.0 initially.
then
for(Symptom s : $p.getSymptoms()) {
if(s==Symptom.RUNNING_NOSE) {
$b.put("cold", ((Double) $b.get("cold")) + 1.0);
}
else if(s==Symptom.SORE_THROAT) {
$b.put("cold", ((Double) $b.get("cold")) + 1.0);
}
else if(s==Symptom.HEADACHE) {
$b.put("cold", ((Double) $b.get("cold")) + 1.0);
}
else if(s==Symptom.SNEEZING) {
$b.put("cold", ((Double) $b.get("cold")) + 1.0);
}
else if(s==Symptom.COUGHING) {
$b.put("cold", ((Double) $b.get("cold")) + 1.0);
}
}
$b.put("cold", ((Double) $b.get("cold"))/6);
end
我收到以下错误:
[dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: Error evaluating constraint 'String' in [Rule "Cold check" in drules.drl]] with root cause
java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.Boolean