JESS: Newbie questions

2004-08-02 Thread Mehta, Chirag (IT)



Hi 
all,
 
I am a newbie to jess 
and have written this code:
(defrule calcifnc 
(bondMVMax (cusip ?c))
(bondMVMax (mv ?mv))
(bondMVMax (issue_outstanding 
?io&~nil))
5. (bind ?noncomp (/ ?mv ?io))
(test (> ?noncomp 10)) 
=>
(printout t ?c " is Non Complaint nc = " ?noncomp 
crlf)
)
 
At line 5, it gives me 
the following error:
Jess reported an error in routine 
Jesp.parsePattern
while executing (batch 
jessrules/bondMVMaxPCOutstandingrules.clp).
Message: Bad slot value .
Program text: ( defrule calcifnc ( bondMVMax ( 
cusip ?c ) ) ( bondMVMax ( mv ?mv ) ) ( bondMVMax ( issue_outstanding ?io & 
~~ nil ) ) ( bind ?noncomp ( at line 5.
 
I cannot seem to 
figure out what is wrong!
Also, I wish to save 
all the facts that meet the tests to a data structure and then return the data 
to my java program. What is the best method to do this??
Thanks
Chirag
 




NOTICE: If received in error, please destroy and notify sender.  Sender does not waive confidentiality or privilege, and use is prohibited.



JESS: Newbie questions

2004-08-03 Thread Mehta, Chirag (IT)
 Also,

If ?q is a negative number, how do I change it so its positive? i.e |?q|

Chirag

-Original Message-
From: Mehta, Chirag (IT) 
Sent: 03 August 2004 11:01
To: '[EMAIL PROTECTED]'
Subject: JESS: Newbie questions

I have another silly beginner question:

This is my code:

(defrule equityHedgeMaxLiquidity::calcifnc (declare (auto-focus TRUE))
(productType EQTY)
  ?b <- (Positions (quantity ?q)
(cusip ?c)
(median_22_day_volume ?m)
(liquidity ?l))
  (test (.)
  => ...

This does not work as (productType EQTY) is incorrect. 

(defrule equityHedgeMaxLiquidity::calcifnc (declare (auto-focus TRUE))
  ?b <- (Positions (quantity ?q)
(cusip ?c)
(median_22_day_volume ?m)
(liquidity ?l))
  (test (.)
  => ...

This works fine but I need for it to check the product type. 

I cannot see what is different in what I am doing compared to page 101
of JESS in Action!!

Chirag 

 
NOTICE: If received in error, please destroy and notify sender.  Sender does not waive 
confidentiality or privilege, and use is prohibited. 
 


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]




JESS: Newbie questions

2004-08-03 Thread Mehta, Chirag (IT)
I have another silly beginner question:

This is my code:

(defrule equityHedgeMaxLiquidity::calcifnc
(declare (auto-focus TRUE))
(productType EQTY)
  ?b <- (Positions (quantity ?q)
(cusip ?c)
(median_22_day_volume ?m)
(liquidity ?l))
  (test (.)
  => ...

This does not work as (productType EQTY) is incorrect. 

(defrule equityHedgeMaxLiquidity::calcifnc
(declare (auto-focus TRUE))
  ?b <- (Positions (quantity ?q)
(cusip ?c)
(median_22_day_volume ?m)
(liquidity ?l))
  (test (.)
  => ...

This works fine but I need for it to check the product type. 

I cannot see what is different in what I am doing compared to page 101
of JESS in Action!!

Chirag 

 
NOTICE: If received in error, please destroy and notify sender.  Sender does not waive 
confidentiality or privilege, and use is prohibited. 
 


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: Newbie questions

2004-08-02 Thread ejfried
I think Mehta, Chirag (IT) wrote:
> 
> I cannot seem to figure out what is wrong!

The things on the left-hand-side of a rule are always conditional
elements (patterns or groups of patterns), not function calls. Jess is
trying to interpret "(bind ?noncomp (/ ?mv ?io))" as a pattern that
matches "bind" facts, and it's complaining because (/ ?mv ?io) isn't a
valid slot value constraint.

There's no way to bind a variable on the LHS of a rule and see it on
the RHS of a rule other than by directly matching it. You're going to
have to compute (/ ?mv ?io) twice, once in the "test" CE and once on
the RHS of the rule.

I think, by the way, that you've done something else wrong here. Each
of the three bondMVMax patterns above can match a difference bondMVMax
fact. Since each one matches a different slot, I'm guessing you
actually mean for all the patterns to apply to the *same* fact; you're
not trying to find sets of three facts, but single facts that pass all
these criteria. You need to write all the criteria as one pattern:

(defrule calcifnc 
  (bondMVMax (cusip ?c) 
 (mv ?mv)
 (issue_outstanding ?io&~nil))
  (test (> (/ ?mv ?io) 10))
  =>
  (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf))


> 
> Also, I wish to save all the facts that meet the tests to a data
> structure and then return the data to my java program. What is the best
> method to do this??

You can have the rule store a reference to the fact each time it
fires; for example , in your Java code

  Rete engine = ...
  ArrayList result = new ArrayList();
  engine.store("RESULT", result);

Then make the rule look like

(defrule calcifnc 
  ?b <- (bondMVMax (cusip ?c) 
   (mv ?mv)
   (issue_outstanding ?io&~nil))
  (test (> (/ ?mv ?io) 10))
  =>
  (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf)
  ((fetch RESULT) add ?b))

After running the engine, the ArrayList "result" will contain
references to all the jess.Fact objects that match the criteria.

-
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]




RE: JESS: Newbie questions

2004-08-02 Thread Mehta, Chirag (IT)
Thanks a million. 

Any suggestions on my second question?

I need to save all the details for each fact which passes the test into
a data structure. 
This I need to pass back to my java code, which in turn can save the
results to a db.

What would be the best way of doing this?

Chirag 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: 02 August 2004 15:31
To: [EMAIL PROTECTED]
Subject: Re: JESS: Newbie questions

I think Mehta, Chirag (IT) wrote:
> 
> I cannot seem to figure out what is wrong!

The things on the left-hand-side of a rule are always conditional
elements (patterns or groups of patterns), not function calls. Jess is
trying to interpret "(bind ?noncomp (/ ?mv ?io))" as a pattern that
matches "bind" facts, and it's complaining because (/ ?mv ?io) isn't a
valid slot value constraint.

There's no way to bind a variable on the LHS of a rule and see it on the
RHS of a rule other than by directly matching it. You're going to have
to compute (/ ?mv ?io) twice, once in the "test" CE and once on the RHS
of the rule.

I think, by the way, that you've done something else wrong here. Each of
the three bondMVMax patterns above can match a difference bondMVMax
fact. Since each one matches a different slot, I'm guessing you actually
mean for all the patterns to apply to the *same* fact; you're not trying
to find sets of three facts, but single facts that pass all these
criteria. You need to write all the criteria as one pattern:

(defrule calcifnc
  (bondMVMax (cusip ?c) 
 (mv ?mv)
 (issue_outstanding ?io&~nil))
  (test (> (/ ?mv ?io) 10))
  =>
  (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf))


> 
> Also, I wish to save all the facts that meet the tests to a data
> structure and then return the data to my java program. What is the
best
> method to do this??

You can have the rule store a reference to the fact each time it
fires; for example , in your Java code

  Rete engine = ...
  ArrayList result = new ArrayList();
  engine.store("RESULT", result);

Then make the rule look like

(defrule calcifnc 
  ?b <- (bondMVMax (cusip ?c) 
   (mv ?mv)
   (issue_outstanding ?io&~nil))
  (test (> (/ ?mv ?io) 10))
  =>
  (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf)
  ((fetch RESULT) add ?b))

After running the engine, the ArrayList "result" will contain
references to all the jess.Fact objects that match the criteria.

-
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]
 

 
NOTICE: If received in error, please destroy and notify sender.  Sender does not waive 
confidentiality or privilege, and use is prohibited. 
 


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: Newbie questions

2004-08-02 Thread ejfried
I think Mehta, Chirag (IT) wrote:
> Thanks a million. 
> 
> Any suggestions on my second question?

If you scroll down to the very bottom of this message, you'll see in
the quoted part that I answered that one too.

> 
> I need to save all the details for each fact which passes the test into
> a data structure. 
> This I need to pass back to my java code, which in turn can save the
> results to a db.
> 
> What would be the best way of doing this?
> 
> Chirag 
> 
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> On Behalf Of [EMAIL PROTECTED]
> Sent: 02 August 2004 15:31
> To: [EMAIL PROTECTED]
> Subject: Re: JESS: Newbie questions
> 
> I think Mehta, Chirag (IT) wrote:
> > 
> > I cannot seem to figure out what is wrong!
> 
> The things on the left-hand-side of a rule are always conditional
> elements (patterns or groups of patterns), not function calls. Jess is
> trying to interpret "(bind ?noncomp (/ ?mv ?io))" as a pattern that
> matches "bind" facts, and it's complaining because (/ ?mv ?io) isn't a
> valid slot value constraint.
> 
> There's no way to bind a variable on the LHS of a rule and see it on the
> RHS of a rule other than by directly matching it. You're going to have
> to compute (/ ?mv ?io) twice, once in the "test" CE and once on the RHS
> of the rule.
> 
> I think, by the way, that you've done something else wrong here. Each of
> the three bondMVMax patterns above can match a difference bondMVMax
> fact. Since each one matches a different slot, I'm guessing you actually
> mean for all the patterns to apply to the *same* fact; you're not trying
> to find sets of three facts, but single facts that pass all these
> criteria. You need to write all the criteria as one pattern:
> 
> (defrule calcifnc
>   (bondMVMax (cusip ?c) 
>  (mv ?mv)
>  (issue_outstanding ?io&~nil))
>   (test (> (/ ?mv ?io) 10))
>   =>
>   (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf))
> 
> 
> > 
> > Also, I wish to save all the facts that meet the tests to a data
> > structure and then return the data to my java program. What is the
> best
> > method to do this??
> 
> You can have the rule store a reference to the fact each time it
> fires; for example , in your Java code
> 
>   Rete engine = ...
>   ArrayList result = new ArrayList();
>   engine.store("RESULT", result);
> 
> Then make the rule look like
> 
> (defrule calcifnc 
>   ?b <- (bondMVMax (cusip ?c) 
>(mv ?mv)
>(issue_outstanding ?io&~nil))
>   (test (> (/ ?mv ?io) 10))
>   =>
>   (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf)
>   ((fetch RESULT) add ?b))
> 
> After running the engine, the ArrayList "result" will contain
> references to all the jess.Fact objects that match the criteria.
> 
> -
> 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]
>  
> 
>  
> NOTICE: If received in error, please destroy and notify sender.  Sender does not 
> waive confidentiality or privilege, and use is prohibited. 
>  
> 
> 
> 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]
> 
> 



-
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]




RE: JESS: Newbie questions

2004-08-02 Thread Mehta, Chirag (IT)
Thank you ever so much.

One more quick question. In my rule I have calculated the following:

(/ ?mv ?io)

Is there anyway to save this along with the Fact reference in ?b ??

Thanks 

Chirag

 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: 02 August 2004 15:31
To: [EMAIL PROTECTED]
Subject: Re: JESS: Newbie questions

I think Mehta, Chirag (IT) wrote:
> 
> I cannot seem to figure out what is wrong!

The things on the left-hand-side of a rule are always conditional
elements (patterns or groups of patterns), not function calls. Jess is
trying to interpret "(bind ?noncomp (/ ?mv ?io))" as a pattern that
matches "bind" facts, and it's complaining because (/ ?mv ?io) isn't a
valid slot value constraint.

There's no way to bind a variable on the LHS of a rule and see it on the
RHS of a rule other than by directly matching it. You're going to have
to compute (/ ?mv ?io) twice, once in the "test" CE and once on the RHS
of the rule.

I think, by the way, that you've done something else wrong here. Each of
the three bondMVMax patterns above can match a difference bondMVMax
fact. Since each one matches a different slot, I'm guessing you actually
mean for all the patterns to apply to the *same* fact; you're not trying
to find sets of three facts, but single facts that pass all these
criteria. You need to write all the criteria as one pattern:

(defrule calcifnc
  (bondMVMax (cusip ?c) 
 (mv ?mv)
 (issue_outstanding ?io&~nil))
  (test (> (/ ?mv ?io) 10))
  =>
  (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf))


> 
> Also, I wish to save all the facts that meet the tests to a data
> structure and then return the data to my java program. What is the
best
> method to do this??

You can have the rule store a reference to the fact each time it
fires; for example , in your Java code

  Rete engine = ...
  ArrayList result = new ArrayList();
  engine.store("RESULT", result);

Then make the rule look like

(defrule calcifnc 
  ?b <- (bondMVMax (cusip ?c) 
   (mv ?mv)
   (issue_outstanding ?io&~nil))
  (test (> (/ ?mv ?io) 10))
  =>
  (printout t ?c " is Non Complaint nc = " (/ ?mv ?io) crlf)
  ((fetch RESULT) add ?b))

After running the engine, the ArrayList "result" will contain
references to all the jess.Fact objects that match the criteria.

-
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]
 

 
NOTICE: If received in error, please destroy and notify sender.  Sender does not waive 
confidentiality or privilege, and use is prohibited. 
 


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: Newbie questions

2004-08-02 Thread ejfried

I think Mehta, Chirag (IT) wrote:
> Thank you ever so much.
> 
> One more quick question. In my rule I have calculated the following:
> 
> (/ ?mv ?io)
> 
> Is there anyway to save this along with the Fact reference in ?b ??
> 

Sure -- the same way you might do it in Java, by using a little
class to represent the association. For example

  public class Holder {
public double number;
public Object fact;
public Holder(Object o, double d) {
  fact = o;
  number = d;
}
  }

Then in Jess

  (store RESULT (new Holder ?b (/ ?mv ?io)))
  



-
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]




Re: JESS: Newbie questions

2004-08-03 Thread ejfried
I think Mehta, Chirag (IT) wrote:
>  Also,
> 
> If ?q is a negative number, how do I change it so its positive? i.e |?q|
> 

Have a look at
http://herzberg.ca.sandia.gov/jess/docs/61/function_index.html, which
is a list of all the built-in functions in Jess, listed by
category. Under the "Mathematical functions" category, you'll find an
"abs" function which takes the absolute value of a number.

You might also have a look at
http://herzberg.ca.sandia.gov/jess/zen.shtml, Jason Morris' guide to
learning to work with Jess, which points out this web page and other
useful resources.




-
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]




Re: JESS: Newbie questions

2004-08-03 Thread ejfried
I think Mehta, Chirag (IT) wrote:
> 
> This does not work as (productType EQTY) is incorrect. 

Don't know what you mean by "is incorrect", but I'll guess one of two
things: first, you've written this as is there were independent
productType facts. Is this the case, or is productType a slot in the
Positions template? If so, then you need to move the whole thing
inside the Positions pattern.

The other guess is that "incorrect" just means that this never
matches; make sure that you're consistently using the same data type
everywhere. The quoted string "EQTY" and the symbol EQTY are two
different values in Jess and one won't match the other. Pick one and
be consistent.



-
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]