数学之路(3)-机器学习(4)-专家系统(2)

本博客所有内容是原创,如果转载请注明来源

http://blog.csdn.net/myhaspl/


事实的增加与删除

一、说明

1、(facts)为查看事实

2、(deftemplate person
(slot name)
.....)

为定义自定义模板,slot表示槽,person为一个自定义结构

3、(assert (person
(name "zhanghua")
(age 25)
(eye-color blue)
(hair-color red) ) )
增加person结构的事实

4、 (assert (person
(name "zhouhua")
(age 65)
(eye-color blue)
(hair-color red) )
(person
(name "liujun")
(age 45)
(eye-color black)
(hair-color black) ) )
可以同时增加2个或多个事实

5、(retract 2 )为删除事实,可同时删除多个事实(retract 3 5)

6、重复的事实不能反复增加

二、操作

CLIPS (Quicksilver Beta09/24/07)
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (deftemplate person
(slot name)
(slot age)
(slot eye-color)
(slot hair-color))
CLIPS> (assert (person
(name "zhangsan")
(age 25)
(eye-color blue)
(hair-color black) ) )

CLIPS> (assert (person
(name "zhanghua")
(age 25)
(eye-color blue)
(hair-color red) ) )

CLIPS> (assert (person
(name "zhanghua")
(age 25)
(eye-color blue)
(hair-color red) )
(person
(name "zhouhui")
(age 45)
(eye-color black)
(hair-color black) ) )

CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (age 25) (eye-color blue) (hair-colorblack))
f-2(person (name "zhanghua") (age 25) (eye-color blue) (hair-colorred))
f-3(person (name "zhouhui") (age 45) (eye-color black) (hair-colorblack))
For a total of 4 facts.
CLIPS> (assert (person
(name "zhouhua")
(age 65)
(eye-color blue)
(hair-color red) )
(person
(name "liujun")
(age 45)
(eye-color black)
(hair-color black) ) )

CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (age 25) (eye-color blue) (hair-colorblack))
f-2(person (name "zhanghua") (age 25) (eye-color blue) (hair-colorred))
f-3(person (name "zhouhui") (age 45) (eye-color black) (hair-colorblack))
f-4(person (name "zhouhua") (age 65) (eye-color blue) (hair-colorred))
f-5(person (name "liujun") (age 45) (eye-color black) (hair-colorblack))
For a total of 6 facts

CLIPS> (retract 2 )
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (age 25) (eye-color blue) (hair-colorblack))
f-3(person (name "zhouhui") (age 45) (eye-color black) (hair-colorblack))
f-4(person (name "zhouhua") (age 65) (eye-color blue) (hair-colorred))
f-5(person (name "liujun") (age 45) (eye-color black) (hair-colorblack))
For a total of 5 facts.
CLIPS> (retract 3 5)
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (age 25) (eye-color blue) (hair-colorblack))
f-4(person (name "zhouhua") (age 65) (eye-color blue) (hair-colorred))
For a total of 3 facts.
CLIPS>


事实的修改

一、修改用(modify 1 (age 26)),复制用(duplicate 4(name"zhoudahua")),这两个操作产生的事实产能用于有序事实,有关系名没有相应自定义模板的事实为有序事实。修改通过撤销原事实生成新的事实而成。

二、实例

 

CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (age 25) (eye-color blue) (hair-colorblack))
f-4(person (name "zhouhua") (age 65) (eye-color blue) (hair-colorred))
For a total of 3 facts.
CLIPS> (modify 1 (age 26))

CLIPS> (duplicate 4(name "zhoudahua"))

CLIPS> (facts)
f-0(initial-fact)
f-4(person (name "zhouhua") (age 65) (eye-color blue) (hair-colorred))
f-6(person (name "zhangsan") (age 26) (eye-color blue) (hair-colorblack))
f-7(person (name "zhoudahua") (age 65) (eye-color blue) (hair-colorred))
For a total of 4 facts.

 

数学之路(3)-机器学习(4)-专家系统(1)


你可能感兴趣的:(数学,人工智能,专家系统)