Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help with writing a Jess rule?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to make a simple engine based on the PricingEngine example that's packaged with Jess. It's a coach that's supposed to detect if a sailor's doing something wrong with a simulated ship. Anyway, here's my rules:

(import coach_objects.*)

(deftemplate DDGShip (declare (from-class DDGShip)))
(deftemplate Tug (declare (from-class Tug)))
(deftemplate Environs (declare (from-class Environs)))
(deftemplate Location (declare (from-class Location)))

(defrule minSpeed
(DDGShip {speed < 0.5} )
(Environs {windSpeed > 0.0 || currentSpeed > 0.0})
=>
(add (new BrokenRule "You are going too slowly; speed up so the environmentals don't catch you.")))

(defrule speedingship
(DDGShip {(speed > 0.5)})
=>
(add (new BrokenRule "You're going too fast; slow down and try to go just half a knot.")))

(defrule tugSpeedLimit
(DDGShip {speed > 3.5})
(Tug {exists > 0})
=>
(add (new BrokenRule "You're going too fast to use the tug; slow down to three knots.")))

Here is the error message I keep getting:
Jess reported an error in routine Jesp.parsePattern.
Message: No such slot exists in template MAIN::Tug at token 'exists'.
Program text: ( defrule tugSpeedLimit ( DDGShip { speed > 3.5 } ) ( Tug { exists at line 21 in file C:\Documents and Settings\jianhuan\Desktop\CoachReasoner\src\covecoach\rules.jess.
at jess.Jesp.error(Unknown Source)
at jess.Jesp.a(Unknown Source)
at jess.InfixSlotParser.a(Unknown Source)
at jess.InfixSlotParser.a(Unknown Source)
at jess.InfixSlotParser.a(Unknown Source)
at jess.InfixSlotParser.if(Unknown Source)
at jess.InfixSlotParser.if(Unknown Source)
at jess.Jesp.a(Unknown Source)
at jess.Jesp.a(Unknown Source)
at jess.Jesp.if(Unknown Source)
at jess.Jesp.parseDefrule(Unknown Source)
at jess.Jesp.parseExpression(Unknown Source)
at jess.Jesp.promptAndParseOneExpression(Unknown Source)
at jess.Jesp.parse(Unknown Source)
at jess.Batch.batch(Unknown Source)
at jess.Batch.batch(Unknown Source)
at jess.Batch.batch(Unknown Source)
at jess.Batch.batch(Unknown Source)
at jess.Rete.batch(Unknown Source)
at covecoach.CoveCoach.<init>(CoveCoach.java:23)
at samplerun.SampleRun.main(SampleRun.java:15)

If I change (Tug {exists > 0}) to (Tug {speed > 0.0}), then I don't get any error. I'm extremely puzzled since I don't treat the existence of the tug any differently from its speed at any point in the code. Thanks in advance for any help.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jane,

Welcome to JavaRanch!

The rule should work if class Tug (or one of its superclasses) has a public instance method named getExists() that takes no arguments and returns an integer type. Is there such a method?

If the method is just called "exists()" (for example), then it's not going to be treated as a JavaBeans property and you'd have to write the rule slightly differently.
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic