Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

java - Drools Rule depending on Knowledge from JDK Map (not within non-JDK Class)

I'm trying to write the below Rule, which depends on Knowledge provided in the below main that uses just a JDK [library] Map (instead of a Map within a non-library Class). But it doesn't seem to be working...

Main method:

Map<String, Float> mapa = new HashMap<String, Float>();
mapa.put("Height", (float)1.73);
mapa.put("Weight", (float)79.0);
mapa.put("BMI", mapa.get("Weight") /
                (mapa.get("Height") * mapa.get("Height")));
ksession.insert(mapa);

rule.drl:

rule "Low BMI"
    when
        $map : (Map(values("BMI")) < 18.0)
    then 
        System.out.println("You have a low BMI");
end

I want to compare the value of BMI inside of rule precondition, if this condition is true, so I want to show the message below.

What is wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should write something like:

when
    $map: Map(this["BMI"] < 18)
then

It should work :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...