rule help

6 messages Options
Embed this post
Permalink
SzA84

rule help

Reply Threaded More More options
Print post
Permalink
Hi I am working on a simple drools project.
I have now one rule, but it not works.

This is the drl:

package orvosi;
import orvosi.orvosimeres.Adattipus;
import orvosi.orvosimeres.Mertadat;

rule "Your First Rule"
       
        when
                Adattipus(ertek="heart_rate");
                Mertadat(ertek>180, mertekegyseg=="/min",
                mozgas==true);
        then
                System.out.println ("riasztas");
               
end

And this is the orvosi.java in the package but I think it's not good so.
Suggest me any ideas how I can make it work.
Thx!

package orvosi;

import java.io.InputStreamReader;
import java.io.Reader;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;


public class orvosimeres {
       
       
        public static final void main(String[] args) {
        try {
 RuleBase ruleBase = readRule();
            WorkingMemory workingMemory = ruleBase.newStatefulSession();
            Adattipus ertek = new Adattipus();
            Mertadat mertekegyseg = new Mertadat ();
            Mertadat mozgas = new Mertadat ();
            workingMemory.insert( ertek );
            workingMemory.insert( mertekegyseg );
            workingMemory.insert( mozgas );
            workingMemory.fireAllRules();  
} catch (Throwable t) {
            t.printStackTrace();
        }
    }
       
        private static RuleBase readRule() throws Exception {
                Reader source = new InputStreamReader( orvosimeres.class.getResourceAsStream( "/vernyomas.drl" ) );
               
       
                PackageBuilder builder = new PackageBuilder();

                builder.addPackageFromDrl( source );
               
                Package pkg = builder.getPackage();
               
                RuleBase ruleBase = RuleBaseFactory.newRuleBase();
                ruleBase.addPackage( pkg );
                return ruleBase;
        }
       
        public static class Adattipus{
                public int ertek;
        }
        public static class Mertadat{
                public int mertekegyseg;
                boolean mozgas=false;
                }
       

}
nestabur

Re: rule help

Reply Threaded More More options
Print post
Permalink
Hi,

As first look you must add the getters and setters methods into the model classes "Adattipus" and "Mertadat". In your rule you have written "Mertadat(ertek>180, mertekegyseg=="/min",mozgas==true);" but you dont have declared the field "ertek" in the class "Mertadat". And have also care with the field types, if you declare               
               public int mertekegyseg;
               boolean mozgas=false;
you can't write a precedence like
               Mertadat(ertek>180, mertekegyseg=="/min",  mozgas==true);

Hope to help,

Nestor

2009/11/8 SzA84 <[hidden email]>

Hi I am working on a simple drools project.
I have now one rule, but it not works.

This is the drl:

package orvosi;
import orvosi.orvosimeres.Adattipus;
import orvosi.orvosimeres.Mertadat;

rule "Your First Rule"

       when
               Adattipus(ertek="heart_rate");
               Mertadat(ertek>180, mertekegyseg=="/min",
               mozgas==true);
       then
               System.out.println ("riasztas");

end

And this is the orvosi.java in the package but I think it's not good so.
Suggest me any ideas how I can make it work.
Thx!

package orvosi;

import java.io.InputStreamReader;
import java.io.Reader;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;


public class orvosimeres {


       public static final void main(String[] args) {
       try {
 RuleBase ruleBase = readRule();
           WorkingMemory workingMemory =               ruleBase.newStatefulSession();
           Adattipus ertek = new Adattipus();
           Mertadat mertekegyseg = new Mertadat ();
           Mertadat mozgas = new Mertadat ();
           workingMemory.insert( ertek );
           workingMemory.insert( mertekegyseg );
           workingMemory.insert( mozgas );
           workingMemory.fireAllRules();
} catch (Throwable t) {
           t.printStackTrace();
       }
   }

       private static RuleBase readRule() throws Exception {
               Reader source = new InputStreamReader(
orvosimeres.class.getResourceAsStream( "/vernyomas.drl" ) );


               PackageBuilder builder = new PackageBuilder();

               builder.addPackageFromDrl( source );

               Package pkg = builder.getPackage();

               RuleBase ruleBase = RuleBaseFactory.newRuleBase();
               ruleBase.addPackage( pkg );
               return ruleBase;
       }

