[rules-users] Problem with Student - module example

Dave, Rajeev Rajeev.Dave at fmr.com
Tue Aug 21 05:28:45 EDT 2007


Yes, I am inserting s1 and m1 as well. I missed it in my post.

I completely agree with your approach. However, the intent of my example
was to understand the functionality of "exists" keyword

Rgds,
rajeev

-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Anstis,
Michael (M.)
Sent: Monday, August 20, 2007 6:36 PM
To: Rules Users List
Subject: RE: [rules-users] Problem with Student - module example

I assume you also insert s1 and m1 to working memory?

What if you re-write the rule as two patterns (there is an implicit AND
between patterns)

Rule:
$student : Student()
Module( student == $student && score > 40 ) )

With kind regards,

Mike 

-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Dave, Rajeev
Sent: 20 August 2007 13:02
To: Rules Users List
Subject: [rules-users] Problem with Student - module example

Given:
Student.java
public class Student {
    private String name;
    private ArrayList modules = new ArrayList();
...
}

Module.java
public class Module {
	private String name;
    private Student student;
    private int score;
...
}

Rule:
exists( $student : Student() && Module( student == $student && score >
40 ) )

Problem statement:
I assert 2 Students and 2 modules in the session
	Student s = new Student(), s1 = new Student();
      Module m = new Module(), m1 = new Module();
      m.setName("English"); m.setStudent(s); m.setScore(10);
      s.setName("abc"); s.addModule(m);
            
      m1.setName("English1"); m1.setStudent(s1); m1.setScore(50);
      s1.setName("xyz"); s1.addModule(m1);
      
	workingMemory.insert(m);
      workingMemory.insert(s);

Result:
I  get 2 activations. I am expecting only 1 activation as only xyz
student has score > 40

Am I missing something or is this a bug?

Rgds,
rajeev


_______________________________________________
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





More information about the rules-users mailing list