;; FuzzyVariable : Java class
;; Jess globle variables are used to hold Java objects
(import nrc.fuzzy.*)
(defglobal ?*tempFvar* = (new FuzzyVariable "temperature" 0.0 100.0 "C"))
(defglobal ?*pressFvar* = (new FuzzyVariable "pressure" 0.0 10.0 "kilo-pascals"))
;; using an array of (x,y) values to define a Fuzzy set
(bind ?xHot (create$ 25.0 35.0))
(bind ?yHot (create$ 0.0 1.0))
(bind ?xCold (create$ 5.0 15.0))
(bind ?yCold (create$ 1.0 0.0))
(?*tempFvar* addTerm "hot" ?xHot ?yHot 2)
(?*tempFvar* addTerm "cold" ?xCold ?yCold 2)
Show
;; using already defined terms of fuzzy variables and linguistic expressions
(load-package nrc.fuzzy.jess.FuzzyFunctions)
(?*tempFvar* addTerm "veryHot" "very hot")
(?*tempFvar* addTerm "medium" "not hot and (not cold)")
;; assert a fuzzy fact.
;; FuzzyValue : Java class
(assert (theTemp (new FuzzyValue ?*tempFvar* "very medium")))
Show
(load-package nrc.fuzzy.jess.FuzzyFunctions)
(?*fcnFvar* addTerm "trapezoid" (new TrapezoidFuzzySet 3.0 3.8 6.5 7.0))
(?*fcnFvar* addTerm "rectangle" (new RectangleFuzzySet 3.8 6.5))
(?*fcnFvar* addTerm "triangle" (new TriangleFuzzySet 3.0 5.4 7.0))
(?*fcnFvar* addTerm "pi" (new PIFuzzySet 4.7 2.0))
(?*fcnFvar* addTerm "s" (new SFuzzySet 1.0 9.0))
(?*fcnFvar* addTerm "z" (new ZFuzzySet 1.0 9.0))
Plot
(printout t (call (new FuzzyValue ?*fcnFvar* "trapezoid")
plotFuzzyValue "*") crlf)
(defglobal ?*rlf* = (new RightLinearFunction))
(?*fcnFvar* addTerm "right" (new RFuzzySet 0.0 5.0 ?*rlf*))
(defglobal ?*llf* = (new LeftLinearFunction))
(?*fcnFvar* addTerm "left" (new LFuzzySet 5.5 7.0 ?*llf*))
Plot
;; the rule 'if temperature hot then pressure low or medium'
(defrule temp-hot-press-lowOrMedium
(theTemp ?t&:(fuzzy-match ?t "hot"))
=>
(assert (thePress (new FuzzyValue ?*pressFvar* "low or medium")))
)
When a temperature fact is asserted that has a FuzzyValue in it, the fuzzy-match will compare the FuzzyValue in the fact to the FuzzyValue hot.
(defrule identify-tall-people "determine strength of tallness for a person"
(person (name ?n) (height ?ht&:(fuzzy-match ?ht "tall")))
=>
(printout t ?n " is tall with degree (similarity) " (fuzzy-rule-similarity) crlf)
(printout t ?n " is tall with degree (match) " (fuzzy-rule-match-score) crlf)
)