2016-03-02 75 views
0

我有以下類爲內滴料類變量條件檢查規則不工作

public class SeniorClass { 

    List<Students> stud; 
    String highScorerMath; 
    String highScorerChemistry; 
    String highScorerPhysics; 
    String highScorerEnglish; 
    int studentPassCount=2; 

    public String getHighScorerMath() { 
     return highScorerMath; 
    } 

    public void setHighScorerMath(String highScorerMath) { 
     this.highScorerMath = highScorerMath; 
    } 

    public String getHighScorerChemistry() { 
     return highScorerChemistry; 
    } 

    public void setHighScorerChemistry(String highScorerChemistry) { 
     this.highScorerChemistry = highScorerChemistry; 
    } 

    public String getHighScorerPhysics() { 
     return highScorerPhysics; 
    } 

    public void setHighScorerPhysics(String highScorerPhysics) { 
     this.highScorerPhysics = highScorerPhysics; 
    } 

    public String getHighScorerEnglish() { 
     return highScorerEnglish; 
    } 

    public void setHighScorerEnglish(String highScorerEnglish) { 
     this.highScorerEnglish = highScorerEnglish; 
    } 

    public int getStudentPassCount() { 
     return studentPassCount; 
    } 

    public void setStudentPassCount(int studentPassCount) { 
     this.studentPassCount = studentPassCount; 
    } 

    public List<Students> getStud() { 
     return stud; 
    } 

    public void setStud(List<Students> stud) { 
     this.stud = stud; 
    } 


} 

當我將與此相關的類到Drools的會議和消防規則的數據。以下規則似乎不起作用。

rule "Students passed count" 
lock-on-active true 
dialect "mvel" 
dialect "java" 
salience 0 
when 
     $sc : SeniorClass(studentPassCount > 0);   
then 
     System.out.println(" Rule 6: Total no. of Students passed are: " + $sc.getStudentPassCount()); 
end 

我不知道爲什麼我的「studentPassCount> 0」條件檢查沒有,即使在課堂上我已經將這個變量的值2.任何人都可以建議我這種情況的解決方案來爲真。

回答

1

您是否將SeniorClass類的事實插入工作記憶中?

你確定沒有調用setStudentPassCount值爲< = 0嗎?

在規則庫中是否有其他規則將鎖定活動設置爲true? 我強烈建議你不要使用這個屬性,除非沒有別的辦法。

確定您的規則在語法上是正確的,以便規則庫包含此規則(和其他規則)?

你打電話給fireAllRules了嗎? (您是否注意到其他規則觸發?)

爲什麼您使用矛盾的規則屬性值dialect堅持其中之一。

+0

是的,我已將SeniorClass插入工作記憶中,因爲我的其他規則工作正常。 studentPassCount將始終有值0或更大。 是的,還有其他規則鎖定活動爲真 是的,它們在語法上是正確的,因爲我沒有得到任何異常。 是的,我已經調用fireAllRules。 我只用兩種方言來實現兩者的功能。 – gomzee

+0

屬於一組規則的屬性鎖定活動可能會禁止此規則觸發。 - 您無法使用方言來達到使用這兩種功能的目的;它是 - 或者。 - 無論如何,從代碼和答案中不可能發現真正出錯的地方。請編輯您的問題並提供創建會話和插入事實的代碼。或者,檢查問題是否只存在於此規則中,或顯示所有規則。簡而言之:所有代碼重現問題,並確保陳述Drools版本。 – laune

+0

你可以在這裏找到我的代碼:https://github.com/gomzeegautam/sg-usersearch/tree/master/sg-usersearch和我正在使用Drools:5.3 – gomzee