CLIPS:OR 条件元素,当且仅当其内部模式中的 2 个或更多个为 TRUE 时才计算为 TRUE
CLIPS: OR conditional element that evaluates to TRUE if and only if 2 or more of its internal patterns are TRUE
如果 1 个或多个模式匹配,则普通(或)元素的计算结果为 TRUE:
(or
(object (name name-1))
(object (name name-2))
(object (name name-3))
(object (name name-4))
)
问题是:是否有一种简单的方法可以创建一个修改后的(或)元素,如果 2 或更多,该元素的计算结果为 TRUE的模式匹配?
执行此操作的愚蠢粗暴方法当然是以下方法,但我相信有更流畅的方法。
(or
(and
(object (name name-1))
(object (name name-2))
)
(and
(object (name name-1))
(object (name name-3))
)
(and
(object (name name-1))
(object (name name-4))
)
(and
(object (name name-2))
(object (name name-3))
)
...
)
如果您尝试匹配两个以上的对象,则使用相同数量的模式并通过调用实用函数丢弃无关的排列:
CLIPS (6.31 6/12/19)
CLIPS> (defclass X (is-a USER))
CLIPS>
(definstances Xs
(name-0 of X)
(name-1 of X)
(name-3 of X)
(name-4 of X)
(name-5 of X))
CLIPS>
(deffunction in-order (?n1 ?n2)
(< (str-compare ?n1 ?n2) 0))
CLIPS>
(defrule r1
(object (name ?name1&[name-1] | [name-2] | [name-3] | [name-4]))
(object (name ?name2&[name-1] | [name-2] | [name-3] | [name-4]))
(test (in-order ?name1 ?name2))
=>)
CLIPS>
(defrule r2
(exists
(object (name ?name1&[name-1] | [name-2] | [name-3] | [name-4]))
(object (name ?name2&[name-1] | [name-2] | [name-3] | [name-4]))
(test (in-order ?name1 ?name2)))
=>)
CLIPS> (reset)
CLIPS> (agenda)
0 r1: [name-1],[name-4]
0 r1: [name-3],[name-4]
0 r1: [name-1],[name-3]
0 r2: *
For a total of 4 activations.
CLIPS>
如果 1 个或多个模式匹配,则普通(或)元素的计算结果为 TRUE:
(or
(object (name name-1))
(object (name name-2))
(object (name name-3))
(object (name name-4))
)
问题是:是否有一种简单的方法可以创建一个修改后的(或)元素,如果 2 或更多,该元素的计算结果为 TRUE的模式匹配?
执行此操作的愚蠢粗暴方法当然是以下方法,但我相信有更流畅的方法。
(or
(and
(object (name name-1))
(object (name name-2))
)
(and
(object (name name-1))
(object (name name-3))
)
(and
(object (name name-1))
(object (name name-4))
)
(and
(object (name name-2))
(object (name name-3))
)
...
)
如果您尝试匹配两个以上的对象,则使用相同数量的模式并通过调用实用函数丢弃无关的排列:
CLIPS (6.31 6/12/19)
CLIPS> (defclass X (is-a USER))
CLIPS>
(definstances Xs
(name-0 of X)
(name-1 of X)
(name-3 of X)
(name-4 of X)
(name-5 of X))
CLIPS>
(deffunction in-order (?n1 ?n2)
(< (str-compare ?n1 ?n2) 0))
CLIPS>
(defrule r1
(object (name ?name1&[name-1] | [name-2] | [name-3] | [name-4]))
(object (name ?name2&[name-1] | [name-2] | [name-3] | [name-4]))
(test (in-order ?name1 ?name2))
=>)
CLIPS>
(defrule r2
(exists
(object (name ?name1&[name-1] | [name-2] | [name-3] | [name-4]))
(object (name ?name2&[name-1] | [name-2] | [name-3] | [name-4]))
(test (in-order ?name1 ?name2)))
=>)
CLIPS> (reset)
CLIPS> (agenda)
0 r1: [name-1],[name-4]
0 r1: [name-3],[name-4]
0 r1: [name-1],[name-3]
0 r2: *
For a total of 4 activations.
CLIPS>