我正在尝试使用CLIPS定义一些规则,以搜索段落或文档中的文本片段(例如,过滤包含字母“ a”的单词或搜索出现多次的单词),但是我找不到任何规则例。在哪里可以找到我的问题的一些示例?
答案 0 :(得分:1)
在规则模式内,您可以对段落中的多个单词施加约束(例如查看同一单词是否出现多次):
CLIPS>
(deftemplate paragraph
(multislot words))
CLIPS>
(defrule more-than-once
(paragraph (words $? ?w $? ?w $?))
=>
(assert (more-than-once ?w)))
CLIPS>
(defrule print-more-than-once
(more-than-once ?w)
=>
(printout t "'" ?w "' appears more than once." crlf))
CLIPS>
(assert (paragraph (words the quick brown fox jumped over the lazy dogs)))
<Fact-1>
CLIPS> (run)
'the' appears more than once.
CLIPS>
或者您可以将它们放在一个单词上:
CLIPS>
(defrule contains-e
(paragraph (words $? ?w&:(str-index "e" ?w) $?))
=>
(assert (contains ?w e)))
CLIPS>
(defrule print-contains
(contains ?w ?l)
=>
(printout t "'" ?l "' is contained in '" ?w "'." crlf))
CLIPS> (run)
'e' is contained in 'the'.
'e' is contained in 'jumped'.
'e' is contained in 'over'.
CLIPS>