JESS: Correct Way to insert fact

2005-03-29 Thread Joe
Hello, I'm trying to assert a new fact from Java. I
have an engine and I use this function.

public static void addCourse(String prefix,String
number,Rete engine) throws JessException{
Fact course = new Fact("add",engine);
course.setSlotValue("__data",new Value(new
ValueVector().
add(new Value(prefix,RU.ATOM)).
add(new Value(number,RU.ATOM)),RU.LIST));
engine.assertFact(course);

}


I then use a rule to take this fact (add whatever
whatevr) and modify an existing unordered fact.



(defrule Add_a_Course
?newcourse<-(add ?prefix ?number) ; If we wish to
add a course to the ones taken
?existing<-(course (prefix ?prefix)(number
?number)) ; we first find it in the catalog
=>
(assert (DEBUG_MESSAGE "Found Course: ?prefix
?number in catalog."))
(modify ?existing (taken yes)) ; and modify the
existing course to say we have taken it
(retract ?newcourse)
)


My template looks like this:

(deftemplate course
(slot prefix (default UNDEFINED))
(slot number (default UNDEFINED))
(slot Description (default "UNDEFINED"))
(slot credithours (default 0))
(slot classhours (default 0))
(slot labhours (default 0))
(slot college (default UNDEFINED))
(slot department (default UNDEFINED))
(slot taken (default no)))

and here are two examples:

(course
(prefix MAC)
(number 2311)
(credithours 4)
(classhours 4)
(labhours 0)
(college AS)
(department MATH)
(Description "Calculus with Analytic Geometry
I"))

(course
(prefix MAC)
(number 2311H)
(credithours 4)
(classhours 4)
(labhours 0)
(college AS)
(department MATH)
(Description "Calculus with Analytic Geometry
I (Honors)"))

My Problem is that when the course number contains
just numbers, the rule does not work,even though the
course is in the factbase. But when the course number
has a letter after it (ex. MAC2311H) it works fine. Is
there sime way to make Jess treat all number slots as
SYMBOLS and not integers?

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.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]




Re: JESS: Correct Way to insert fact

2005-03-30 Thread ejfried
I think Joe wrote:

> 
> My Problem is that when the course number contains
> just numbers, the rule does not work,even though the
> course is in the factbase. But when the course number
> has a letter after it (ex. MAC2311H) it works fine. Is
> there sime way to make Jess treat all number slots as
> SYMBOLS and not integers?

Not symbols, no, but strings. Change your Java code to use RU.STRING
instead of RU.ATOM, and use double quotes whenever you write a literal
number that you'd like to be interpreted as a string.


-
Ernest Friedman-Hill  
Advanced Software Research  Phone: (925) 294-2154
Sandia National LabsFAX:   (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov


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]