SlideServe
Menu
Préférences
© SlideServe · v2026

Advanced Pattern Matching

fell avatar
16 diapositives · 330 Views · Aug 31, 2014

Advanced Pattern Matching. Field constraints. Used to restrict the values of a field on LHS of a rule. Not field constraint. (defrule person-without-brown-hair (person (name ?name) (hair ~brown)) => (printout t ?name “ does not have brown hair”)). Other field contraints.

Advanced Pattern Matching - slide 1
01 / 16Advanced Pattern Matching
1 / 17

Télécharger la présentation

Advanced Pattern Matching
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Advanced Pattern Matching

  2. Field constraints • Used to restrict the values of a field on LHS of a rule Not field constraint (defrule person-without-brown-hair (person (name ?name) (hair ~brown)) => (printout t ?name “ does not have brown hair”))

  3. Other field contraints • And field constraint & • Or field constraint  | (defrule black-or-brown-hair (person (name ?name) (hair ?color&~brown&~black)) => (printout t ?name “ has ” ?color “ hair ” crlf))

  4. Functions & Expressions • Numeric Expression • Prefix notation • Basic operations : +,-,*,/ (y2-y1) / (x2-x1) >0\ Will be : (> (/ (- y2 y1) (- x2 x1)) 0)

  5. Functions & Expressions • Clips supports variable numbers of arguments • There is no built-in precedence of arithmetic operations • Everything is simply evaluated from left to right, parentheses determining precedence

  6. Functions & Expressions • Be careful! (assert (answer (+ 2 2))) (assert (expression 2+3*4)) Facts inserted by clips (answer 4) (expression 2+3*4)

  7. Summing values using rules (defrule sum-rectangles (rectangle (height ?height)(width ?width)) ?sum<- (sum ?total) => (retract ?sum) (assert (sum(+ ?total (* ?height ?width))))) • This will loop endlessly • Retracting the sum rule and reasserting it will produce a loop with a single rule • Use a temporary fact!!

  8. Summing values using rules (defrule sum-rectangles (rectangle (height ?height) (width ?width)) => (assert (add-to-sum (* ?height ?width)))) (defrule sum-areas ?sum <- (sum ?total) ?new-area <- (add-to-sum ?area) => (retract ?sum ?new-area) (assert (sum (+ ?total ?area))))

  9. Variable Binding • Used to store a value in a variable to prevent recalculation • Syntax: (bind <variable> <value>) • (bind ?new-total (+ ?total ?area))

  10. How to read input? (defrule get-first-name => (printout t “what’s your name?”) (bind ?response (read) (assert (user-name ?response) ))) Sina jafarpour “sina jafarpour”

  11. Predicate Functions • Any function that return the symbol TRUE or FALSE • Any value other than FALSE is treated as TRUE • Check appendix E in Book! • (and (> 4 3) (> 4 5)) • (integerp 3.5)

  12. The Test conditional element • A way to evaluate expressions on the LHS of a rule • Instead of pattern matching, test will evaluate an expression • (test (> ?size 1))

  13. Conditional Elements • Thus far all rules had an implicit and conditional elements between patterns (defrule shutt-off-electricity-1 (emergency (type flood)) => (printout t “shut off electricity” clrf)) (defrule shutt-off-electricity-2 (emergency (type water-sprinkler)) => (printout t “shut off electricity” clrf)) (defrule shut-off-electricity (electrical-power (status on)) (Or (emergency (type flood)) (extinguisher-system (type water-sprinkler) (status on))) => (printout t “shut off electricity”))

  14. Exists and forall conditional Elements (defrule all-fires-being-handled (forall (emergency (type fire) (location ?where)) (fire-squad (location ?where)) (evacuated (building ?where)))) => (printout t “all buildings that are on fire” clrf “have been evacuated and ” clrf “have firefighters on location” clrf)

  15. Logical conditional element • Allows you to specify that the existence of a fact depends on the existence of another fact or group of facts (defrule noxious-fumes-present (emergency (type fire)) (noxious-fumes-present) => (assert (use-oxygen-masks)))

  16. Logical conditional element • After deleting the two preconditions, use-oxygen-masks will remain a fact When the noxious-fumes-present rule is executed A link is created between the facts matching the pattern Contained within the logical CE in the LHS of a rule And the facts asserted in the RHS of the rule. So, if either the emergency fact or the noxious-fumes fact Is retracted,then use-oxygen-masks fact will be also retracted (defrule noxious-fumes-present (logical (noxious-fumes-present)) (emergency (type fire)) => (assert (use-oxygen-masks)))