       public static class Adattipus{
               public int ertek;
       }
       public static class Mertadat{
               public int mertekegyseg;
               boolean mozgas=false;
               }


}
--
View this message in context: http://old.nabble.com/rule-help-tp26245649p26245649.html
Sent from the drools - user mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Wolfgang Laun-2

Re: rule help

Reply Threaded More More options
Print post
Permalink
In reply to this post by SzA84
In addition to what Nestor has said, you'll also have to make sure your inserted facts objects contain values. You are just calling the default constructors
           Adattipus ertek = new Adattipus();
           Mertadat mertekegyseg = new Mertadat ();
           Mertadat mozgas = new Mertadat ();
           workingMemory.insert( ertek );
           workingMemory.insert( mertekegyseg );
           workingMemory.insert( mozgas );
for Adattipus and Mertadat.

Also, it seems that you are confusing your Mertadat fields "mertekegyseg" and "mozgas" with objects of the same name.

Minden jót!
-W

On Sun, Nov 8, 2009 at 12:16 PM, SzA84 <[hidden email]> wrote:

Hi I am working on a simple drools project.
I have now one rule, but it not works.

This is the drl:

package orvosi;
import orvosi.orvosimeres.Adattipus;
import orvosi.orvosimeres.Mertadat;

rule "Your First Rule"

       when
               Adattipus(ertek="heart_rate");
               Mertadat(ertek>180, mertekegyseg=="/min",
               mozgas==true);
       then
               System.out.println ("riasztas");

end

And this is the orvosi.java in the package but I think it's not good so.
Suggest me any ideas how I can make it work.
Thx!

package orvosi;

import java.io.InputStreamReader;
import java.io.Reader;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;


public class orvosimeres {


       public static final void main(String[] args) {
       try {
 RuleBase ruleBase = readRule();
           WorkingMemory workingMemory =               ruleBase.newStatefulSession();
           Adattipus ertek = new Adattipus();
           Mertadat mertekegyseg = new Mertadat ();
           Mertadat mozgas = new Mertadat ();
           workingMemory.insert( ertek );
           workingMemory.insert( mertekegyseg );
           workingMemory.insert( mozgas );
           workingMemory.fireAllRules();
} catch (Throwable t) {
           t.printStackTrace();
       }
   }

       private static RuleBase readRule() throws Exception {
               Reader source = new InputStreamReader(
orvosimeres.class.getResourceAsStream( "/vernyomas.drl" ) );


               PackageBuilder builder = new PackageBuilder();

               builder.addPackageFromDrl( source );

               Package pkg = builder.getPackage();

               RuleBase ruleBase = RuleBaseFactory.newRuleBase();
               ruleBase.addPackage( pkg );
               return ruleBase;
       }

       public static class Adattipus{
               public int ertek;
       }
       public static class Mertadat{
               public int mertekegyseg;
               boolean mozgas=false;
               }


}
--
View this message in context: http://old.nabble.com/rule-help-tp26245649p26245649.html
Sent from the drools - user mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
SzA84

Re: rule help

Reply Threaded More More options
Print post
Permalink
In reply to this post by SzA84
Thx!
Jane James

Guvnor 5.1.0M1 bug?

Reply Threaded More More options
Print post
Permalink
I downloaded the Guvnor 5.1.0M1 version, but then I found out I found out I can't add more than one condition to it now. there used to be a little bracket between two conditions but now it's gone. Is it a bug or it's a feature? How am I supposed to say startDate > 11/11/2009 and start date < 11/30/2009 now?

thanks



     
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Jane James

Re: Guvnor 5.1.0M1 bug?

Reply Threaded More More options
Print post
Permalink
To make myself clear, here is the difference I copy and paste in a picture.



----- Original Message ----
From: Jane James <[hidden email]>
To: Rules Users List <[hidden email]>
Sent: Tue, November 10, 2009 5:30:25 PM
Subject: [rules-users] Guvnor 5.1.0M1 bug?

I downloaded the Guvnor 5.1.0M1 version, but then I found out I found out I can't add more than one condition to it now. there used to be a little bracket between two conditions but now it's gone. Is it a bug or it's a feature? How am I supposed to say startDate > 11/11/2009 and start date < 11/30/2009 now?

thanks



     
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



     

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users

drools.JPG (12K) Download Attachment