一个家庭的 CLIPS 事实和模板

问题描述

最近几天第一次尝试 CLIPS,必须承认这有点让人不知所措。我正在参加 Giarratano 书中的这个练习:

"Convert the following sentences to facts in a deffacts statement. For each group of related facts,define a deftemplate that describes a more general relationship.

The father of John is Tom.

The mother of John is Susan.

The parents of John are Tom and Susan.

Tom is a father.

Susan is a mother.

John is a son.

Tom is a male.

Susan is a female.

John is a male.

所以我尝试了以下方法

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

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

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

(deftemplate male
    (slot person)
)

(deftemplate female
    (slot person)
)

(deftemplate father
    (slot person)
)

(deftemplate mother
    (slot person)
)

(deftemplate son
    (slot person)
)

(deftemplate male
    (slot person)
)

(deftemplate female
    (slot person)
)

(deffacts family
    (father-of (father Tom) (child John))
    (mother-of (mother Susan) (child John))
    (parents-of (mother Susan) (father Tom) (child John))
    (father (person Tom))
    (mother (perosn Susan))
    (son (person John))
    (male (person Tom))
    (female (person Susan))
    (male (person John))
)

加载到 CLIP 时返回

CLIPS> (load familyy.clp)
Defining deftemplate: father-of
Defining deftemplate: mother-of
Defining deftemplate: parents-of
Defining deftemplate: male
Defining deftemplate: female
Defining deftemplate: father
Defining deftemplate: mother
Defining deftemplate: son
Defining deffacts: family
TRUE

这样好吗?喜欢它吗?我有很多我想做的练习,但 TRUE 是否意味着它做对了?所有的“重新定义模板是什么意思”

此外,如果您有任何关于剪辑的示例或任何内容的地方,非常感谢,因为我注意到 CLIPS 资源很少而且很难找到。

解决方法

您可以从这里下载 CLIPS 相关材料:https://sourceforge.net/projects/clipsrules/

除了可以下载的文档,您还可以在这里在线查看:http://www.clipsrules.net/Documentation.html

来自加载命令的文档:

将存储在由 指定的文件中的构造加载到环境中。如果正在监视编译项(请参阅第 13.2 节),那么将为每个加载的构造显示一条信息消息(包括构造的类型和名称)。如果未监视编译项,则为加载的每个构造打印一个字符(“*”表示 defrule,“$”表示 defacts,“%”表示 deftemplate,“:”表示 defglobal,“!”表示 deffunction,“ ^”代表defgeneric,“&”代表defmethod,“#”代表defclass,“~”代表defmessage-handler,“@”代表definstances,“+”代表defmodule)。如果文件加载成功,此函数返回 TRUE,否则返回 FALSE。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...