G'day all,
A few questions:
1. Why can't defrule be used directly within a user function?
2. What is the scope of a variabled bound (binded?) within a user function?
3. If "build" comes across a variable ( ?someVar ) in a string it is evaluating, does it treat it like a variable?
I'm trying to get a rule working which has a RHS that adds some variables to a Java ArrayList.
I have been experimenting with str-cat and build. I realize str-cat converts and Java objects to their toString. Also, I am aware of the \" trick to include quotes if necessary. But I keep running into trouble at runtime when Jess says that there is no such variable.
A code snippet:
-------------------------------------------------------
(clear)
(reset)
(import java.util.ArrayList)
(deftemplate street_name_alias (slot actual_name) (slot actual_type) (slot dli_id) (slot soundex) (multislot alias) (slot lga) (slot locality) )
(load-facts "road_facts.fct")
(deffunction street-names-soundex (?input)
(bind ?matches (new ArrayList 0) )
(bind ?code (str-cat "\""?input"\"") )
(printout t ?code crlf)
(bind ?rule (str-cat "(defrule name-from-soundex (street_name_alias (soundex " ?code ") (actual_name ?name)) => (call ?matches add ?name) )") )
(build ?rule)
(return true)
)
(street-names-soundex "M640")
(run)
-------------------------------------------------------
When I refer to ?matches in my RHS, shouldn't it see the variable I have already established, which points to the ArrayList?
As always thanks. I posted this I have been stuck for ages.
Cheers,
Matt
--
Matthew Hutchinson
Ph.D. Candidate
Department of Spatial Sciences
Curtin University of Technology
GPO Box U1987
Perth, Western Australia 6845
Visiting Scholar
Department of Geography and Planning
University of Akron
Akron, Ohio USA
- JESS: resolving variables when using build Matthew Hutchinson
- Re: JESS: resolving variables when using build ejfried
- Re: JESS: resolving variables when using build Matthew Hutchinson
