不能使“ not”和“ eq”一起工作

fs71gh

我有一棵家谱。我需要使用CLIPS查找某人的小brother。

家谱

http://oi61.tinypic.com/viik4y.jpg

寻找兄弟姐妹的规则

规则1(寻找配偶的兄弟)

(defrule MAIN::fnd_BrthrsNLaw1 ;spouse's brother
   (findRelative (person ?pn) (relationship b_i_lw)) ;Brothers-in-Law
   (and
        (and (and (or (marriage-between (personA ?pn) (personB ?sp))
                      (marriage-between (personA ?sp) (personB ?pn))
                  )
                  (child-of (relationship ?x) (person ?sp) (mother ?m) (father ?f))
             )
             (child-of (relationship son-of) (person ?pn2) (mother ?m) (father ?f))
        )
        (not (marriage-between (personA ?pn) (personB ?pn2)))
   )
   =>
   (printout t ?pn "'s brothers-in-Law: (spouse's brother) " ?pn2 crlf) 
)

规则2(寻找配偶的姐姐的丈夫)

(defrule MAIN::fnd_BrthrsNLaw2 ;spouse's sister's husband
   (findRelative (person ?pn) (relationship b_i_lw)) ;Brothers-in-Law
   (and
        (and 
              (and 
                    (or 
                        (marriage-between (personA ?pn) (personB ?sp))
                        (marriage-between (personA ?sp) (personB ?pn))
                    )
                    (and 
                         (child-of (relationship ?x) (person ?sp) (mother ?a) (father ?b))
                         (child-of (relationship daughter-of) (person ?p2) (mother ?a) (father ?b))
                    )
               )
               (and
                    (not (eq ?sp ?p2))
                    (marriage-between (personA ?p2) (personB ?px2))
               )
        )
    =>
    (printout t ?pn "'s brothers-in-Law: (spouse's sister's husband) " ?px2 " <sister = " ?p2 " ; spouse = " ?sp " ; spouse's parents: " ?a " , " ?b ">" crlf)
)

规则3(寻找姐姐的丈夫)

(defrule MAIN::fnd_BrthrsNLaw3 ;sister's husband
   (findRelative (person ?p) (relationship b_i_lw)) ;Brothers-in-Law
   (and 
          (and
                (child-of (relationship ?y) (person ?p) (mother ?c) (father ?d))
                (child-of (relationship daughter-of) (person ?sist) (mother ?c) (father ?d))
          )
          (and 
                (not (eq ?p ?sist))
                (marriage-between (personA ?sist) (personB ?p2))
          )
    )
    =>
   (printout t ?p "'s brothers-in-Law: (sister's husband) " ?p2 <sister = " ?sist " ; " ?p "'s parent = " ?sp " ; spouse's parents: " ?c " , " ?d ">"crlf) 
   (reset)
)

范本

(deftemplate MAIN::marriage-between
   (slot personA)
   (slot personB))

(deftemplate MAIN::child-of
   (slot relationship (type SYMBOL) (allowed-symbols son-of daughter-of))
   (slot person)
   (slot mother)
   (slot father))

(deftemplate MAIN::findRelative
   (slot relationship (type SYMBOL) 
         (allowed-symbols g_g_p ;Great-GrandParents 
                    g_ch ;GrandChildren 
                    b_i_lw)) ;Brothers-in-Law 
   (slot person))

现在,对于-1)戴安娜(Diana)的brother子(或b_i_lw)必须是Andrew,Mark和Edward(2)马克(Mark),b_i_lw的是Andrew(Andrew),Edward(爱德华)和Charles(查尔斯)。3)Charles,b_i_lw'必须是Mark。

但是我的输出并不完全正确,因为对于配偶的兄弟姐妹的姐姐(规则名为“ fnd_BrthrsNLaw2”)和姐姐的丈夫(规则名为“ fnd_BrthrsNLaw3”),还使用了正确的信息推导出了一些错误的信息

Mark,Diana和Charles的输出如下:

搜索戴安娜的输出:

CLIPS> (assert (findRelative (person Diana) (relationship b_i_lw)))
<Fact-20>
CLIPS> (run)
Diana's brothers-in-Law: (spouse's brother) Edward
Diana's brothers-in-Law: (spouse's brother) Andrew
Diana's brothers-in-Law: (spouse's sister's husband) Mark <sister = Anne ; spouse = Charles ; Charles's parents: Elizabeth , Phillip>
Diana's brothers-in-Law: (sister's husband) Charles <sister = Diana ; Diana's parent: Kydd , Spencer>

搜索标记的输出:

CLIPS> (assert (findRelative (person Mark) (relationship b_i_lw)))
<Fact-20>
CLIPS> (run)
Mark's brothers-in-Law: (spouse's brother) Edward
Mark's brothers-in-Law: (spouse's brother) Andrew
Mark's brothers-in-Law: (spouse's brother) Charles
Mark's brothers-in-Law: (spouse's sister's husband) Mark <sister = Anne ; spouse = Anne ; Anne's parents: Elizabeth , Phillip>

搜索Charles的输出:

CLIPS> (assert (findRelative (person Charles) (relationship b_i_lw)))
<Fact-20>
CLIPS> (run)
Charles's brothers-in-Law: (spouse's sister's husband) Charles <sister = Diana ; spouse = Diana ; Diana's parents: Kydd , Spencer>
Charles's brothers-in-Law: (sister's husband) Mark <sister = Anne ; Anne's parent: Elizabeth , Phillip>

我的假设是在Rule-2中使用(not(eq)),rule-3不会影响它们在其中的'and'块,尽管我已经测试过(not(eq))在和不相等时为真当它们相等时为false,这是我打算得到的。

加里·莱利(Gary Riley)

您需要使用测试CE来评估规则条件下的表达式。例如,代替

(not (eq ?sp ?p2))

使用

(test (not (eq ?sp ?p2)))

或者

(test (neq ?sp ?p2))

您现有的规则试图将事实与关系名称eq匹配,而不是调用eq函数比较值。

同样,您可能不想执行在fnd_BrthrsNLaw3规则操作中调用reset命令。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

GTK和INotify不能一起工作

来自分类Dev

Mongodb:$ exists和$ ne不能一起工作

来自分类Dev

kubeadm 和 weave 不能一起工作

来自分类Dev

不能使字符串相等方法和将字符串转换为数字一起工作。

来自分类Dev

MongoDB:$ nin和$ in在$ elemMatch中不能一起工作

来自分类Dev

GridView和导航抽屉不能在android中一起工作

来自分类Dev

Ruby on rails collection_select。多个和远程不能一起工作

来自分类Dev

Vertx和Redis:我不能让他们一起工作

来自分类Dev

为什么$ cookies和$ localStorage不能一起工作?

来自分类Dev

JQuery 调光器和无滚动不能一起工作

来自分类Dev

背景颜色和背景图像不能一起工作

来自分类Dev

淘汰赛 beforeRemove 和 CSS 动画不能在 IE 中一起工作

来自分类Dev

canvas.lineCap 和 canvas.closePath 不能一起工作

来自分类Dev

CPT 和 ACF 中继器不能一起工作

来自分类Dev

关闭 ViewController 和关闭键盘不能一起工作

来自分类Dev

CLOC --diff 和 --exclude-dir 似乎不能一起工作

来自分类Dev

express - bodyParser.json() 和 cors() 不能一起工作

来自分类Dev

Boostap4 和@media 查询不能一起工作

来自分类Dev

CSS 变换 - 旋转和倾斜不能一起工作

来自分类Dev

NVIDIA 驱动程序和 Xserver 不能一起工作

来自分类Dev

matplotlib 中的子图和 hlines 不能一起工作

来自分类Dev

Axon 事件处理程序和查询处理程序在 kotlin 中不能一起工作

来自分类Dev

Xamarin 表单自定义 GridView Tap 和 Long Tap 不能一起工作

来自分类Dev

创建情节提要动画,但不能与行和列一起工作WPF XAML C#

来自分类Dev

(VIM错误报告?)是否有原因,所以$ MYVIMRC和filetype = unix不能一起工作?

来自分类Dev

Rails:ckeditor gem 不能在生产模式下与 nginx 和乘客一起工作

来自分类Dev

SwipeRefreshLayout 和处理 webview 中的外部链接(手动类)在 android webview 中不能一起工作

来自分类Dev

为什么 std::bind 不能与 std::filesystem::path 和 std::ostream 一起工作?

来自分类Dev

Gulp 网络服务器任务和监视任务不能一起工作

Related 相关文章

  1. 1

    GTK和INotify不能一起工作

  2. 2

    Mongodb:$ exists和$ ne不能一起工作

  3. 3

    kubeadm 和 weave 不能一起工作

  4. 4

    不能使字符串相等方法和将字符串转换为数字一起工作。

  5. 5

    MongoDB:$ nin和$ in在$ elemMatch中不能一起工作

  6. 6

    GridView和导航抽屉不能在android中一起工作

  7. 7

    Ruby on rails collection_select。多个和远程不能一起工作

  8. 8

    Vertx和Redis:我不能让他们一起工作

  9. 9

    为什么$ cookies和$ localStorage不能一起工作?

  10. 10

    JQuery 调光器和无滚动不能一起工作

  11. 11

    背景颜色和背景图像不能一起工作

  12. 12

    淘汰赛 beforeRemove 和 CSS 动画不能在 IE 中一起工作

  13. 13

    canvas.lineCap 和 canvas.closePath 不能一起工作

  14. 14

    CPT 和 ACF 中继器不能一起工作

  15. 15

    关闭 ViewController 和关闭键盘不能一起工作

  16. 16

    CLOC --diff 和 --exclude-dir 似乎不能一起工作

  17. 17

    express - bodyParser.json() 和 cors() 不能一起工作

  18. 18

    Boostap4 和@media 查询不能一起工作

  19. 19

    CSS 变换 - 旋转和倾斜不能一起工作

  20. 20

    NVIDIA 驱动程序和 Xserver 不能一起工作

  21. 21

    matplotlib 中的子图和 hlines 不能一起工作

  22. 22

    Axon 事件处理程序和查询处理程序在 kotlin 中不能一起工作

  23. 23

    Xamarin 表单自定义 GridView Tap 和 Long Tap 不能一起工作

  24. 24

    创建情节提要动画,但不能与行和列一起工作WPF XAML C#

  25. 25

    (VIM错误报告?)是否有原因,所以$ MYVIMRC和filetype = unix不能一起工作?

  26. 26

    Rails:ckeditor gem 不能在生产模式下与 nginx 和乘客一起工作

  27. 27

    SwipeRefreshLayout 和处理 webview 中的外部链接(手动类)在 android webview 中不能一起工作

  28. 28

    为什么 std::bind 不能与 std::filesystem::path 和 std::ostream 一起工作?

  29. 29

    Gulp 网络服务器任务和监视任务不能一起工作

热门标签

归档