[rules-users] Unable to create restriction '[QualifiedIndentifierRestr: != $nissan.pos ]' for field 'pos' , in the rule 'Racing order'

Marcin Krol mrkafk at gmail.com
Wed Aug 20 13:22:18 EDT 2008


Hello everyone,

I managed to produce my first example of Drools rules. However, I am 
having problems with some field restrictions:

Racing order:Unable to create restriction '[QualifiedIndentifierRestr: 
!= $nissan.pos ]' for field 'pos' in the rule 'Racing order'

The problem is only SOME field restrictions produce this error. Other 
field restrictions don't!

If anybody has a hint or knows why this is not working, please let me 
know, I would greatly appreciate it.



The rules are:


#created on: 2008-08-20
package com.sample

#list any import classes here.

#declare any global variables here

dialect "mvel"

import com.sample.Car;

rule "Racing order"
     when

         // Porsche was not red
         $porsche : Car( manufacturer == "Porsche",
                 pos != $nissan.pos,
                 pos != $subaru.pos,
                 color != "red"
                 //color != "blue",
                 //color != $nissan.color,
                 //color != $subaru.color
                 )


		// First car was Nissan
         $nissan : Car( manufacturer == "Nissan",
          pos == 1,
          color != $subaru.color,
          color != $porsche.color )

         // Subaru was blue
         $subaru : Car( manufacturer == "Subaru",
                 //pos == 2,
                 pos != $nissan.pos,
                 pos != $porsche.pos,
                 color == "blue" )

   		// 2nd car was silver
         Car( pos == 2,
                       color == "silver",
                       this in ( $nissan, $subaru, $porsche ) )

	then
         System.out.println( "Nissan " + $nissan.getPos() + " " + 
$nissan.getColor() );
         System.out.println( "Subaru " + $subaru.getPos() + " " + 
$subaru.getColor() );
         System.out.println( "Porsche " + $porsche.getPos() + " " + 
$porsche.getColor() );

end

  	



The Car.java file:


package com.sample;

     public class Car {
     	private String manufacturer;
     	private String color;
     	private int pos;
     	
     	public Car() {
     		
     	}
     	
     	public Car(String manufacturer, String color, int pos) {
     		super();
     		this.color = color;
     		this.pos = pos;
     		this.manufacturer = manufacturer;
     	}
     	
     	public String getManufacturer() {
     		return this.manufacturer;
     	}
     	
     	public float getPos() {
     		return this.pos;
     	}
     	
     	public String getColor() {
     		return this.color;
     	}
     }




The CarExample.java file, which is the main app:



package com.sample;

import java.io.InputStreamReader;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.compiler.PackageBuilder;
import com.sample.Car;

public class CarExample {

     public static void main(String[] args) throws Exception {

         final PackageBuilder builder = new PackageBuilder();
         builder.addPackageFromDrl( new InputStreamReader( 
CarExample.class.getResourceAsStream( "CarExample.drl" ) ) );

         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
         ruleBase.addPackage( builder.getPackage() );

         final StatefulSession session = ruleBase.newStatefulSession();

         String[] names = new String[] { "Nissan", "Subaru", "Porsche"};
         String[] colors = new String[] { "red", "blue", "silver"};
         int[] positions = new int[] { 1, 2, 3 };

         for ( int n = 0; n < names.length; n++ ) {
             for ( int c = 0; c < colors.length; c++ ) {
                 for ( int p = 0; p < positions.length; p++ ) {
                     session.insert( new Car( names[n], colors[c], 
positions[p]) );
                 }
             }
         }

         session.fireAllRules();
         session.dispose();
     }



}




More information about the rules-users mailing list