I tried reading tutorials about Jess, but I can't find anything very helpful. I want to build a program which finds out which instrument I'm talking about.
So, if an instrument has strings, we know that the instrument is either in the strings or percussion (i.e. piano) category. How would I write a rule that saves a fact saying the category is either percussion or strings based on this criteria?
I considered bind, but doesn't bind mean that I would have to have a separate variable for each potential category? Or, should I use an assert?
This demonstrates how to insert a fact from within a rule to store a set of possible categories.
(deftemplate Instrument (slot strings))
(deftemplate Classification (multislot category))
(defrule cat-by-strings
?i <- (Instrument (strings ?s&:(> ?s 0)))
=>
(assert (Classification (category STRING PERCUSSION)))
)
(assert (Instrument (strings 18)))
(run)
(facts)
Output:
f-0 (MAIN::initial-fact)
f-1 (MAIN::Instrument (strings 18))
f-2 (MAIN::Classification (category STRING PERCUSSION))
For a total of 3 facts in module MAIN.
Using bound variables is useless as they are limited to the context of a rule.