Drools Regensburg G2
Jump to navigation
Jump to search
Basic
EX1
rule "Select Salgrade" enabled false
when
$s : Salgrade()
then
System.out.println( $s.grade + " " + $s.losal + " " + $s.hisal)
endEX2
rule "employees who earn between 1000 and 2000" enabled true
when
e : Emp(sal >= 1000 && <= 2000)
then
System.out.println(e.id + " " + e.name + "\t" + e.job
+ " \t" + e.mgr + "\t" + e.hiredate + " " + e.sal
+ " " + e.deptno );
endEX3
rule "example 3"
when
$e : Emp(job == "CLERK" && deptno == 20)
then
System.out.println($e.id + "\t" + $e.name + "\t" + $e.job + "\t" + $e.mgr + "\t" + $e.hiredate + "\t" + $e.sal + "\t" + $e.deptno)
endEX4
rule "employees who have a boss."
enabled false
when
$e : Emp(mgr != 0)
then
System.out.println($e.id + " " + $e.name + " " + $e.job + " " + $e.mgr + " " + $e.hiredate + " " + $e.sal + " " + $e.deptno )
endEX5
rule "Exercise 5"
enabled true
when
$e : Emp(job == "MANAGER")
then
System.out.println($e.id + " " + $e.name + " " + $e.job + " " + $e.mgr + " " + $e.hiredate + " " + $e.sal * 12 + " " + $e.deptno )
endEX6
rule "Exercise 6"
enabled false
when
$e : Emp(name matches ".LA.*")
then
System.out.println($e.id + " " + $e.name + " " + $e.job + " " + $e.mgr + " " + $e.hiredate + " " + $e.sal + " " + $e.deptno )
endEX7
rule "Exercise 7"
enabled true
when
$e : Emp(name matches ".*T.*N")
then
System.out.println($e.id + " " + $e.name + " " + $e.job + " " + $e.mgr + " " + $e.hiredate + " " + $e.sal + " " + $e.deptno )
endEX8
rule "Exercise 8"
enabled false
when
$e : Emp((job == "MANAGER" && deptno !=10) || (job != "MANAGER" && deptno == 10) )
then
System.out.println($e.id + " " + $e.name + " " + $e.job + " " + $e.mgr + " " + $e.hiredate + " " + $e.sal + " " + $e.deptno )
endAdvanced
EX31
rule "Exercise 31"
enabled true
when
$d : Dept()
$e : Emp($d.deptno == deptno )
then
System.out.println($e.name + "\t" + $d.loc )
endEX32
rule "Exercise 32"
enabled false
when
e : Emp()
d: Dept(e.deptno == deptno)
then
System.out.println(e.id + " " + e.name + "\t"
+ " \t\t" + d.loc + "\t" + d.deptno );
endEX33
rule "Exercise 33"
enabled false
when
e : Emp()
s: Salgrade(e.sal >= losal, e.sal <= hisal)
then
System.out.println(e.id + " " + e.name + "\t"
+ " \t\t" + s.grade );
endEX34
rule "Exercise 34"
enabled true
when
e : Emp()
d: Dept(e.deptno == deptno, loc == "LONDON")
then
System.out.println(e.id + " " + e.name + "\t"
+ " \t\t" + d.loc );
endEX35
rule "Exercise 35"
enabled true
when
e : Emp()
d: Dept(e.deptno == deptno, loc != "LONDON")
s: Salgrade(e.sal >= losal, e.sal <= hisal)
then
System.out.println(e.id + " " + e.name + "\t" + s.grade
+ " \t\t" + d.loc );
endEX36
rule "Exercise 36"
enabled true
when
d :Dept()
not (Emp(deptno == d.deptno))
then
System.out.println( d.dname )
endEX37
rule "Exercise 37"
enabled true
when
e1 :Emp()
e2 :Emp(id == e1.mgr)
then
System.out.println( e1.name + "\t -->" + e2.name )
endEX38
rule "Exercise 38"
enabled true
when
$e : Emp()
not Emp($e.mgr == id)
then
System.out.println($e.name )
endEX39
rule "Exercise 39"
enabled true
when
$e : Emp()
not Emp($e.id == mgr)
then
System.out.println($e.name )
endEX41
rule "Exercise 41"
enabled true
when
$e : Emp()
$m : Emp($e.mgr == id && $e.hiredate < hiredate)
then
System.out.println($e.name + " (" +$e.hiredate+ ") was hired earlier than "+$m.name +"("+$m.hiredate+")" )
endrule "41. Select employees hired earlier than their bosses." enabled true
when
$emp : Emp($mgr : mgr, $empHireDate : hiredate)
$boss : Emp(id == $mgr, $empHireDate < hiredate)
then
System.out.println($emp.name + " hired in " + $empHireDate + " whose boss is " + $boss.name + " hired in " + $boss.hiredate)
endEX44
rule "Exercise 44"
enabled true
when
$e : Emp(deptno==10) && not Emp(job==$e.job && deptno==20)
then
System.out.println($e.job)
end