如何在 defacts 构造中检索事实的句柄?
How to retrieve a handle to facts inside a deffacts construct?
如问题所述,我会以某种方式尝试在 defacts 构造中获取事实句柄。出现问题是因为我不想在 WM 中多次重新定义相同的东西(因为 set-fact-duplication 是真的)并且因为我使用结构化 detemplate,其中一个字段是 FACT_ADDRESS.
您不能在 defacts 构造中绑定事实地址。相反,我建议的是在事实之间使用符号 link。在您的情况下,如果旅游类型、旅游胜地和酒店事实的名称在每种类型的事实中是唯一的,您可以使用该插槽作为符号 link:
(deftemplate tourism-type
(slot name)
(slot score))
(deftemplate hotel
(slot name)
(slot tr)
(slot stars)
(slot price-per-night))
(deftemplate tourism-resort
(slot name)
(slot region)
(multislot type))
(deffacts the-tourism-type-list
(tourism-type (name culturale) (score 3))
(tourism-type (name enogastronomico) (score 4)))
(deffacts the-tourism-resort-list
(tourism-resort
(name Venezia)
(region Veneto)
(type culturale enogastronomico)))
(deffacts the-hotels-list
(hotel
(name hotel1)
(tr Venezia)
(stars 3)
(price-per-night 100)))
在您的规则中,您可以使用符号 link 检索 linked 事实:
(defrule food-and-wine-hotels
(hotel (name ?hotel)
(tr ?tr-name))
(tourism-resort
(name ?tr-name)
(type $? enogastronomico $?))
=>
(printout t ?hotel crlf))
如问题所述,我会以某种方式尝试在 defacts 构造中获取事实句柄。出现问题是因为我不想在 WM 中多次重新定义相同的东西(因为 set-fact-duplication 是真的)并且因为我使用结构化 detemplate,其中一个字段是 FACT_ADDRESS.
您不能在 defacts 构造中绑定事实地址。相反,我建议的是在事实之间使用符号 link。在您的情况下,如果旅游类型、旅游胜地和酒店事实的名称在每种类型的事实中是唯一的,您可以使用该插槽作为符号 link:
(deftemplate tourism-type
(slot name)
(slot score))
(deftemplate hotel
(slot name)
(slot tr)
(slot stars)
(slot price-per-night))
(deftemplate tourism-resort
(slot name)
(slot region)
(multislot type))
(deffacts the-tourism-type-list
(tourism-type (name culturale) (score 3))
(tourism-type (name enogastronomico) (score 4)))
(deffacts the-tourism-resort-list
(tourism-resort
(name Venezia)
(region Veneto)
(type culturale enogastronomico)))
(deffacts the-hotels-list
(hotel
(name hotel1)
(tr Venezia)
(stars 3)
(price-per-night 100)))
在您的规则中,您可以使用符号 link 检索 linked 事实:
(defrule food-and-wine-hotels
(hotel (name ?hotel)
(tr ?tr-name))
(tourism-resort
(name ?tr-name)
(type $? enogastronomico $?))
=>
(printout t ?hotel crlf))