2017-06-20 49 views
0

我使用小於運算符'<定義規則時,我正在學習較少並遇到問題。 這是我defTemplates:Jess:運算符錯誤小於

(deftemplate AgudezaVisual 
    (slot agudezaVisual) 
    (slot estado) 
) 

(deftemplate Bucodental 
    (slot hayDientesDañados) 
    (slot hayDientesConConcavidades) 
    (slot hayCaries) 
    (slot estadoEncias) 
    (slot presentaCancerOral) 
    (slot haySangradoOInflamacionPaladar) 
    (slot haySangradoOInflamacionLengua) 
    (slot tieneGengivitis) 
    (slot estado) 
) 

(deftemplate Respiratorio 
    (slot tieneDisnea) 
    (slot tieneTos) 
    (slot tieneEsputo) 
    (slot tieneDolorToracico) 
    (slot tieneEdema) 
    (slot tieneJadeo) 
    (slot estado) 
) 

(deftemplate Digestivo 
    (slot tieneCirrosis) 
    (slot esCeliaco) 
    (slot esDiabetico) 
    (slot tieneHepatitisB) 
    (slot tieneHepatitisC) 
    (slot estado) 
) 

(deftemplate Electrocardiograma 
    (slot frecuenciaCardiaca) 
    (slot tieneInsuficienciaCardiaca) 
    (slot tieneArritmia) 
    (slot tienePericarditis) 
    (slot tieneMiocarditis) 
    (slot estado) 
) 

(deftemplate Hemograma 
    (slot eritrocitos) 
    (slot hematocrito) 
    (slot hemoglobina) 
    (slot leucocitos) 
    (slot plaquetas) 
    (slot estado) 
) 

(deftemplate Eritrocedimentacion 
    (slot velocidad) 
    (slot posibleAnemia) 
    (slot posibleInfecciosas) 
    (slot posibleEnfermedadesInflamatorias) 
    (slot posiblesEnfermedadesReumaticas) 
    (slot estado) 
) 

(deftemplate Glucemia 
    (slot glocosa) 
    (slot estado) 
) 

(deftemplate Uremia 
    (slot urea) 
    (slot estado) 
) 

(deftemplate Orina 
    (slot leucocitos) 
    (slot cetonas) 
    (slot sangre) 
    (slot ph) 
    (slot bilirrubina) 
    (slot nitritos) 
    (slot estado) 
) 

(deftemplate RadiografiaTorax 
    (slot presentaElementosPatologicos) 
    (slot estado) 
) 

(deftemplate InformeFinalAptitud 
    (slot observaciones) 
    (slot estado) 
) 

而且這是我的規則:

(defrule R1 
    (AgudezaVisual (agudezaVisual ?a & : (> ?a 0.5))) 
    => 
    (assert (AgudezaVisual (estado APTO))) 
) 

(defrule R2 
    (AgudezaVisual (agudezaVisual ?a & : (< ?a 0.5))) 
    => 
    (assert (AgudezaVisual (estado NO_APTO))) 
) 

(defrule R3 
    (Bucodental (hayDientesDañados true)) 
    (Bucodental (hayCaries true)) 
    (Bucodental (hayDientesConConcavidades true)) 
    (Bucodental (haySangradoOInflamacionLengua true)) 
    (Bucodental (haySangradoOInflamacionPaladar true)) 
    => 
    (assert (Bucodental (estado NO_APTO))) 
) 

(defrule R4 
    (Bucodental (presentaCancerOral true)) 
    => 
    (assert (Bucodental (estado NO_APTO))) 
) 

(defrule R5 
    (Bucodental (tieneGengivitis true)) 
    => 
    (assert (Bucodental (estado APTO))) 
) 

(defrule R6 
    (Respiratorio (tieneDisnea true)) 
    (Respiratorio (tieneJadeo true)) 
    => 
    (assert (Respiratorio (estado NO_APTO))) 
) 

(defrule R7 
    (or (Respiratorio (tieneTos true)) 
    (Respiratorio (tieneJadeo true))) 
    => 
    (assert (Respiratorio (estado NO_APTO))) 
) 

(defrule R8 
    (Respiratorio (tieneTos true)) 
    (Respiratorio (tieneEsputo true)) 
    (Respiratorio (tieneDolorToracico true)) 
    => 
    (assert (Respiratorio (estado NO_APTO))) 
) 

(defrule R9 
    (Respiratorio (tieneDisnea true)) 
    (Respiratorio (tieneEdema true)) 
    => 
    (assert (Respiratorio (estado NO_APTO))) 
) 

(defrule R10 
    (Respiratorio (tieneDolorToracico true)) 
    => 
    (assert (Respiratorio (estado APTO))) 
) 

(defrule R11 
    (Digestivo (tieneCirrosis true)) 
    => 
    (assert (Digestivo (estado NO_APTO))) 
) 

(defrule R12 
    (Digestivo (esCeliaco true)) 
    => 
    (assert (Digestivo (estado APTO))) 
) 

