CLIPS-单字通配符

一、

1、? 为单字段通配符,如(person (name ? ? ?lastname)(social-security-number ?ssnum))
中的? ?表示一个名字含3个字段中的前2个字段

2、(assert (print-ssnumber"Public"))错误的原因在于要去掉"",因为是看成一个字段,所以

(run)
<== Focus MAIN
0 rules fired
失败,因为根本规则根本就没进议程.

二、操作

CLIPS> (deftemplate person
(multislot name)
(slot social-security-number))
CLIPS> (deffacts some-people
(person (name john Q. Public)(social-security-number435-8992354325))
(person (name jack Q. Public)(social-security-number934-2345350092))
)

CLIPS> (defrule print-person-ssnumber
(print-ssnumber ?lastname)
(person (name ? ? ?lastname)(social-security-number ?ssnum))
=>
(printout t ?ssnum crlf))

CLIPS> (reset)
CLIPS> (watch all)
CLIPS> (agenda)
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name john Q. Public) (social-security-number435-8992354325))
f-2(person (name jack Q. Public) (social-security-number934-2345350092))
For a total of 3 facts.
CLIPS> (assert (print-ssnumber "Public"))


==>f-3(print-ssnumber "Public")
<Fact-3>
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name john Q. Public) (social-security-number435-8992354325))
f-2(person (name jack Q. Public) (social-security-number934-2345350092))
f-3(print-ssnumber "Public")
For a total of 4 facts.
CLIPS> (agenda)
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name john Q. Public) (social-security-number435-8992354325))
f-2(person (name jack Q. Public) (social-security-number934-2345350092))
f-3(print-ssnumber "Public")
For a total of 4 facts.
CLIPS> (run)
<== Focus MAIN
0 rules fired
4 mean number of facts (4 maximum).
1 mean number of instances (1 maximum).
0 mean number of activations (0 maximum).
CLIPS> (ppdefrule print-person-ssnumber)
(defrule MAIN::print-person-ssnumber
(print-ssnumber?lastname)
(person (name ? ? ?lastname)(social-security-number ?ssnum))
=>
(printout t ?ssnumcrlf))
CLIPS> (assert (print-ssnumber Public))
==>f-4(print-ssnumber Public)
==> Activation0print-person-ssnumber: f-4,f-1
==> Activation0print-person-ssnumber: f-4,f-2
<Fact-4>
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name john Q. Public) (social-security-number435-8992354325))
f-2(person (name jack Q. Public) (social-security-number934-2345350092))
f-3(print-ssnumber "Public")
f-4(print-ssnumber Public)
For a total of 5 facts.
CLIPS> (agenda)
0print-person-ssnumber: f-4,f-2
0print-person-ssnumber: f-4,f-1
For a total of 2 activations.
CLIPS> (run)
==> Focus MAIN
FIRE 1print-person-ssnumber: f-4,f-2
934-2345350092
FIRE 2print-person-ssnumber: f-4,f-1
435-8992354325
<== Focus MAIN
2 rulesfiredRun time is 0.391000000000076 seconds.
5.1150895140655 rules per second.
5 mean number of facts (5 maximum).
1 mean number of instances (1 maximum).
1 mean number of activations (2 maximum).
CLIPS>

你可能感兴趣的:(Security,F#,Social)