[rules-users] rules not being reconsidered after modify

Stephen Masters stephen.masters at me.com
Fri Aug 31 05:44:26 EDT 2012


Pretty much as described by Vincent, here's a minimally tweaked version of the BMI rule (no fact model changes), which seems to execute quite happily in my little test bed...


rule "Wenn der BMI des Patienten >= 18.5 und < 25 ist, dann gehört der Patient der Kategorie 'Normalgewicht' an und hat ein 'durchschnittliches' Risiko für Begleiterkrankungen des Übergewichts"
	no-loop
	when
		MessdatenVonPatient($patient : patient && (getMessdaten().getBmi() >= 18.5) && (getMessdaten().getBmi() < 25))
		$krankheitsbildVonPatient : KrankheitsbildVonPatient(
			patient == $patient
		)
	then
		$krankheitsbildVonPatient.getKrankheitsbild().setAdipositasGrad("Normalgewicht");
		$krankheitsbildVonPatient.getKrankheitsbild().setRisikoBegleiterkrankungGrad(1);
		update($krankheitsbildVonPatient);
end


rule "Wenn Patient der Kategorie 'Normalgewicht' angehoert, dann werden folgende Maßnahmen vorgeschlagen"
	when
		KrankheitsbildVonPatient($patient : patient, krankheitsbild.adipositasGrad == "Normalgewicht")
	then
		System.out.println("Some Text");
end


rule "Insert test facts"
    	no-loop
    when
        // whenever...
    then
        Patient patient = new Patient();
        patient.setName("Frank");
        
        Messdaten messdaten = new Messdaten();
        messdaten.setBmi(19.9);
        
        MessdatenVonPatient mvp = new MessdatenVonPatient();
        mvp.setPatient(patient);
        mvp.setMessdaten(messdaten);
        insert(mvp);
        
        KrankheitsbildVonPatient kvp = new KrankheitsbildVonPatient();
        kvp.setPatient(patient);
        kvp.setKrankheitsbild(new Krankheitsbild());
        insert(kvp);
end


On 30 Aug 2012, at 17:44, Vincent LEGENDRE <vincent.legendre at eurodecision.com> wrote:

> Hi,
> 
> You must make a difference between "facts" and other objects (that you can get by "bindings"). 
> "facts" are the objects inserted in the working memory. Only those objects can be matched directly in LHS. Other entities can be accessed by using attributes (of facts) bindings or "from" constructions to get objects from "facts" fields. 
> And finally, only the "facts" can be modified/inserted/retracted, ie actions that trigger a RETE evaluation and thus new candidate rules to fire.
> 
> Here, in your first rule, your LHS is matching facts and use a binding $krankheitsbild for a field of KrankheitsbildVonPatient fact. 
> And you are modifying the binded attribute, which is not a fact. So it won't trigger RETE evaluation... To me, it should not compile, but apparently it does .... 
> 
> You can think about 2 corrections :
>    1 - make your $krankheitsbild objects real facts, ie insert them in the WM, and don't get them via attribute binding
>    2 - do the set on $krankheitsbild, then "update" your containing fact object ( with update($krankheitsbildVonPatient)  ) 
> 
> 
> here are the approximative form of the resulting rules for the 2 approaches :
> 
> ---------------1------------------- 
>  I suppose that Krankheitsbild objects are inserted independently, and your model modified like that
> declare KrankheitsbildVonPatient
> 	patient : Patient
> end
> 
> declare Krankheitsbild
>         parent : KrankheitsbildVonPatient
> 	abdominaleAdipositas : boolean
> 	adipositasGrad : String
> 	risikoBegleiterkrankungGrad : int
> 	risikoMetabolischeKardiovaskulaereKomplikationen : String
> 	metabolischesSyndrom : boolean
> end
> 
> so the rule should look like :
> 
> rule "...."
>         when
>                 MessdatenVonPatient($patient : patient && (getMessdaten().getBmi() >= 18.5) && (getMessdaten().getBmi() < 25))
>                 $krankheitsbildVonPatient : KrankheitsbildVonPatient(patient == $patient)
>                 $krankheitsbild : Krankheitsbild ( parent ==  $krankheitsbildVonPatient )
>          then
>                 modify($krankheitsbild){setAdipositasGrad("Normalgewicht"),
>                                                                 setRisikoBegleiterkrankungGrad(1)
>                                                                 }
> end
> 
> 
> 
> ---------------2------------------- 
> May be simpler, but beware of loops ...
> 
> rule "..."
>         when
>                 MessdatenVonPatient($patient : patient && (getMessdaten().getBmi() >= 18.5) && (getMessdaten().getBmi() < 25))
>                 $krankheitsbildVonPatient : KrankheitsbildVonPatient(patient == $patient && $krankheitsbild : krankheitsbild)
>         then
>                 $krankheitsbild.setAdipositasGrad("Normalgewicht");
>                 $krankheitsbild.setRisikoBegleiterkrankungGrad(1);
>                 update ( $krankheitsbildVonPatient  ) ;
> end
> 
> 
> 
> De: "wichtl" <irr4ever at gmx.net>
> À: rules-users at lists.jboss.org
> Envoyé: Jeudi 30 Août 2012 15:56:29
> Objet: [rules-users] rules not being reconsidered after modify
> 
> Hi,
> 
> I'm new to using Drools and its probably just a problem with me
> understanding how this works, but I've tried everything i can think of, so I
> come to you in hope for some help!
> 
> I have a set of rules which modify an object in the RHS and another set of
> Rules that should be fireing after the modification of the object.
> 
> Rule modifying the Object:
> 
> rule "Wenn der BMI des Patienten >= 18.5 und < 25 ist, dann gehört der
> Patient der Kategorie 'Normalgewicht' an und hat ein 'durchschnittliches'
> Risiko für Begleiterkrankungen des Übergewichts"
>         when
>                 MessdatenVonPatient($patient : patient && (getMessdaten().getBmi() >=
> 18.5) && (getMessdaten().getBmi() < 25))
>                 $krankheitsbildVonPatient : KrankheitsbildVonPatient(patient == $patient
> && $krankheitsbild : krankheitsbild)
>         then
>                 modify($krankheitsbild){setAdipositasGrad("Normalgewicht"),
>                                                                 setRisikoBegleiterkrankungGrad(1)
>                                                                 }
> end
> 
> 
> Rule that should fire after the modification:
> 
> rule "Wenn Patient der Kategorie 'Normalgewicht' angehoert, dann werden
> folgende Maßnahmen vorgeschlagen"
>         when
>                 KrankheitsbildVonPatient($patient : patient, krankheitsbild.adipositasGrad
> == "Normalgewicht")
>         then
>                 System.out.println("Some Text");
> end
> 
> 
> Also I have encountered problems (application freezes) when trying to modify
> the "$krankheitsbildVonPatient" object in the RHS. And I still don't
> understand why it did freeze and why modifying "$krankheitsbild" does not.
> 
> Heres my datamodel if needed: 
> http://drools.46999.n3.nabble.com/file/n4019463/dataModel.drl dataModel.drl
> 
> 
> Best Regards,
> 
> wichtl
> 
> 
> 
> 
> --
> View this message in context: http://drools.46999.n3.nabble.com/rules-not-being-reconsidered-after-modify-tp4019463.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120831/71e844be/attachment-0001.html 


More information about the rules-users mailing list