КЛИПС (аргументы) - семейные отношения: как избежать вопроса о том, что один человек является братом самому себе?

Введение

Я пытаюсь реализовать правило на языке CLIPS - отношение, что человек является братом другого человека. Ограничение состоит в том, что такое правило должно выводиться только из следующих предпосылок:

(мужчина? x) ("x - женщина")

(female? y) ("y - женщина")

(мать? x? y) ("x - мать y")

(отец? x? y) ("x - отец y")

Моя попытка

Я написал следующий код:

(deftemplate father-of 
    (slot father)
    (slot child)
)

(deftemplate mother-of 
    (slot mother)
    (slot child)
)

(deftemplate male 
    (slot person)
)

(deftemplate female
     (slot person)
)

(deffacts family
    (father-of (father John) (child Mark))
    (father-of (father John) (child Mary))
    (mother-of (mother Alice) (child Mark))
    (mother-of (mother Alice) (child Mary))
    (male (person John))
    (male (person Mark))
    (female (person Alice))
    (female (person Mary))
)

(defrule brother
    (and
        (male (person ?alpha))
        (mother-of (mother ?x) (child ?alpha))
        (father-of (father ?y) (child ?alpha))
        (mother-of (mother ?x) (child ?beta))
        (father-of (father ?y) (child ?beta))
    )
    =>
    (printout t ?alpha " is a brother of " ?beta crlf)
    (assert (brother ?alpha ?beta))
)

Суть проблемы

Приведенный выше код компилируется и возвращает «истину» (другими словами, построенное правило логически корректно).

Однако есть тонкая проблема:

Как избежать проблемы добавления факта, например, «Марк - брат Марка» (мы предполагаем, что каждое имя уникально, поэтому одно и то же имя соответствует одному и тому же человеку)? Очевидно, что это ложный факт, но мое правило выводит такую ​​глупость.

Приведенный выше код не решает эту проблему.

Как побороть эту проблему?

Благодарности

Буду благодарен за помощь в этом вопросе !!!


person xxx    schedule 26.10.2018    source источник


Ответы (2)


Измените ограничение? Beta во втором материнском шаблоне на? Beta & ~? Alpha.

(defrule brother
    (and
        (male (person ?alpha))
        (mother-of (mother ?x) (child ?alpha))
        (father-of (father ?y) (child ?alpha))
        (mother-of (mother ?x) (child ?beta&~?alpha))
        (father-of (father ?y) (child ?beta))
    )
    =>
    (printout t ?alpha " is a brother of " ?beta crlf)
    (assert (brother ?alpha ?beta))
)
person Gary Riley    schedule 26.10.2018

Вот мое независимое решение:

(defrule brother
    (and
        (male (person ?alpha))

        (or
             (male (person ?beta))
             (female (person ?beta))
         )

        (mother-of (mother ?x) (child ?alpha))
        (father-of (father ?y) (child ?alpha))
        (mother-of (mother ?x) (child ?beta))
        (father-of (father ?y) (child ?beta))
        (test (neq ?alpha ?beta))
    )
    =>
    (printout t ?alpha " is a brother of " ?beta crlf)
    (assert (brother ?alpha ?beta))
)
person xxx    schedule 26.10.2018