【发布时间】:2021-10-23 09:47:53
【问题描述】:
所以我最近一直在使用 clipspy 开发专家系统。我已经提出了规则文件并使用 clipspy 将其加载回。我的一些问题是,如何使用 clipspy 库提取规则文件中的打印输出内容,因为我必须为系统制作一个简单的 GUI。 GUI会像弹出问题一样提示用户填写答案,直到系统结束。
示例规则文件:
(defrule BR_Service
(service BR)
=>
(printout t crlf "Would you like to book or return a car? ("B" for book / "R" for return)" crlf)
(assert (br (upcase(read))))
)
(defrule Book_Service
(br B)
=>
(printout t crlf "Are you a first-time user? (Y/N)" crlf)
(assert (b (upcase(read))))
)
(defrule Premium_Member
(b N)
=>
(printout t crlf "Are you a Premium status member? (Y/N)" crlf)
(assert (p (upcase(read))))
)
带有 clipspy 的 Python 脚本:
import clips
env = clips.Environment()
rule_file = 'rule_file.CLP'
env.load(rule_file)
print("What kind of service needed? ('BR' for book/return car / 'EM' for emergency)")
input = input()
env.assert_string("(service {})".format(input))
env.run()
【问题讨论】: