To add to Wolfgangs response, you are missing

public static final int HIGHROADS = 4
in the Assignment class, also since you are updating Assignment in the rule actions you should either put NO-LOOP on each of the rules, or you could use a "trick" to set "lock-on-active" on a package level (see uploaded xls). With the also uploaded test, the results I am getting are:
*****
Knowledgebase read
All rules fired
Status: 0
Message: Heavy snow and cold. Medium clearance on main roads
*****
and you can also see the generated DRL (using SpreadsheetCompiler). Checking the generated DRL of your decision table is useful for debugging in the future.

Hope this helps ;)

Thanks.
Tihomir

On 12/27/10 10:13 AM, Wolfgang Laun wrote:
Hi Frank

Join C8:F8 and change the contents to
   a:Assignment() and w:Weather
all conditions deal with Weather - they'll be inserted into the last pair of parentheses that will be added to Weather. (The "and" is redundant as it is implied for patterns at the outermost level. There should be a single Assignment fact, and I guess there is only one Weather.)

I would not add an update(a) to each individual action; another ACTION column with $param; in row nine and "update(a)" in all rows below lets you remove the repeated "update(a)" from H9:J9. (But this is, perhaps, a matter of taste.)

Cheers
Wolfgang

PS: Regretfully, this set of rules is going to be late for this winter ;-)



On 27 December 2010 10:23, FrankVhh <[email protected] <mailto:[email protected]>> wrote:


    Hi all,

    I am a brand new user of the Drools-tools and am not quite
    comfortable with
    the tools yet. The current problem I am having, is caused by an
    "Unknown
    parsing error" in a decision table.

    >From past experience, I guess I have made a syntax error
    somewhere in the
    file. However, I am not able to detect the error myself. Probably
    it is a
    quite simple mistake, caused by a combination of inexperience and
    neglectance :-).

    I figured I could use an extra pair of eyes and was hoping that some
    friendly community member could help me out on this.

    I will annex the table as well as the java code that contains the java
    classes (the table isn't callad from the code yet).
    
http://drools-java-rules-engine.46999.n3.nabble.com/file/n2150980/strooidiensten.java
    strooidiensten.java
    
http://drools-java-rules-engine.46999.n3.nabble.com/file/n2150980/clearance.xls
    clearance.xls

    Thank you very much in advance!

    Kind regards,

    Frank
    --
    View this message in context:
    
http://drools-java-rules-engine.46999.n3.nabble.com/Decision-Table-tp2150980p2150980.html
    Sent from the Drools - User mailing list archive at Nabble.com.
    _______________________________________________
    rules-users mailing list
    [email protected] <mailto:[email protected]>
    https://lists.jboss.org/mailman/listinfo/rules-users



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

Attachment: clearance.xls
Description: MS-Excel spreadsheet

package com.sample;

import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.DecisionTableConfiguration;
import org.drools.builder.DecisionTableInputType;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.decisiontable.InputType;
import org.drools.decisiontable.SpreadsheetCompiler;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;




public class ClearanceTest {
    public static final void main(String[] args) {
        try {
            // load up the knowledge base
            KnowledgeBase kbase = readKnowledgeBase();
            System.out.println("Knowledgebase read");
            StatefulKnowledgeSession ksession = 
kbase.newStatefulKnowledgeSession();
            //KnowledgeRuntimeLogger logger = 
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
            // go !
            Weather weather = new Weather();
            weather.setTemperature(-3);
            weather.setPrecipitation(Weather.SNOW);
            weather.setIntensity(Weather.HEAVY);
            Assignment assignment = new Assignment();
            ksession.insert(weather);
            ksession.insert(assignment);
            ksession.fireAllRules();
            System.out.println("All rules fired");
            //logger.close();
            System.out.println("Status: " + assignment.status);
            System.out.println("Message: " + assignment.message);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

    private static KnowledgeBase readKnowledgeBase() throws Exception {
        
        SpreadsheetCompiler sc = new SpreadsheetCompiler();
        String drlstr = sc.compile( 
ResourceFactory.newClassPathResource("clearance.xls").getInputStream() , 
InputType.XLS);
        System.out.println("****\n" + drlstr + "\n*****");
        
        KnowledgeBuilder kbuilder = 
KnowledgeBuilderFactory.newKnowledgeBuilder();
        DecisionTableConfiguration dtableconfiguration = 
KnowledgeBuilderFactory.newDecisionTableConfiguration();
        dtableconfiguration.setInputType( DecisionTableInputType.XLS );
        
        kbuilder.add(ResourceFactory.newClassPathResource("clearance.xls"), 
ResourceType.DTABLE, dtableconfiguration);
        
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        if (errors.size() > 0) {
            for (KnowledgeBuilderError error: errors) {
                System.err.println(error);
            }
            throw new IllegalArgumentException("Could not parse knowledge.");
        }
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
        
        return kbase;
    }

    public static class Assignment {
        
        public static final int INACTIVE = 0;
        public static final int ACTIVE = 1;
        
        public static final int ALL = 0;
        public static final int MAINROADSANDCITYCENTERS = 1;
        public static final int MAINROADS = 2;
        public static final int HIGHWAYS = 3;
        public static final int HIGHROADS = 4;
        
        public static final int PREVENTIVE = 0;
        public static final int MEDIUM = 1;
        public static final int INTENSIVE = 2;

        private String message;
        private int status = INACTIVE;
        private int level;
        private int intensity;
        private int vehicleCount;

        public String getMessage() {
            return this.message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public int getStatus() {
            return this.status;
        }

        public void setStatus(int status) {
            this.status = status;
        }
        
        public int getLevel() {
            return this.level;
        }
        
        public void setLevel(int level) {
            this.level = level;
        }
        
        public int getIntensity() {
            return this.intensity;
        }
        
        public void setIntensity(int level) {
            this.intensity = level;
        }
        public int getVehicleCount() {
            return this.vehicleCount;
        }
        
        public void setVehicleCount(int vehicleCount) {
            this.vehicleCount = vehicleCount;
        }
        
    }
    
public static class Weather {
        
        public static final int CLEAR = 0;
        public static final int RAIN = 1;
        public static final int SNOW = 2;
        
        public static final int NONE = 0;
        public static final int LIGHT = 1;
        public static final int MEDIUM = 2;
        public static final int HEAVY = 3;

        private String message;
        private double temperature;
        private int precipitation;
        private int intensity;

        public String getMessage() {
            return this.message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public double getTemperature() {
            return this.temperature;
        }

        public void setTemperature(double temp) {
            this.temperature = temp;
        }
        
        public int getPrecipitation() {
            return this.precipitation;
        }
        
        public void setPrecipitation(int precipitation) {
            this.precipitation = precipitation;
        }
        
        public int getIntensity() {
            return this.intensity;
        }
        
        public void setIntensity(int level) {
            this.intensity = level;
        }
                
    }

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

Reply via email to