praktikum 03 sistem pakar

19
PRAKTIKUM 03 SISTEM PAKAR CLIPS [again]

Upload: ankti

Post on 24-Feb-2016

54 views

Category:

Documents


2 download

DESCRIPTION

PRAKTIKUM 03 SISTEM PAKAR. CLIPS [again] . WildCard Pattern. WildCard Pattern. Used to take the place of a symbol on the left hand side of a rule. ? -> match any one symbol $?-> match zero or more symbols ?name-> only match one symbols. bands.CLP. ( deftemplate member_bands - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: PRAKTIKUM  03 SISTEM   PAKAR

PRAKTIKUM 03 SISTEM PAKAR

CLIPS [again]

Page 2: PRAKTIKUM  03 SISTEM   PAKAR

WildCard Pattern

Page 3: PRAKTIKUM  03 SISTEM   PAKAR

WildCard Pattern

• Used to take the place of a symbol on the left hand side of a rule.

• ? -> match any one symbol• $? -> match zero or more symbols

• ?name -> only match one symbols

Page 4: PRAKTIKUM  03 SISTEM   PAKAR

bands.CLP• (deftemplate member_bands

(multislot member-of))

• (deffacts nama_band(member_bands (member-of beatles john_lennon paul_mccartney george_harrison ringo_starr))(member_bands (member-of who roger_daltrey pete_townsend keith_moon))

(member_bands (member-of ebtg tracey_thorn ben_watt)))

• (defrule bands(member_bands (member-of ?band $?))=>(printout t "there is a band called " ?band crlf))

Page 5: PRAKTIKUM  03 SISTEM   PAKAR

bands_member.CLP• (deftemplate member_bands

(multislot member-of))

• (deffacts nama_band(member_bands (member-of beatles john_lennon paul_mccartney george_harrison ringo_starr))(member_bands (member-of who roger_daltrey pete_townsend keith_moon))

(member_bands (member-of ebtg tracey_thorn ben_watt)))

• (defrule band-members(member_bands (member-of ?band $? ?member $?))=>(printout t ?member " is a member of " ?band crlf))

Page 6: PRAKTIKUM  03 SISTEM   PAKAR

multi_member.CLP• (deftemplate member_bands

(multislot member-of))

• (deffacts nama_band(member_bands (member-of beatles john_lennon paul_mccartney george_harrison ringo_starr))(member_bands (member-of who roger_daltrey pete_townsend keith_moon))

(member_bands (member-of ebtg tracey_thorn ben_watt)))

• (defrule band-members(member_bands (member-of ?band $?members))=>(printout t "The members of " ?band " are " $?members crlf))

Page 7: PRAKTIKUM  03 SISTEM   PAKAR

VARIABEL

Page 8: PRAKTIKUM  03 SISTEM   PAKAR

variabel.CLP(deftemplate variabel

(slot number))

(deftemplate jumlah(slot total))

(deffacts nilai(variabel (number 4))(variabel (number 6)))

(defrule addup(variabel (number ?x))(variabel (number ?y))

=>(bind ?total (+ ?x ?y))(printout t ?x " + " ?y " = " ?total crlf)(assert (jumlah (total ?total))))

Page 9: PRAKTIKUM  03 SISTEM   PAKAR

defglobal.CLP(defglobal

?*var1* = 17?*oranges* = "seven")

(deftemplate variabel(slot number))

(deftemplate jumlah(slot total))

(deffacts nilai(variabel (number 24)))

(defrule addup(variabel (number ?x))=>(bind ?total (- ?x ?*var1*))(printout t ?x " + " ?*var1* " = " ?total "(" ?*oranges* ")" crlf)(assert (jumlah (total ?total))))

Page 10: PRAKTIKUM  03 SISTEM   PAKAR

FunctionTemplates and Conditions

Page 11: PRAKTIKUM  03 SISTEM   PAKAR

birthday.CLP

(defrule birthday_is?ulang_tahun <- (ultah (birthday ?name)) ?data-fact <- (personal-data (name ?

name) (age ?age))=>

(modify ?data-fact (age (+ ?age 1)))(retract ?ulang_tahun))

Page 12: PRAKTIKUM  03 SISTEM   PAKAR

tes_weight.CLP(deftemplate personal-data

(slot name) (slot age) (slot weight) (slot height) (multislot blood-pressure))

(deffacts people(personal-data (name Andrew) (age 20) (weight 180) (height 188) (blood-pressure 130

80))(personal-data (name Cyril) (age 63) (weight 70) (height 1678) (blood-pressure 180

90)))

(defrule lardy-bugger(personal-data (name ?name) (weight ?weight))(test (> ?weight 100))=>(printout t ?name " weighs " ?weight " kg - the fat sod." crlf))

Page 13: PRAKTIKUM  03 SISTEM   PAKAR

print_age.CLP(deftemplate personal-data

(slot name) (slot age) (slot weight) (slot height) (multislot blood-pressure))

(deffacts people(personal-data (name Andrew) (age 120) (weight 80) (height 188) (blood-pressure 130

80))(personal-data (name Cyril) (age 63) (weight 70) (height 1678) (blood-pressure 180

90)))

(defrule print-ages(and(personal-data (name ?name) (age ?age))(personal-data (name ?name) (weight ?weight)))=>(printout t ?name " weighs " ?weight " at " ?age " years old." crlf))

Page 14: PRAKTIKUM  03 SISTEM   PAKAR

umbrella.CLP(deftemplate umbrella

(slot weather))

(deffacts cuaca(umbrella (weather raining))(umbrella (weather snowing))(umbrella (weather sunny)))

(defrule take-an-umbrella(or(umbrella (weather raining))(umbrella (weather snowing)))=>(printout t "Take an umbrella" crlf))

Page 15: PRAKTIKUM  03 SISTEM   PAKAR

not_birthday.CLP(deftemplate personal-data

(slot name) (slot age) (slot weight) (slot height) (multislot blood-pressure))

(deftemplate ultah(slot birthday))

(deffacts is_ultah(ultah (birthday Andrew)))

(deffacts people(personal-data (name Andrew) (age 120) (weight 80) (height 188) (blood-pressure 130 80))(personal-data (name Cyril) (age 63) (weight 70) (height 1678) (blood-pressure 180 90)))

(defrule not-birthday(personal-data (name ?name) (weight ?weight))(not (ultah (birthday ?name)))=>(printout t "It's not " ?name "'s birthday" crlf))

Page 16: PRAKTIKUM  03 SISTEM   PAKAR

pointless.CLP

(defrule pointless(test (> 6 5))

=>(printout t "Six is indeed greater than five"

crlf))

Page 17: PRAKTIKUM  03 SISTEM   PAKAR

exist_forall.CLP(deftemplate personal-data

(slot name) (slot age) (slot weight) (slot height) (multislot blood-pressure))

(deffacts people(personal-data (name Andrew) (age 20) (weight 80) (height 188) (blood-

pressure 130 80))(personal-data (name Cyril) (age 63) (weight 70) (height 1678) (blood-

pressure 180 90)))

(defrule person-exists(personal-data (name ?name))

=>(printout t "Rule person exists reports there is a person called " ?name crlf))

Page 18: PRAKTIKUM  03 SISTEM   PAKAR

Lanjutan......(defrule are-there-people

(exists (personal-data (name ?name)))=>(printout t "Rule are-there-people reports there is at least one person"

crlf))

(defrule check-each-person(forall (personal-data (name ?name) (age ?umur))(personal-data (name ?name) (weight ?berat)))=>(printout t "Rule check-each-person reports that all persons have a name"

crlf))

Page 19: PRAKTIKUM  03 SISTEM   PAKAR

Summary

• (deftemplate (slot slotname1) (slot slotname1))

• (and (predicate1) (predicate2)) • (or (predicate1) (predicate2)) • (not (predicate1)) • (test (predicate1)) • (exists (pattern)) • (forall (pattern1) (pattern2) )