I think that Calvin said:
>>How can I extract these 2 facts out?

Hi Calvin,
These operations are so basic to Jess that you might want to review them in
greater detail before proceeding.  If you can get a copy of Jess In Action
http://www.manning.com/friedman-hill, study chapters 1-7 thoroughly.  There
are numerous examples of how to do this very thing.  If not, go to
http://herzberg.ca.sandia.gov/jess/docs/61/ and look at Section 2:
http://herzberg.ca.sandia.gov/jess/docs/61/language.html, sub sections 2.7
and 2.8 in particular.

If you're really unsure about the number of attributes at the time that you
assert the fact, consider using "unordered" facts - facts with slots - to
store your data.  One variation (and there are so many ways to do this)
might be a generic "attributes" fact like this:

  (deftemplate adv-attributes
  (slot id)
  (multislot attribs))

Then you can assert facts like:

  (assert (adv-attributes (id 1) (attribs radio-advertisement low-budget)))
  (assert (adv-attributes (id 2) (attribs radio-advertisement
control-message-frequency)))

As for "extracting these facts out", I'm not sure if you want a reference to
the fact or one of its slot values.  To get a reference to a fact, simply
bind the LHS pattern to a variable like this

  ?fact <- (adv-attributes (id ?id) (attribs $?attribs))

For example:

  (defrule print-adv-attributes-facts
  "This rule matches all adv-attributes facts and binds their id and
attribute slots to variables"
  ;; Only use the $ prefix to match multifields in LHS patterns.  Drop it on
the RHS of rules.
  ?fact <- (adv-attributes (id ?id) (attributes $?attribs))
  =>
  (printout t "Fact-id=" ?fact crlf)
  (printout t "id=" ?fact crlf)
  (printout t "attribs=" ?fact crlf))

If you put all this in a batch file and run it, Jess will print:

Jess> (batch cal.clp)
MAIN::show-adv-attributes: +1+1+1+t
 ==> Focus MAIN
 ==> f-0 (MAIN::initial-fact)
 ==> f-1 (MAIN::adv-attributes (id 1) (attribs radio-advertisement
low-budget))
==> Activation: MAIN::show-adv-attributes :  f-1
 ==> f-2 (MAIN::adv-attributes (id 2) (attribs radio-advertisement
control-message-frequency))
==> Activation: MAIN::show-adv-attributes :  f-2
FIRE 1 MAIN::show-adv-attributes f-2
-------------------------
Fact-id=<Fact-2>
id=2
attribs=(radio-advertisement control-message-frequency)
FIRE 2 MAIN::show-adv-attributes f-1
-------------------------
Fact-id=<Fact-1>
id=1
attribs=(radio-advertisement low-budget)
 <== Focus MAIN
2
Jess>

Hope this gives you some traction.
Cheers,

Jason
------------------------

Jason Morris
Morris Technical Solutions
[EMAIL PROTECTED]
www.morristechnicalsolutions.com
fax/phone: 503.692.1088

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

Reply via email to