Re: JESS: Setting slot values using Java api
"Ernest Friedman-Hill" <[email protected]>
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <[email protected]> |
"ANY" is a slot type, not a Value type. The concept you're looking for
simply doesn't exist in Jess; you can't have a Value of unknown or
unspecified type, any more than a Java object can have unknown type. A
Java object always knows its exact class, just as a jess Value always
knows its exact type. A method like the one below should throw an
exception if the value of the "type" argument is unrecognized.
A couple of Jess programming tips: the FLOAT type is actually a Java
double, so I'd use Double.parseDouble() here (the Jess type name comes
from CLIPS). Also, you have to use the LongValue class to construct a
Value of type long, or you'll get a runtime error.
Finally, a Java tip: you can (and should) just write
else if ("STRING".equals(type))
Comparison to a boolean literal is never necessary.
On Sep 22, 2010, at 1:04 AM, Donald Winston wrote:
> When the "slotType" is "ANY" my value is "<UNKNOWN>". So the RU.ANY
> data type cannot be used this way and I have to use one of the others?
>
> ...
> fact.setSlotValue(name, getJessValue(slotType, value));
> ...
>
> private Value getJessValue(String type, String value) throws
> JessException {
> if ("ANY".equals(type) == true)
> return new Value(value, RU.ANY);
> else if ("STRING".equals(type) == true)
> return new Value(value, RU.STRING);
> else if ("INTEGER".equals(type) == true)
> return new Value(Integer.parseInt(value), RU.INTEGER);
> else if ("FLOAT".equals(type) == true)
> return new Value(Float.parseFloat(value), RU.FLOAT);
> else if ("SYMBOL".equals(type) == true)
> return new Value(value, RU.SYMBOL);
> else if ("LONG".equals(type) == true)
> return new Value(Long.parseLong(value), RU.LONG);
> else
> return new Value(value, RU.ANY);
> }
---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [email protected]'
in the BODY of a message to [email protected], NOT to the list
(use your own address!) List problems? Notify [email protected].
--------------------------------------------------------------------