用于删除剪辑中重复字符串的函数

时间:2014-01-20 10:25:09

标签: string clips

Clips中是否存在删除重复字符串的功能? 示例:我有这样的结构:

[quality] [comfort] [caliber] [console]
[quality] [comfort] [caliber] [console]
[quality] [comfort] [character] [console]
[quality] [comfort] [lineament] [console]
[quality] [comfort] [timbre] [console]

我需要保持一个[质量] [舒适]。它们存储在变量中,如下所示: “[”?tpe1“]”“[”?tpic1“]”“[”?syntype“]”“[”?syntopic“]”

这些是写入文件的代码:

(defrule Synonymous::rulesoftgoal " "
(declare (salience 55))
(synonymoustype
(type            ?type    )
(syntype         ?syntype ))
(synonymoustopic
(topic           ?topic   )
(syntopic        ?syntopic))
=>
(printout  baseFile "[" ?tpe1 "]" "["?tpic1"]""[" ?syntype"]" "[" ?syntopic "]" crlf) 
)

有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

如果这是您原来的方法:

CLIPS> 
(deftemplate synonymoustype
   (slot id)
   (slot type)
   (slot syntype))
CLIPS>    
(deftemplate synonymoustopic
   (slot id)
   (slot topic)
   (slot syntopic))
CLIPS>    
(deffacts initial
   (synonymoustype (id 1) (type quality) (syntype caliber))
   (synonymoustype (id 2) (type quality) (syntype caliber))
   (synonymoustype (id 4) (type quality) (syntype character))
   (synonymoustype (id 4) (type quality) (syntype linament))
   (synonymoustype (id 5) (type quality) (syntype timbre))
   (synonymoustopic (id 6) (topic comfort) (syntopic console)))
CLIPS> 
(defrule rulesoftgoal
   (declare (salience 55))
   (synonymoustype
      (type ?type)
      (syntype ?syntype ))
   (synonymoustopic
      (topic ?topic)
      (syntopic ?syntopic))
   =>
   (printout t "[" ?type "]" " [" ?topic "]" " [" ?syntype "]" " [" ?syntopic "]" crlf))
CLIPS> (reset)
CLIPS> (run)
[quality] [comfort] [caliber] [console]
[quality] [comfort] [caliber] [console]
[quality] [comfort] [character] [console]
[quality] [comfort] [linament] [console]
[quality] [comfort] [timbre] [console]
CLIPS>

这是防止重复打印的一种方法:

CLIPS>    
(deftemplate synonymoustype
   (slot id)
   (slot type)
   (slot syntype))
CLIPS>    
(deftemplate synonymoustopic
   (slot id)
   (slot topic)
   (slot syntopic))
CLIPS>    
(deffacts initial
   (synonymoustype (id 1) (type quality) (syntype caliber))
   (synonymoustype (id 2) (type quality) (syntype caliber))
   (synonymoustype (id 4) (type quality) (syntype character))
   (synonymoustype (id 4) (type quality) (syntype linament))
   (synonymoustype (id 5) (type quality) (syntype timbre))
   (synonymoustopic (id 6) (topic comfort) (syntopic console)))
CLIPS> 
(defrule rulesoftgoal
   (declare (salience 55))
   (synonymoustype
      (type ?type)
      (syntype ?syntype ))
   (synonymoustopic
      (topic ?topic)
      (syntopic ?syntopic))
   =>
   (assert (print-string (str-cat "[" ?type "]" " [" ?topic "]" " [" ?syntype "]" " [" ?syntopic "]"))))
CLIPS> 
(defrule rulesoftgoal-print
   ?f <- (print-string ?string)
   =>
   (retract ?f)
   (printout t ?string crlf))
CLIPS> (reset)
CLIPS> (run)
[quality] [comfort] [timbre] [console]
[quality] [comfort] [linament] [console]
[quality] [comfort] [character] [console]
[quality] [comfort] [caliber] [console]
CLIPS> 

这是另一个:

CLIPS>    
(deftemplate synonymoustype
   (slot id)
   (slot type)
   (slot syntype))
CLIPS>    
(deftemplate synonymoustopic
   (slot id)
   (slot topic)
   (slot syntopic))
CLIPS>    
(deffacts initial
   (synonymoustype (id 1) (type quality) (syntype caliber))
   (synonymoustype (id 2) (type quality) (syntype caliber))
   (synonymoustype (id 4) (type quality) (syntype character))
   (synonymoustype (id 4) (type quality) (syntype linament))
   (synonymoustype (id 5) (type quality) (syntype timbre))
   (synonymoustopic (id 6) (topic comfort) (syntopic console)))
CLIPS> 
(defrule rulesoftgoal
   (declare (salience 55))
   (synonymoustype
      (type ?type)
      (syntype ?syntype ))
   (synonymoustopic
      (topic ?topic)
      (syntopic ?syntopic))
   (not (already-printed ?type ?topic ?syntype ?syntopic))
   =>
   (assert (already-printed ?type ?topic ?syntype ?syntopic))
   (printout t "[" ?type "]" " [" ?topic "]" " [" ?syntype "]" " [" ?syntopic "]" crlf))
CLIPS> (reset)
CLIPS> (run)
[quality] [comfort] [caliber] [console]
[quality] [comfort] [character] [console]
[quality] [comfort] [linament] [console]
[quality] [comfort] [timbre] [console]
CLIPS>