如何在 clipspy 中获取事实值并将其存储在 python 变量中
How to get a fact value in clipspy and store it in a python variable
假设我插入了一条规则:
(defrule matching
(fever ?fever)
(headache ?headache)
(disease (fever ?fever) (disname ?disname1) (headache ?headache))
=>
(assert (dis ?disname1)))
现在我想获取 ?disname1 的值到一个 python 变量中,以便我可以在网页上显示它,
烧瓶代码-
import clips
from flask import Flask , render_template ,request
app = Flask(__name__)
env = clips.Environment()
env.load("clips.clp")
env.reset()
@app.route('/')
def home():
return render_template('main.html')
@app.route('/result' , methods = ['POST', 'GET'])
def result():
if request.method == 'POST':
if request.form.get('fever'):
env.assert_string("(fever true) ")
if request.form.get('headache'):
env.assert_string("(headache true)")
rule = """ (defrule matching
(fever ?fever) (headache ?headache)
(disease (fever ?fever) (disname ?disname1) (headache ?headache))
=>
(assert ( dis ?disname1 )) """
env.build(rule)
return render_template('next.html')
env.run()
if __name__ == '__main__':
app.run(debug= True)
所以在构建规则后 (dis ?disname) 被断言为剪辑中的事实所以现在,我想检索 ?disname 的值 会将一个人所面临的疾病转化为 python 变量,以便我可以将其传递给 html 模板并显示它。
假设我插入了一条规则:
(defrule matching
(fever ?fever)
(headache ?headache)
(disease (fever ?fever) (disname ?disname1) (headache ?headache))
=>
(assert (dis ?disname1)))
现在我想获取 ?disname1 的值到一个 python 变量中,以便我可以在网页上显示它,
烧瓶代码-
import clips
from flask import Flask , render_template ,request
app = Flask(__name__)
env = clips.Environment()
env.load("clips.clp")
env.reset()
@app.route('/')
def home():
return render_template('main.html')
@app.route('/result' , methods = ['POST', 'GET'])
def result():
if request.method == 'POST':
if request.form.get('fever'):
env.assert_string("(fever true) ")
if request.form.get('headache'):
env.assert_string("(headache true)")
rule = """ (defrule matching
(fever ?fever) (headache ?headache)
(disease (fever ?fever) (disname ?disname1) (headache ?headache))
=>
(assert ( dis ?disname1 )) """
env.build(rule)
return render_template('next.html')
env.run()
if __name__ == '__main__':
app.run(debug= True)
所以在构建规则后 (dis ?disname) 被断言为剪辑中的事实所以现在,我想检索 ?disname 的值 会将一个人所面临的疾病转化为 python 变量,以便我可以将其传递给 html 模板并显示它。