首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jess:操作符小于

Jess:操作符小于
EN

Stack Overflow用户
提问于 2017-06-20 21:20:27
回答 1查看 138关注 0票数 0

当使用小于运算符的<定义规则时,我正在学习更少的内容,并且遇到了问题。这是我的defTemplates:

代码语言:javascript
复制
(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)
)

这是我的原则:

代码语言:javascript
复制
(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)))
)

但是,当我运行推理机时,我会得到下一个错误:

代码语言:javascript
复制
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

如果你能帮我,我很感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-20 21:41:36

在规则R17的右边,您可以断言

代码语言:javascript
复制
Electrocardiograma (estado APTO)

但是在此断言过程中,所有规则中对心电信号的所有约束都会被评估。这包括规则R16,在此规则下,心电信号的frecuenciaCardiaca为60。但是这个插槽还没有被设置,所以它仍然是零。因此,使用数字比较运算符<进行的比较必然会失败。

(注:不要使用59和60。使用<60和>=60要清楚得多。

如果你真的想断言另一个(!)心电图的事实,你应该至少为所有插槽提供安全的值。(更有可能的是,您希望修改心电图以保存其结果)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44663183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档