J'essaie de montrer quelques messages quand une personne malade a un diagnostic. La règle pour montrer ceci est "Imprime diagnosticos" Le problème ici est que ce code ne montre aucun message d'impression ... et s'exécute en boucle infinie.Règles Drools 6.0.3 - Pourquoi ce code s'exécute-t-il en boucle infinie?
package com.sample
rule "sem sintomas 1"
salience 100
when
$p : Paciente()
forall($s : Sintomas(idPessoa != $p.getId()))
then
$p.setDiagnostico("sem sintomas definidos");
update($p);
end
rule "sem sintomas 2"
salience 90
when
$s1 : Sintomas(sintoma == "dores")
$s2 : Sintomas(sintoma == "manchas")
$p : Paciente(id == $s1.getIdPessoa(), id == $s2.getIdPessoa(), diagnostico == "")
then
$p.setDiagnostico("sem sintomas definidos");
update($p);
end
rule "gripe"
salience 60
when
$s1 : Sintomas(sintoma == "febre")
$s2 : Sintomas(sintoma == "dores")
$p : Paciente(id == $s1.getIdPessoa(), id == $s2.getIdPessoa(), diagnostico == "")
then
$p.setDiagnostico("gripe");
update($p);
end
rule "enxatema 1"
salience 80
when
$s1 : Sintomas(sintoma == "febre")
$s2 : Sintomas(sintoma == "dores")
$s3 : Sintomas(sintoma == "manchas")
$p : Paciente(id == $s1.getIdPessoa(), id == $s2.getIdPessoa(), id == $s3.getIdPessoa(), diagnostico == "", idade >= 15)
then
$p.setDiagnostico("enxatema");
update($p);
end
rule "enxatema 2"
salience 70
when
$s1 : Sintomas(sintoma == "febre")
$s2 : Sintomas(sintoma == "manchas")
$p : Paciente(id == $s1.getIdPessoa(), id == $s2.getIdPessoa(), diagnostico == "", idade < 15)
then
$p.setDiagnostico("enxatema");
update($p);
end
rule "resfriado"
salience 50
when
$s1 : Sintomas(sintoma == "febre")
$p : Paciente(id == $s1.getIdPessoa(), diagnostico == "")
then
$p.setDiagnostico("resfriado");
update($p);
end
rule "Imprime diagnosticos"
salience 40
when
$s : Sintomas()
$p : Paciente(id == $s.getIdPessoa(), diagnostico != "")
then
System.out.println("Paciente " + $p.getNome() + " com diagnóstico: " + $p.getDiagnostico());
end
Voici le programme Java insertion des faits:
package com.sample;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
public class DroolsTest {
public static final void main(String[] args) {
try {
// load up the knowledge base
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-rules");
// go !
Paciente p1 = new Paciente("001", "Ana Melo", "", 33);
Paciente p2 = new Paciente("002", "Rui Costa", "", 13);
Paciente p3 = new Paciente("003", "Joana Martins", "", 85);
Paciente p4 = new Paciente("004", "Pedro Torres","", 53);
Paciente p5 = new Paciente("005", "Ana Gomes", "", 93);
Paciente p6 = new Paciente("006", "Jorge Costa", "", 56);
Sintomas s1 = new Sintomas("001", "febre");
Sintomas s2 = new Sintomas("001", "dores");
Sintomas s3 = new Sintomas("001", "manchas");
Sintomas s4 = new Sintomas("002", "febre");
Sintomas s5 = new Sintomas("002", "manchas");
Sintomas s6 = new Sintomas("003", "febre");
Sintomas s7 = new Sintomas("003", "dores");
Sintomas s8 = new Sintomas("004", "febre");
Sintomas s9 = new Sintomas("006", "manchas");
Sintomas s10 = new Sintomas("006", "dores");
kSession.insert(p1);
kSession.insert(p2);
kSession.insert(p3);
kSession.insert(p4);
kSession.insert(p5);
kSession.insert(p6);
kSession.insert(s1);
kSession.insert(s2);
kSession.insert(s3);
kSession.insert(s4);
kSession.insert(s5);
kSession.insert(s6);
kSession.insert(s7);
kSession.insert(s8);
kSession.insert(s9);
kSession.insert(s10);
kSession.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
public class Paciente {
private String id, nome, diagnostico;
private int idade;
//...
}
public class Sintomas {
private String idPessoa, sintoma;
//...
}
Merci pour toute l'aide,
[link] (http://pastebin.com/H13Ct4GV) [link] (http://pastebin.com/VP04F0PG) –
Bienvenue sur SO. S'il vous plaît jeter un oeil à cet article utile [MCVE] sur la façon de présenter une question qui est relativement facile à aider. – roadrunner66
Ne pas utiliser les liens vers pastebin & Co. Ils disparaîtront tôt ou tard, et la question sera inutile. – laune