如何在规则中打印出所有匹配事实

时间:2015-12-08 18:44:10

标签: clips

我有一个像下面这样的规则,我想打印与此规则兼容的所有事实(此处为objct)。我有一个事实对象,其中有一些" objct" s遵循规则。我怎么能这样做?下面的打印输出只打印玩家获得的最新对象。但是我想打印出所有这些。有什么想法吗?

sudo npm install-g yaml2json

1 个答案:

答案 0 :(得分:2)

使用matches命令:

CLIPS> 
(deftemplate objct
   (slot name)
   (slot location)
   (slot used))
CLIPS>    
(deffacts initial
   (objct (name x) (location player) (used 0))
   (objct (name y) (location elsewhere) (used 1))
   (objct (name z) (location player) (used 0))
   (input have)
   (input want)
   (input possession)
   (input thing))
CLIPS>    
(defrule have_objcts   
   ?input <- (input have|possession)
   (objct (name ?n) (location player) (used 0))
   =>       
   (retract ?input)) 
CLIPS> (reset)
CLIPS> (matches have_objcts)
Matches for Pattern 1
f-4
f-6
Matches for Pattern 2
f-1
f-3
Partial matches for CEs 1 - 2
f-6,f-3
f-6,f-1
f-4,f-3
f-4,f-1
Activations
f-6,f-3
f-6,f-1
f-4,f-3
f-4,f-1
(4 4 4)
CLIPS> (run)
CLIPS> (matches have_objcts)
Matches for Pattern 1
 None
Matches for Pattern 2
f-1
f-3
Partial matches for CEs 1 - 2
 None
Activations
 None
(2 0 0)
CLIPS>