(defrule R13 
    (Digestivo (esDiabetico true)) 
    => 
    (assert (Digestivo (estado APTO))) 
) 

(defrule R14 
    (Digestivo (tieneHepatitisB true)) 
    (Digestivo (tieneHepatitisC true)) 
    => 
    (assert (Digestivo (estado NO_APTO))) 
) 

(defrule R15 
    (Digestivo (tieneHepatitisB true)) 
    (Digestivo (esCeliaco true)) 
    => 
    (assert (Digestivo (estado NO_APTO))) 
) 

(defrule R16 
    (Electrocardiograma {frecuenciaCardiaca < 60}) 
    => 
    (assert (Electrocardiograma (estado NO_APTO))) 
) 

(defrule R17 
    (Electrocardiograma {frecuenciaCardiaca < 100}) 
    (Electrocardiograma {frecuenciaCardiaca > 59}) 
    => 
    (assert (Electrocardiograma (estado APTO))) 
) 

(defrule R18 
    (Electrocardiograma {frecuenciaCardiaca > 100}) 
    (Electrocardiograma (tieneArritmia true)) 
    => 
    (assert (Electrocardiograma (estado NO_APTO))) 
) 

(defrule R19 
    (Electrocardiograma {frecuenciaCardiaca < 60}) 
    (Electrocardiograma (tieneInsuficienciaCardiaca true)) 
    => 
    (assert (Electrocardiograma (estado NO_APTO))) 
) 

(defrule R20 
    (Electrocardiograma (tieneMiocarditis true)) 
    (Electrocardiograma (tienePericarditis true)) 
    => 
    (assert (Electrocardiograma (estado NO_APTO))) 
) 

然而,當我運行推理引擎,我得到了一個錯誤:

Exception in thread "main" Jess reported an error in routine < 
    while executing (< ?__synth0(0,0,-1) 60) 
    while executing rule LHS (TEQ) 
    while executing rule LHS (TECT) 
    while executing (assert (MAIN::Electrocardiograma (frecuenciaCardiaca nil) (tieneInsuficienciaCardiaca nil) (tieneArritmia nil) (tienePericarditis nil) (tieneMiocarditis nil) (estado APTO))) 
    while executing defrule MAIN::R17. 
    Message: compareTo threw an exception. 
    at jess.AbstractComparison.call(AbstractComparison.java:30) 
    at jess.FunctionHolder.call(FunctionHolder.java:35) 
    at jess.Funcall.execute(Funcall.java:338) 
    at jess.FuncallValue.resolveValue(FuncallValue.java:29) 
    at jess.Node1TEQ.callNodeRight(Node1TEQ.java:33) 
    at jess.Node1.passAlong(Node1.java:49) 
    at jess.Node1TECT.callNodeRight(Node1TECT.java:40) 
    at jess.NodeRoot.passAlong(NodeRoot.java:39) 
    at jess.NodeRoot.callNodeRight(NodeRoot.java:14) 
    at jess.FactList.processToken(FactList.java:31) 
    at jess.FactList._assert(FactList.java:210) 
    at jess.FactList.assertFact(FactList.java:181) 
    at jess.Rete.assertFact(Rete.java:548) 
    at jess.FactFunctions$Assert.call(FactFunctions.java:50) 
    at jess.FunctionHolder.call(FunctionHolder.java:35) 
    at jess.Funcall.execute(Funcall.java:338) 
    at jess.Defrule.fire(Defrule.java:407) 
    at jess.Activation.fire(Activation.java:98) 
    at jess.Agenda.run(Agenda.java:267) 
    at jess.Agenda.run(Agenda.java:243) 
    at jess.Rete.run(Rete.java:1829) 
    at jess.Rete.run(Rete.java:1824) 
    at Main.main(Main.java:96) 
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String 
    at java.lang.String.compareTo(String.java:111) 
    at jess.Lt.computeComparable(ArithmeticFunctions.java:165) 
    at jess.AbstractComparison.call(AbstractComparison.java:27) 
    ... 22 more 

我已經感激不盡如果你能幫助我。

回答

0

在規則R17的右手邊斷言

Electrocardiograma (estado APTO) 

,但在此斷言爲Electrocardiograma所有約束中的所有規則進行評估。這包括規則R16,在此Electrocardiograma的frecuenciaCardiaca與60比較。但此插槽尚未設置,因此它仍然爲零。因此,使用數字比較運算符<的比較必然會失敗。

(注:請不要使用59和60是更清晰的使用< 60> = 60)。

如果你真的想發出另一個Electrocardiograma事實上,你至少應該提供(!)所有插槽的安全值。 (這更可能是您要修改心電圖事實以保留結果)

+0

@asueso您還應該使用「默認」插槽限定符爲所有需要保存數字值的插槽指定數字默認值 - 即「(deftemplate AgudezaVisual(slot agudezaVisual(default 1.0)))」 –