规则

规则由几个互相依赖的简单句(谓词)组成。用来描述事实之间的依赖关系,如:因果关系,蕴含关系,对应关系

规则的实质就是存储起来得查询

 

其语法结构如下:

head:-body

head 为谓词的定义部分,和事实一样,也包括谓词名和参数说明

:-   连接符 表示 蕴含

body  一个或多个目标,用“,”连接,表示 且

如上一章中的混合查询按规则保存下来即为:

where_food(X,Y):-location(X,Y),edible(X).

房间Y中,有可食事物的条件是:X位于Y 中,且X具有 edible属性

 

 

 

继续用上一章举例子,在文件的最后追加一个规则

where_food(X,Y):-location(X,Y),edible(X).

文件内容如下:

room(kitchen).  
room(office).
room(hall).
room('dining room'). 
room(cellar).
location(nani,'washing mechine').
location(desk,office). 
location(apple,kitchen).
location(broccoli,kitchen).
location(crackers,kitchen).
location(flashlight,desk).
location('washing mechine',cellar).
location(computer,office).
door(office,hall).    
door(kitchen,office).
door(hall,'dining room').
door(kitchen,cellar).
door('dining room',kitchen).
edible(apple).
edible(crackers).
tastes_yucky(broccoli).
turned_off(flashlight).
here(kitchen).



where_food(X,Y):-location(X,Y),edible(X).
View Code

相关文章:

  • 2021-05-07
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2021-08-21
  • 2022-12-23
  • 2021-09-30
相关资源
相似解决方案